mirror of
https://github.com/esphome/esphome.git
synced 2025-09-14 09:12:19 +01:00
add heating functionality to SI7021 (#4828)
* add heating functoinality * add test * add heat * fix * fix * fix * fix * fix * fix sensor * restore class * Update esphome/components/htu21d/sensor.py * Update esphome/components/htu21d/sensor.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update esphome/components/htu21d/sensor.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --------- Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import i2c, sensor
|
||||
from esphome import automation
|
||||
from esphome.const import (
|
||||
CONF_HUMIDITY,
|
||||
CONF_ID,
|
||||
@@ -10,6 +11,10 @@ from esphome.const import (
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
UNIT_CELSIUS,
|
||||
UNIT_PERCENT,
|
||||
CONF_HEATER,
|
||||
UNIT_EMPTY,
|
||||
CONF_LEVEL,
|
||||
CONF_STATUS,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["i2c"]
|
||||
@@ -19,6 +24,10 @@ HTU21DComponent = htu21d_ns.class_(
|
||||
"HTU21DComponent", cg.PollingComponent, i2c.I2CDevice
|
||||
)
|
||||
|
||||
SetHeaterLevelAction = htu21d_ns.class_("SetHeaterLevelAction", automation.Action)
|
||||
SetHeaterAction = htu21d_ns.class_("SetHeaterAction", automation.Action)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
@@ -35,6 +44,11 @@ CONFIG_SCHEMA = (
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_HEATER): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_EMPTY,
|
||||
accuracy_decimals=1,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
}
|
||||
)
|
||||
.extend(cv.polling_component_schema("60s"))
|
||||
@@ -54,3 +68,45 @@ async def to_code(config):
|
||||
if CONF_HUMIDITY in config:
|
||||
sens = await sensor.new_sensor(config[CONF_HUMIDITY])
|
||||
cg.add(var.set_humidity(sens))
|
||||
|
||||
if CONF_HEATER in config:
|
||||
sens = await sensor.new_sensor(config[CONF_HEATER])
|
||||
cg.add(var.set_heater(sens))
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"htu21d.set_heater_level",
|
||||
SetHeaterLevelAction,
|
||||
cv.maybe_simple_value(
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(HTU21DComponent),
|
||||
cv.Required(CONF_LEVEL): cv.templatable(cv.int_),
|
||||
},
|
||||
key=CONF_LEVEL,
|
||||
),
|
||||
)
|
||||
async def set_heater_level_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
level_ = await cg.templatable(config[CONF_LEVEL], args, int)
|
||||
cg.add(var.set_level(level_))
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"htu21d.set_heater",
|
||||
SetHeaterAction,
|
||||
cv.maybe_simple_value(
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(HTU21DComponent),
|
||||
cv.Required(CONF_STATUS): cv.templatable(cv.boolean),
|
||||
},
|
||||
key=CONF_STATUS,
|
||||
),
|
||||
)
|
||||
async def set_heater_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
status_ = await cg.templatable(config[CONF_LEVEL], args, bool)
|
||||
cg.add(var.set_status(status_))
|
||||
return var
|
||||
|
Reference in New Issue
Block a user