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

Fix: Missing repeated events for Philips Hue Tap Dial switch #167

Merged
merged 1 commit into from
Dec 14, 2022
Merged
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
19 changes: 14 additions & 5 deletions aiohue/v2/controllers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def __contains__(self, id: str) -> bool:
return id in self._items

async def _handle_event(
self, evt_type: EventType, evt_data: Optional[dict]
self, evt_type: EventType, evt_data: Optional[dict], is_reconnect: bool = False
) -> None:
"""Handle incoming event for this resource from the EventStream."""
if evt_data is None:
Expand Down Expand Up @@ -225,8 +225,8 @@ async def _handle_event(
return
# update the existing data with the changed keys/data
updated_keys = update_dataclass(cur_item, evt_data)
# do not forward update event if no keys were updated
if len(updated_keys) == 0 and self.item_type != ResourceTypes.BUTTON:
# do not forward update event at reconnects if no keys were updated
if len(updated_keys) == 0 and is_reconnect:
return
# Do not forward update events for button resource if
# the button feature is missing in event data in an attempt to prevent
Expand All @@ -236,6 +236,10 @@ async def _handle_event(
# https://developers.meethue.com/forum/t/differentiate-stateless-events/6627
if self.item_type == ResourceTypes.BUTTON and not evt_data.get("button"):
return
if self.item_type == ResourceTypes.RELATIVE_ROTARY and not evt_data.get(
"relative_rotary"
):
return
else:
# ignore all other events
return
Expand Down Expand Up @@ -267,9 +271,14 @@ async def __handle_reconnect(self, full_state: List[dict]) -> None:
else:
# work out if the item changed in the regular event logic
# ignore stateless (button) resources to prevent false positive state events
if item["type"] == ResourceTypes.BUTTON.value:
if item["type"] in (
ResourceTypes.BUTTON.value,
ResourceTypes.RELATIVE_ROTARY.value,
):
continue
await self._handle_event(EventType.RESOURCE_UPDATED, item)
await self._handle_event(
EventType.RESOURCE_UPDATED, item, is_reconnect=True
)

# work out item deletions
deleted_ids = {x for x in prev_ids if x not in cur_ids}
Expand Down