Skip to content

Commit 8a86325

Browse files
authored
Merge pull request #296 from fersingb/fix_reconnect
Fix reconnects to gql endpoint after network outage
2 parents ac476db + 1b0943a commit 8a86325

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

pyhilo/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
LOG: Final = logging.getLogger(__package__)
88
DEFAULT_STATE_FILE: Final = "hilo_state.yaml"
99
REQUEST_RETRY: Final = 9
10-
PYHILO_VERSION: Final = "2025.5.01"
10+
PYHILO_VERSION: Final = "2025.6.01"
1111
# TODO: Find a way to keep previous line in sync with pyproject.toml automatically
1212

1313
CONTENT_TYPE_FORM: Final = "application/x-www-form-urlencoded"

pyhilo/graphql.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,9 @@ async def call_get_location_query(self, location_hilo_id: str) -> None:
547547
async def subscribe_to_device_updated(
548548
self, location_hilo_id: str, callback: callable = None
549549
) -> None:
550+
LOG.debug("subscribe_to_device_updated called")
550551
while True: # Loop to reconnect if the connection is lost
552+
LOG.debug("subscribe_to_device_updated while true")
551553
access_token = await self._get_access_token()
552554
transport = WebsocketsTransport(
553555
url=f"wss://platform.hiloenergie.com/api/digital-twin/v3/graphql?access_token={access_token}"
@@ -559,14 +561,25 @@ async def subscribe_to_device_updated(
559561
async for result in session.subscribe(
560562
query, variable_values={"locationHiloId": location_hilo_id}
561563
):
562-
LOG.debug(f"Received subscription result {result}")
564+
LOG.debug(
565+
f"subscribe_to_device_updated: Received subscription result {result}"
566+
)
563567
device_hilo_id = self._handle_device_subscription_result(result)
564568
if callback:
565569
callback(device_hilo_id)
566570
except Exception as e:
567-
LOG.debug(f"Connection lost: {e}. Reconnecting in 5 seconds...")
571+
LOG.debug(
572+
f"subscribe_to_device_updated: Connection lost: {e}. Reconnecting in 5 seconds..."
573+
)
568574
await asyncio.sleep(5)
569-
await self.call_get_location_query(location_hilo_id)
575+
try:
576+
await self.call_get_location_query(location_hilo_id)
577+
LOG.debug("subscribe_to_device_updated, call_get_location_query success")
578+
579+
except Exception as e2:
580+
LOG.error(
581+
f"subscribe_to_device_updated, exception while reconnecting, retrying: {e2}"
582+
)
570583

571584
async def subscribe_to_location_updated(
572585
self, location_hilo_id: str, callback: callable = None

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ exclude = ".venv/.*"
4040

4141
[tool.poetry]
4242
name = "python-hilo"
43-
version = "2025.5.1"
43+
version = "2025.6.1"
4444
description = "A Python3, async interface to the Hilo API"
4545
readme = "README.md"
4646
authors = ["David Vallee Delisle <[email protected]>"]

0 commit comments

Comments
 (0)