Skip to content

Commit

Permalink
only update brew running once
Browse files Browse the repository at this point in the history
  • Loading branch information
zweckj committed Aug 10, 2023
1 parent 7a8da13 commit 60a9fa3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion custom_components/lamarzocco/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(self, hass, config_entry, lm):
self._websocket_task = None
self._config_entry = config_entry
self._use_websocket = self._config_entry.options.get(CONF_USE_WEBSOCKET, True)
self._brew_running_set = False

async def _async_update_data(self):
try:
Expand Down Expand Up @@ -84,14 +85,24 @@ def _on_data_received(self, property_updated, update):
if not property_updated or not self._initialized:
return

_LOGGER.debug("Received data from websocket, property updated: %s", str(property_updated))
_LOGGER.debug("Received data from websocket, property updated: %s with value: %s", str(property_updated), str(update))
if property_updated:
if property_updated != BREW_ACTIVE:
self._lm._current_status[property_updated] = update
else:
self._lm._brew_active = update

self.data = self._lm

# machine spams the websocket with brew_active updates, during brew
# so we only want to update the listeners once, to avoid overloading HA
if property_updated == BREW_ACTIVE and update and not self._brew_running_set:
self._brew_running_set = True
elif property_updated == BREW_ACTIVE and update and self._brew_running_set:
return
elif property_updated == BREW_ACTIVE and not update:
self._brew_running_set = False

self.async_update_listeners()

def terminate_websocket(self):
Expand Down

0 comments on commit 60a9fa3

Please sign in to comment.