Skip to content

Commit 18fe145

Browse files
committed
Linting préliminaire
L250 dans websocket ne lintera pas, le call est malformé. À revoir
1 parent 9659122 commit 18fe145

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

pyhilo/api.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,10 @@ async def get_devices(self, location_id: int) -> list[dict[str, Any]]:
807807
# Try to use cached websocket device data first
808808
# The DeviceHub websocket sends DeviceListInitialValuesReceived with full device info
809809
if self._websocket_device_cache:
810-
LOG.debug("Using cached device list from websocket (%d devices)", len(self._websocket_device_cache))
810+
LOG.debug(
811+
"Using cached device list from websocket (%d devices)",
812+
len(self._websocket_device_cache),
813+
)
811814
devices = self._websocket_device_cache.copy()
812815
# Try GraphQL if we have a URN and no websocket cache
813816
elif self.urn:
@@ -862,37 +865,38 @@ async def get_devices(self, location_id: int) -> list[dict[str, Any]]:
862865
devices.append(callback())
863866

864867
return devices
865-
868+
866869
def cache_websocket_devices(self, device_list: list[dict[str, Any]]) -> None:
867870
"""Cache device list received from DeviceHub websocket.
868-
871+
869872
The DeviceListInitialValuesReceived message contains the full device list
870873
with all the info we need (id, name, identifier, etc.) in REST format.
871874
This eliminates the need to call the deprecated REST endpoint.
872-
875+
873876
Args:
874877
device_list: List of devices from DeviceListInitialValuesReceived
875878
"""
876879
self._websocket_device_cache = device_list
877880
self._device_cache_ready.set()
878881
LOG.debug("Cached %d devices from websocket", len(device_list))
879-
882+
880883
async def wait_for_device_cache(self, timeout: float = 10.0) -> bool:
881884
"""Wait for the websocket device cache to be populated.
882-
885+
883886
This should be called before devices.async_init() to ensure
884887
device names and IDs are available from the websocket.
885-
888+
886889
Args:
887890
timeout: Maximum time to wait in seconds (default: 10.0)
888-
891+
889892
Returns:
890893
True if cache was populated, False if timeout occurred
891894
"""
892895
import time
896+
893897
start_time = time.time()
894898
LOG.debug("Waiting for websocket device cache (timeout: %.1fs)...", timeout)
895-
899+
896900
try:
897901
await asyncio.wait_for(self._device_cache_ready.wait(), timeout=timeout)
898902
elapsed = time.time() - start_time
@@ -902,7 +906,7 @@ async def wait_for_device_cache(self, timeout: float = 10.0) -> bool:
902906
elapsed = time.time() - start_time
903907
LOG.warning(
904908
"Timeout waiting for websocket device cache after %.2f seconds, will use fallback method",
905-
elapsed
909+
elapsed,
906910
)
907911
return False
908912

@@ -1114,4 +1118,4 @@ async def get_weather(self, location_id: int) -> dict[str, Any]:
11141118
LOG.debug("Weather URL is %s", url)
11151119
response = await self.async_request("get", url)
11161120
LOG.debug("Weather API response: %s", response)
1117-
return cast(dict[str, Any], response)
1121+
return cast(dict[str, Any], response)

pyhilo/websocket.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ def _parse_message(self, msg: dict[str, Any]) -> None:
242242
self._ready_event.set()
243243
LOG.info("Websocket: Ready for data")
244244
return
245-
245+
246246
# Cache device list from DeviceListInitialValuesReceived
247247
if msg.get("target") == "DeviceListInitialValuesReceived":
248248
if "arguments" in msg and len(msg["arguments"]) > 0:
249249
device_list = msg["arguments"][0]
250250
if isinstance(device_list, list) and self._api.api:
251251
self._api.api.cache_websocket_devices(device_list)
252-
252+
253253
event = websocket_event_from_payload(msg)
254254
for callback in self._event_callbacks:
255255
schedule_callback(callback, event)
@@ -579,4 +579,4 @@ async def _get_websocket_params(self, config: WebsocketConfig) -> None:
579579
else "websocketChallenges"
580580
)
581581
LOG.debug("Calling set_state %s_params", state_key)
582-
await self._set_state(self._state_yaml, state_key, websocket_dict)
582+
await self._set_state(self._state_yaml, state_key, websocket_dict)

0 commit comments

Comments
 (0)