Skip to content

Commit 0161248

Browse files
committed
Update api.py
1 parent 6dc2ccd commit 0161248

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

pyhilo/api.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async def async_get_access_token(self) -> str:
140140
await self._oauth_session.async_ensure_token_valid()
141141

142142
access_token = str(self._oauth_session.token["access_token"])
143-
LOG.debug(f"Websocket access token is {access_token}")
143+
LOG.debug("Websocket access token is %s", access_token)
144144

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

@@ -246,8 +246,9 @@ async def _async_request(
246246
data: dict[str, Any] = {}
247247
url = parse.urljoin(f"https://{host}", endpoint)
248248
if self.log_traces:
249-
LOG.debug(f"[TRACE] Headers: {kwargs['headers']}")
250-
LOG.debug(f"[TRACE] Async request: {method} {url}")
249+
LOG.debug("[TRACE] Headers: %s", kwargs["headers"])
250+
LOG.debug("[TRACE] Async request: %s %s", method, url)
251+
251252
async with self.session.request(method, url, **kwargs) as resp:
252253
if "application/json" in resp.headers.get("content-type", ""):
253254
try:
@@ -396,7 +397,7 @@ async def get_websocket_params(self) -> None:
396397
"""Retrieves and constructs WebSocket connection parameters from the negotiation endpoint."""
397398
uri = parse.urlparse(self.ws_url)
398399
LOG.debug("Getting websocket params")
399-
LOG.debug(f"Getting uri {uri}")
400+
LOG.debug("Getting uri %s", uri)
400401
resp: dict[str, Any] = await self.async_request(
401402
"post",
402403
f"{uri.path}negotiate?{uri.query}",
@@ -407,7 +408,7 @@ async def get_websocket_params(self) -> None:
407408
)
408409
conn_id: str = resp.get("connectionId", "")
409410
self.full_ws_url = f"{self.ws_url}&id={conn_id}&access_token={self.ws_token}"
410-
LOG.debug(f"Getting full ws URL {self.full_ws_url}")
411+
LOG.debug("Getting full ws URL %s", self.full_ws_url)
411412
transport_dict: list[WebsocketTransportsDict] = resp.get(
412413
"availableTransports", []
413414
)
@@ -441,7 +442,7 @@ async def fb_install(self, fb_id: str) -> None:
441442
if err.status in (401, 403):
442443
raise InvalidCredentialsError("Invalid credentials") from err
443444
raise RequestError(err) from err
444-
LOG.debug(f"FB Install data: {resp}")
445+
LOG.debug("FB Install data: %s", resp)
445446
auth_token = resp.get("authToken", {})
446447
LOG.debug("Calling set_state from fb_install")
447448
await set_state(
@@ -479,7 +480,7 @@ async def android_register(self) -> None:
479480
if err.status in (401, 403):
480481
raise InvalidCredentialsError("Invalid credentials") from err
481482
raise RequestError(err) from err
482-
LOG.debug(f"Android client register: {resp}")
483+
LOG.debug("Android client register: %s", resp)
483484
msg: str = resp.get("message", "")
484485
if msg.startswith("Error="):
485486
LOG.error(f"Android registration error: {msg}")
@@ -497,14 +498,14 @@ async def android_register(self) -> None:
497498
async def get_location_ids(self) -> tuple[int, str]:
498499
"""Gets location id from an API call"""
499500
url = f"{API_AUTOMATION_ENDPOINT}/Locations"
500-
LOG.debug(f"LocationId URL is {url}")
501+
LOG.debug("LocationId URL is %s", url)
501502
req: list[dict[str, Any]] = await self.async_request("get", url)
502503
return (req[0]["id"], req[0]["locationHiloId"])
503504

504505
async def get_devices(self, location_id: int) -> list[dict[str, Any]]:
505506
"""Get list of all devices"""
506507
url = self._get_url("Devices", location_id)
507-
LOG.debug(f"Devices URL is {url}")
508+
LOG.debug("Devices URL is %s", url)
508509
devices: list[dict[str, Any]] = await self.async_request("get", url)
509510
devices.append(await self.get_gateway(location_id))
510511
# Now it's time to add devices coming from external sources like hass
@@ -521,7 +522,7 @@ async def _set_device_attribute(
521522
) -> None:
522523
"""Sets device attributes"""
523524
url = self._get_url(f"Devices/{device.id}/Attributes", device.location_id)
524-
LOG.debug(f"Device Attribute URL is {url}")
525+
LOG.debug("Device Attribute URL is %s", url)
525526
await self.async_request("put", url, json={key.hilo_attribute: value})
526527

527528
async def get_event_notifications(self, location_id: int) -> dict[str, Any]:
@@ -549,7 +550,7 @@ async def get_event_notifications(self, location_id: int) -> dict[str, Any]:
549550
"viewed": false
550551
}"""
551552
url = self._get_url(None, location_id, events=True)
552-
LOG.debug(f"Event Notifications URL is {url}")
553+
LOG.debug("Event Notifications URL is %s", url)
553554
return cast(dict[str, Any], await self.async_request("get", url))
554555

555556
async def get_gd_events(
@@ -622,7 +623,7 @@ async def get_gd_events(
622623
else:
623624
url += f"/{event_id}"
624625

625-
LOG.debug(f"get_gd_events URL is {url}")
626+
LOG.debug("get_gd_events URL is %s", url)
626627
return cast(dict[str, Any], await self.async_request("get", url))
627628

628629
async def get_seasons(self, location_id: int) -> dict[str, Any]:
@@ -645,13 +646,13 @@ async def get_seasons(self, location_id: int) -> dict[str, Any]:
645646
]
646647
"""
647648
url = self._get_url("Seasons", location_id, challenge=True)
648-
LOG.debug(f"Seasons URL is {url}")
649+
LOG.debug("Seasons URL is %s", url)
649650
return cast(dict[str, Any], await self.async_request("get", url))
650651

651652
async def get_gateway(self, location_id: int) -> dict[str, Any]:
652653
"""Gets info about the Hilo hub (gateway)"""
653654
url = self._get_url("Gateways/Info", location_id)
654-
LOG.debug(f"Gateway URL is {url}")
655+
LOG.debug("Gateway URL is %s", url)
655656
req = await self.async_request("get", url)
656657
saved_attrs = [
657658
"zigBeePairingActivated",
@@ -694,7 +695,7 @@ async def get_weather(self, location_id: int) -> dict[str, Any]:
694695
]
695696
"""
696697
url = self._get_url("Weather", location_id)
697-
LOG.debug(f"Weather URL is {url}")
698+
LOG.debug("Weather URL is %s", url)
698699
response = await self.async_request("get", url)
699-
LOG.debug(f"Weather API response: {response}")
700+
LOG.debug("Weather API response: %s", response)
700701
return cast(dict[str, Any], await self.async_request("get", url))

0 commit comments

Comments
 (0)