From ff136a19d9864e3d72c4d0774f65ba5170f1f236 Mon Sep 17 00:00:00 2001 From: SukramJ Date: Mon, 9 Sep 2019 22:02:53 +0200 Subject: [PATCH] Add Delta Counter of HmIP-SPDR to Homematic IP Cloud (#26538) --- .../components/homematicip_cloud/sensor.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/homeassistant/components/homematicip_cloud/sensor.py b/homeassistant/components/homematicip_cloud/sensor.py index b396a8d9def..43812df94d2 100644 --- a/homeassistant/components/homematicip_cloud/sensor.py +++ b/homeassistant/components/homematicip_cloud/sensor.py @@ -10,6 +10,7 @@ from homematicip.aio.device import ( AsyncMotionDetectorIndoor, AsyncMotionDetectorOutdoor, AsyncMotionDetectorPushButton, + AsyncPassageDetector, AsyncPlugableSwitchMeasuring, AsyncPresenceDetectorIndoor, AsyncTemperatureHumiditySensorDisplay, @@ -38,6 +39,8 @@ from .device import ATTR_MODEL_TYPE _LOGGER = logging.getLogger(__name__) +ATTR_LEFT_COUNTER = "left_counter" +ATTR_RIGHT_COUNTER = "right_counter" ATTR_TEMPERATURE_OFFSET = "temperature_offset" ATTR_WIND_DIRECTION = "wind_direction" ATTR_WIND_DIRECTION_VARIATION = "wind_direction_variation_in_degree" @@ -100,6 +103,8 @@ async def async_setup_entry( devices.append(HomematicipWindspeedSensor(home, device)) if isinstance(device, (AsyncWeatherSensorPlus, AsyncWeatherSensorPro)): devices.append(HomematicipTodayRainSensor(home, device)) + if isinstance(device, AsyncPassageDetector): + devices.append(HomematicipPassageDetectorDeltaCounter(home, device)) if devices: async_add_entities(devices) @@ -338,6 +343,29 @@ class HomematicipTodayRainSensor(HomematicipGenericDevice): return "mm" +class HomematicipPassageDetectorDeltaCounter(HomematicipGenericDevice): + """Representation of a HomematicIP passage detector delta counter.""" + + def __init__(self, home: AsyncHome, device) -> None: + """Initialize the device.""" + super().__init__(home, device) + + @property + def state(self) -> int: + """Representation of the HomematicIP passage detector delta counter value.""" + return self._device.leftRightCounterDelta + + @property + def device_state_attributes(self): + """Return the state attributes of the delta counter.""" + state_attr = super().device_state_attributes + + state_attr[ATTR_LEFT_COUNTER] = self._device.leftCounter + state_attr[ATTR_RIGHT_COUNTER] = self._device.rightCounter + + return state_attr + + def _get_wind_direction(wind_direction_degree: float) -> str: """Convert wind direction degree to named direction.""" if 11.25 <= wind_direction_degree < 33.75: