Skip to content

Commit

Permalink
Added support for VALLHORN Motion Sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
c503ghosh committed Mar 30, 2024
1 parent 3f3727a commit 0a06895
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions custom_components/dirigera_platform/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
9 changes: 4 additions & 5 deletions custom_components/dirigera_platform/dirigera_lib_patch.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions custom_components/dirigera_platform/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0a06895

Please sign in to comment.