Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate battery sensor entity for SOMRIG devices #33

Merged
merged 3 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions custom_components/dirigera_platform/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ def name(self):

@property
def is_on(self):
# Note: the `is_detected` attribute is not present for Trådfri Motion Sensor E1745, only in the webhook events
return self._json_data.attributes.is_on or getattr(self._json_data.attributes, 'is_detected', False)
return self._json_data.attributes.is_on or self._json_data.attributes.is_detected

async def async_update(self):
logger.debug("motion sensor update...")
Expand Down
31 changes: 16 additions & 15 deletions custom_components/dirigera_platform/hub_event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ def on_message(self, ws:Any, ws_msg:str):

info = msg['data']
id = info['id']

device_type = None
if "deviceType" in info:
device_type = info["deviceType"]
elif "type" in info:
device_type = info["type"]
else:
logger.warn("expected type or deviceType in JSON, none found, ignoring...")
return

logger.debug(f"device type of message {device_type}")
if device_type not in process_events_from:
# To avoid issues been reported. If we dont have it in our list
# then best to not process this event
return

if id not in hub_event_listener.device_registry:
logger.info(f"discarding message as device for id: {id} not found for msg: {msg}")
return
Expand All @@ -75,22 +91,7 @@ def on_message(self, ws:Any, ws_msg:str):
except Exception as ex:
logger.error(f"Failed to setattr is_reachable on device: {id} for msg: {msg}")
logger.error(ex)

device_type = None
if "deviceType" in info:
device_type = info["deviceType"]
elif "type" in info:
device_type = info["type"]
else:
logger.warn("expected type or deviceType in JSON, none found, ignoring...")
return

logger.debug(f"device type of message {device_type}")
if device_type not in process_events_from:
# To avoid issues been reported. If we dont have it in our list
# then best to not process this event
return

to_process_attr = process_events_from[device_type]

if "attributes" in info:
Expand Down
3 changes: 3 additions & 0 deletions custom_components/dirigera_platform/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ async def async_setup_entry(
controller_devices = [
ikea_controller(hub, controller_device)
for controller_device in hub_controllers
# Only create a battery sensor entity if the device reports battery percentage
# This is not the case of the second device for SOMRIG controllers
if controller_device.attributes.battery_percentage
]

env_sensors = []
Expand Down
Loading