diff --git a/README.md b/README.md index 4178531..c515c12 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Supports * STYRBAR Remotes * AirPurifier * STARKVIND AirPurifier +* VALLHORN Motion Sensors ## Pre-requisite 1. Identify the IP of the gateway - Usually looking at the client list in your home router interface will give that. diff --git a/custom_components/dirigera_platform/binary_sensor.py b/custom_components/dirigera_platform/binary_sensor.py index 57857eb..68b69b2 100644 --- a/custom_components/dirigera_platform/binary_sensor.py +++ b/custom_components/dirigera_platform/binary_sensor.py @@ -72,11 +72,17 @@ async def async_setup_entry( class ikea_motion_sensor(BinarySensorEntity): + def __init__(self, hub, json_data): logger.debug("ikea_motion_sensor ctor...") self._hub = hub self._json_data = json_data + self.user_detected_attr = False + if self._json_data.attributes.model.lower().startswith("vallhorn"): + logger.debug("VALLHORN Motion sensor detected will use is_detected attribute..") + self.user_detected_attr = True + @property def unique_id(self): return self._json_data.id @@ -103,6 +109,8 @@ def name(self): @property def is_on(self): + if self.user_detected_attr: + return self._json_data.attributes.is_detected return self._json_data.attributes.is_on def update(self): diff --git a/custom_components/dirigera_platform/dirigera_lib_patch.py b/custom_components/dirigera_platform/dirigera_lib_patch.py index 9d1979e..b71afe6 100644 --- a/custom_components/dirigera_platform/dirigera_lib_patch.py +++ b/custom_components/dirigera_platform/dirigera_lib_patch.py @@ -1,9 +1,9 @@ -from typing import Any, Dict, List +from typing import Any, Dict, List, Optional from dirigera import Hub from dirigera.devices.air_purifier import AirPurifier, dict_to_air_purifier from dirigera.devices.blinds import Blind, dict_to_blind -from dirigera.devices.device import Attributes +from dirigera.devices.motion_sensor import MotionSensorAttributes from dirigera.devices.environment_sensor import ( EnvironmentSensor, dict_to_environment_sensor, @@ -18,9 +18,8 @@ # Patch to fix issues with motion sensor -class MotionSensorAttributesX(Attributes): - battery_percentage: int - is_on: bool +class MotionSensorAttributesX(MotionSensorAttributes): + is_detected: Optional[bool] class MotionSensorX(MotionSensor): diff --git a/custom_components/dirigera_platform/light.py b/custom_components/dirigera_platform/light.py index a9d820b..1963563 100644 --- a/custom_components/dirigera_platform/light.py +++ b/custom_components/dirigera_platform/light.py @@ -50,8 +50,7 @@ async def async_setup_entry( logger.debug("LIGHT Complete async_setup_entry") class ikea_bulb(LightEntity): - _attr_has_entity_name = True - + def __init__(self, hub, json_data) -> None: logger.debug("ikea_bulb ctor...") self._hub = hub