Skip to content

Commit

Permalink
Pass data object into event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
sebr committed Nov 9, 2020
1 parent 228a81e commit e80964a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions custom_components/bhyve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def __init__(
def _on_ws_data(self, data):
pass

def _should_handle_event(self, event_name):
def _should_handle_event(self, event_name, data):
"""True if the websocket event should be handled"""
return True

Expand Down Expand Up @@ -299,7 +299,7 @@ def update(device_id, data):
self._available = False
elif event == "device_connected":
self._available = True
if self._should_handle_event(event):
if self._should_handle_event(event, data):
_LOGGER.info(
"Message received: {} - {} - {}".format(
self.name, self._device_id, str(data)
Expand Down
6 changes: 3 additions & 3 deletions custom_components/bhyve/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def unique_id(self):
"""Return a unique, unchanging string that represents this sensor."""
return f"{self._mac_address}:{self._device_id}:battery"

def _should_handle_event(self, event_name):
def _should_handle_event(self, event_name, data):
return event_name in [EVENT_CHANGE_MODE]

async def async_update(self):
Expand Down Expand Up @@ -139,7 +139,7 @@ def unique_id(self):
"""Return a unique, unchanging string that represents this sensor."""
return f"{self._mac_address}:{self._device_id}:{self._zone_id}:history"

def _should_handle_event(self, event_name):
def _should_handle_event(self, event_name, data):
return event_name in [EVENT_DEVICE_IDLE]

async def async_update(self):
Expand Down Expand Up @@ -219,5 +219,5 @@ def _on_ws_data(self, data):
if event == EVENT_CHANGE_MODE:
self._state = data.get("mode")

def _should_handle_event(self, event_name):
def _should_handle_event(self, event_name, data):
return event_name in [EVENT_CHANGE_MODE]
6 changes: 3 additions & 3 deletions custom_components/bhyve/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def _on_ws_data(self, data):
if program is not None:
self._program = program

def _should_handle_event(self, event_name):
def _should_handle_event(self, event_name, data):
return event_name in [EVENT_PROGRAM_CHANGED]


Expand Down Expand Up @@ -448,7 +448,7 @@ def _set_watering_program(self, program):
}
)

def _should_handle_event(self, event_name):
def _should_handle_event(self, event_name, data):
return event_name in [
EVENT_DEVICE_IDLE,
EVENT_WATERING_COMPLETE,
Expand Down Expand Up @@ -576,7 +576,7 @@ def _on_ws_data(self, data):
# The REST API returns more data about a rain delay (eg cause/weather_type)
self._update_device_soon()

def _should_handle_event(self, event_name):
def _should_handle_event(self, event_name, data):
return event_name in [EVENT_RAIN_DELAY]

def _update_device_soon(self):
Expand Down

0 comments on commit e80964a

Please sign in to comment.