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/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
LOG: Final = logging.getLogger(__package__)
DEFAULT_STATE_FILE: Final = "hilo_state.yaml"
REQUEST_RETRY: Final = 9
PYHILO_VERSION: Final = "2025.4.02"
PYHILO_VERSION: Final = "2025.5.01"
# TODO: Find a way to keep previous line in sync with pyproject.toml automatically

CONTENT_TYPE_FORM: Final = "application/x-www-form-urlencoded"
Expand Down
15 changes: 8 additions & 7 deletions pyhilo/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from gql.transport.websockets import WebsocketsTransport

from pyhilo import API
from pyhilo.const import LOG
from pyhilo.device.graphql_value_mapper import GraphqlValueMapper
from pyhilo.devices import Devices

Expand Down Expand Up @@ -557,14 +558,14 @@ async def subscribe_to_device_updated(
async for result in session.subscribe(
query, variable_values={"locationHiloId": location_hilo_id}
):
print(f"Received subscription result {result}")
LOG.debug(f"Received subscription result {result}")
device_hilo_id = self._handle_device_subscription_result(result)
if callback:
callback(device_hilo_id)
except Exception as e:
print(f"Connection lost: {e}. Reconnecting in 5 seconds...")
LOG.debug(f"Connection lost: {e}. Reconnecting in 5 seconds...")
await asyncio.sleep(5)
self.call_get_location_query(location_hilo_id)
await self.call_get_location_query(location_hilo_id)

async def subscribe_to_location_updated(
self, location_hilo_id: str, callback: callable = None
Expand All @@ -580,11 +581,11 @@ async def subscribe_to_location_updated(
async for result in session.subscribe(
query, variable_values={"locationHiloId": location_hilo_id}
):
print(f"Received subscription result {result}")
LOG.debug(f"Received subscription result {result}")
device_hilo_id = self._handle_location_subscription_result(result)
callback(device_hilo_id)
except asyncio.CancelledError:
print("Subscription cancelled.")
LOG.debug("Subscription cancelled.")
asyncio.sleep(1)
await self.subscribe_to_location_updated(location_hilo_id)

Expand All @@ -602,13 +603,13 @@ def _handle_device_subscription_result(self, result: Dict[str, Any]) -> str:
attributes = self.mapper.map_device_subscription_values(devices_values)
updated_device = self._devices.parse_values_received(attributes)
# callback to update the device in the UI
print(f"Device updated: {updated_device}")
LOG.debug(f"Device updated: {updated_device}")
return devices_values.get("hiloId")

def _handle_location_subscription_result(self, result: Dict[str, Any]) -> str:
devices_values: list[any] = result["onAnyLocationUpdated"]["location"]
attributes = self.mapper.map_location_subscription_values(devices_values)
updated_device = self._devices.parse_values_received(attributes)
# callback to update the device in the UI
print(f"Device updated: {updated_device}")
LOG.debug(f"Device updated: {updated_device}")
return devices_values.get("hiloId")
2 changes: 1 addition & 1 deletion pyhilo/util/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async def set_state(
LOG.debug("Saving state to yaml file")
# TODO: Use asyncio.get_running_loop() and run_in_executor to write
# to the file in a non blocking manner. Currently, the file writes
# are properly async but the yaml dump is done synchroniously on the
# are properly async but the yaml dump is done synchronously on the
# main event loop.
content = yaml.dump(new_state)
await yaml_file.write(content)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exclude = ".venv/.*"

[tool.poetry]
name = "python-hilo"
version = "2025.4.2"
version = "2025.5.1"
description = "A Python3, async interface to the Hilo API"
readme = "README.md"
authors = ["David Vallee Delisle <me@dvd.dev>"]
Expand Down
Loading