From 5c073dbe7bbe7fd473795fb6b9942f3f0a877c3a Mon Sep 17 00:00:00 2001 From: Thomas Schamm Date: Sat, 18 Feb 2023 22:50:19 +0100 Subject: [PATCH] Added support for illuminance level of motion detector. --- custom_components/bosch_shc/manifest.json | 2 +- custom_components/bosch_shc/sensor.py | 27 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/custom_components/bosch_shc/manifest.json b/custom_components/bosch_shc/manifest.json index 639750b..936d290 100644 --- a/custom_components/bosch_shc/manifest.json +++ b/custom_components/bosch_shc/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://github.com/tschamm/boschshc-hass/blob/master/README.md", "requirements": ["boschshcpy==0.2.56"], - "version": "0.4.47", + "version": "0.4.48", "zeroconf": [{ "type": "_http._tcp.local.", "name": "bosch shc*" }], "iot_class": "local_push", "issue_tracker": "https://github.com/tschamm/boschshc-hass/issues", diff --git a/custom_components/bosch_shc/sensor.py b/custom_components/bosch_shc/sensor.py index 9c0c2d0..5bf425f 100644 --- a/custom_components/bosch_shc/sensor.py +++ b/custom_components/bosch_shc/sensor.py @@ -244,6 +244,15 @@ async def async_setup_entry( ) ) + for sensor in session.device_helper.motion_detectors: + entities.append( + IlluminanceLevelSensor( + device=sensor, + parent_id=session.information.unique_id, + entry_id=config_entry.entry_id, + ) + ) + if entities: async_add_entities(entities) @@ -454,3 +463,21 @@ def extra_state_attributes(self): return { "valve_tappet_state": self._device.valvestate.name, } + + +class IlluminanceLevelSensor(SHCEntity, SensorEntity): + """Representation of an SHC illuminance level reporting sensor.""" + + _attr_state_class = SensorStateClass.MEASUREMENT + _attr_entity_category = EntityCategory.DIAGNOSTIC + + def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: + """Initialize an SHC illuminance level reporting sensor.""" + super().__init__(device, parent_id, entry_id) + self._attr_name = f"{device.name} Illuminance" + self._attr_unique_id = f"{device.root_device_id}_{device.id}_illuminance" + + @property + def native_value(self): + """Return the state of the sensor.""" + return self._device.illuminance