From d6210a9378a62b2397e924e12fe2bd22188e30bc Mon Sep 17 00:00:00 2001 From: t0urista Date: Mon, 28 Oct 2024 15:00:24 +0100 Subject: [PATCH] Update sensor.py --- esphome/components/bthome/sensor.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/esphome/components/bthome/sensor.py b/esphome/components/bthome/sensor.py index 95e12d5df6..6ffbb33588 100644 --- a/esphome/components/bthome/sensor.py +++ b/esphome/components/bthome/sensor.py @@ -6,8 +6,12 @@ from esphome.const import ( CONF_BATTERY_LEVEL, CONF_ID, CONF_ILLUMINANCE, + CONF_HUMIDITY, + CONF_TEMPERATURE, DEVICE_CLASS_BATTERY, DEVICE_CLASS_ILLUMINANCE, + DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_TEMPERATURE, ENTITY_CATEGORY_DIAGNOSTIC, STATE_CLASS_MEASUREMENT, UNIT_DEGREES, @@ -42,6 +46,18 @@ CONFIG_SCHEMA = cv.Schema( device_class=DEVICE_CLASS_ILLUMINANCE, state_class=STATE_CLASS_MEASUREMENT, ), + cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( + unit_of_measurement=UNIT_PERCENT, + accuracy_decimals=2, + device_class=DEVICE_CLASS_HUMIDITY, + state_class=STATE_CLASS_MEASUREMENT, + ), + cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( + unit_of_measurement=UNIT_DEGREES, + accuracy_decimals=2, + device_class=DEVICE_CLASS_TEMPERATURE, + state_class=STATE_CLASS_MEASUREMENT, + ), } ) @@ -60,3 +76,12 @@ async def to_code(config): if CONF_ILLUMINANCE in config: sens = await sensor.new_sensor(config[CONF_ILLUMINANCE]) cg.add(parent.set_illuminance(sens)) + + if CONF_HUMIDITY in config: + sens = await sensor.new_sensor(config[CONF_HUMIDITY]) + cg.add(parent.set_humidity(sens)) + + if CONF_TEMPERATUREE in config: + sens = await sensor.new_sensor(config[CONF_TEMPERATURE]) + cg.add(parent.set_temperature(sens)) +