Skip to content

Commit

Permalink
Rely on defaultdict to handle defaults and degenerate forms.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Oct 23, 2022
1 parent f3ff58c commit d0adb71
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions jaraco/abode/event_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,17 @@ def _on_socket_connected(self):
# Callbacks should still execute even if refresh fails (Abode
# server issues) so that the entity availability in Home Assistant
# is updated since we are in fact connected to the web socket.
for callbacks in self._connection_status_callbacks.items():
for callback in callbacks[1]:
for callbacks in self._connection_status_callbacks.values:
for callback in callbacks:
_execute_callback(callback)

def _on_socket_disconnected(self):
"""Socket IO disconnected callback."""
self._connected = False

for callbacks in self._connection_status_callbacks.items():
# Check if list is not empty.
# Applicable when remove_all_device_callbacks
# is called before _on_socket_disconnected.
if callbacks[1]:
for callback in callbacks[1]:
_execute_callback(callback)
for callbacks in self._connection_status_callbacks.values():
for callback in callbacks:
_execute_callback(callback)

def _on_device_update(self, devid):
"""Device callback from Abode SocketIO server."""
Expand All @@ -229,7 +225,7 @@ def _on_device_update(self, devid):
_LOGGER.debug("Got device update for unknown device: %s", devid)
return

for callback in self._device_callbacks.get(device.device_id, ()):
for callback in self._device_callbacks[device.device_id]:
_execute_callback(callback, device)

def _on_mode_change(self, mode):
Expand All @@ -256,7 +252,7 @@ def _on_mode_change(self, mode):
# pylint: disable=W0212
alarm_device._json_state['mode']['area_1'] = mode

for callback in self._device_callbacks.get(alarm_device.device_id, ()):
for callback in self._device_callbacks[alarm_device.device_id]:
_execute_callback(callback, alarm_device)

def _on_timeline_update(self, event):
Expand Down Expand Up @@ -290,9 +286,8 @@ def _on_timeline_update(self, event):
# Attempt to map the event code to a group and callback
event_group = TIMELINE.map_event_code(event_code)

if event_group:
for callback in self._event_callbacks.get(event_group, ()):
_execute_callback(callback, event)
for callback in self._event_callbacks[event_group]:
_execute_callback(callback, event)

def _on_automation_update(self, event):
"""Automation update broadcast from Abode SocketIO server."""
Expand All @@ -301,7 +296,7 @@ def _on_automation_update(self, event):
if isinstance(event, (tuple, list)):
event = event[0]

for callback in self._event_callbacks.get(event_group, ()):
for callback in self._event_callbacks[event_group]:
_execute_callback(callback, event)


Expand Down

0 comments on commit d0adb71

Please sign in to comment.