Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pyhilo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async def async_get_access_token(self) -> str:
await self._oauth_session.async_ensure_token_valid()

access_token = str(self._oauth_session.token["access_token"])
LOG.debug("LOCALLY Websocket access token is %s", access_token)
LOG.debug("Websocket access token is %s", access_token)

return str(self._oauth_session.token["access_token"])

Expand Down
8 changes: 7 additions & 1 deletion pyhilo/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Event:
def __init__(self, **event: dict[str, Any]):
"""Initialize."""
self._convert_phases(cast(dict[str, Any], event.get("phases")))
params: dict[str, Any] = event.get("parameters", {})
params: dict[str, Any] = event.get("parameters") or {}
devices: list[dict[str, Any]] = params.get("devices", [])
consumption: dict[str, Any] = event.get("consumption", {})
allowed_wH: int = consumption.get("baselineWh", 0) or 0
Expand Down Expand Up @@ -71,6 +71,12 @@ def update_wh(self, used_wH: float) -> None:
self.used_kWh = round(used_wH / 1000, 2)
self.last_update = datetime.now(timezone.utc).astimezone()

def update_allowed_wh(self, allowed_wH: float) -> None:
"""This function is used to update the allowed_kWh attribute during a Hilo Challenge Event"""
LOG.debug("Updating allowed Wh: %s", allowed_wH)
self.allowed_kWh = round(allowed_wH / 1000, 2)
self.last_update = datetime.now(timezone.utc).astimezone()

def should_check_for_allowed_wh(self) -> bool:
"""This function is used to authorize subscribing to a specific event in Hilo to receive the allowed_kWh
that is made available in the pre_heat phase"""
Expand Down
4 changes: 4 additions & 0 deletions pyhilo/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ async def async_connect(self) -> None:
raise CannotConnectError(err) from err

LOG.info(f"Connected to websocket server {self._api.endpoint}")

# Quick pause to prevent race condition
await asyncio.sleep(0.05)

self._watchdog.trigger()
for callback in self._connect_callbacks:
schedule_callback(callback)
Expand Down
Loading