Skip to content

Commit

Permalink
poll: ignore events without id or state attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
willoma committed Jul 21, 2023
1 parent 3e39d26 commit be87df1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions pycalaos/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,37 @@ def poll(self):
)
if len(resp["events"]) > 0:
_LOGGER.debug(f"Raw events from polling: {resp['events']}")

events = []
for rawEvent in resp["events"]:
try:
item = self.items[rawEvent["data"]["id"]]
eventData = rawEvent["data"]
except:
_LOGGER.error(f"Poll received event without data: {rawEvent}")
continue

try:
itemID = eventData["id"]
except:
_LOGGER.error(f"Poll received event without ID: {rawEvent}")
continue

try:
state = eventData["state"]
except:
_LOGGER.debug(f"Poll received event without state: {rawEvent}")
continue

try:
item = self.items[itemID]
except KeyError:
_LOGGER.error(f"Poll received event with unknown ID: {rawEvent}")
continue
changed = item.internal_from_event(rawEvent["data"]["state"])

changed = item.internal_from_event(state)
if changed:
events.append(Event(item))

self._last_poll = now
if len(events) > 0:
_LOGGER.debug(f"Events: {events}")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pycalaos"
version = "0.0.25"
version = "0.0.26"
authors = [
{ name = "Willow Maccagnoni", email = "willow.maccagnoni@gmail.com" },
]
Expand Down

0 comments on commit be87df1

Please sign in to comment.