Skip to content

Commit

Permalink
Comment and old stuff cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ic-dev21 committed Mar 1, 2025
1 parent 95cb1e7 commit 60e5297
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
7 changes: 3 additions & 4 deletions pyhilo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,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(f"ic-dev21 access token is {access_token}")
LOG.debug(f"Websocket access token is {access_token}")

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

Expand Down Expand Up @@ -238,9 +238,8 @@ async def _async_request(
kwargs["headers"]["authorization"] = f"Bearer {access_token}"
kwargs["headers"]["Host"] = host

# ic-dev21 trying Leicas suggestion
if endpoint.startswith(AUTOMATION_CHALLENGE_ENDPOINT):
# remove Ocp-Apim-Subscription-Key header to avoid 401 error
# remove Ocp-Apim-Subscription-Key header to avoid 401 error (Thanks Leicas)
kwargs["headers"].pop("Ocp-Apim-Subscription-Key", None)
kwargs["headers"]["authorization"] = f"Bearer {access_token}"

Expand Down Expand Up @@ -369,7 +368,7 @@ def enable_request_retries(self) -> None:

async def _async_post_init(self) -> None:
"""Perform some post-init actions."""
LOG.debug("Websocket postinit")
LOG.debug("Websocket _async_post_init running")
await self._get_fid()
await self._get_device_token()

Expand Down
4 changes: 0 additions & 4 deletions pyhilo/oauth2.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
"""Custom OAuth2 implementation."""

import base64
import hashlib
import os
import re
from typing import Any, cast

from homeassistant.core import HomeAssistant
Expand Down
1 change: 1 addition & 0 deletions pyhilo/oauth2helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
AUTH_TOKEN,
)


class OAuth2Helper:
"""Custom OAuth2 implementation."""

Expand Down
6 changes: 2 additions & 4 deletions pyhilo/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async def _async_send_json(self, payload: dict[str, Any]) -> None:
)
# Hilo added a control character (chr(30)) at the end of each payload they send.
# They also expect this char to be there at the end of every payload we send them.
LOG.debug(f"ic-dev21 send_json {payload}")
LOG.debug(f"WebsocketClient _async_send_json payload: {payload}")
await self._client.send_str(json.dumps(payload) + chr(30))

def _parse_message(self, msg: dict[str, Any]) -> None:
Expand Down Expand Up @@ -378,7 +378,7 @@ async def async_invoke(
return
self._ready_event.clear()
LOG.debug(
f"ic-dev21 invoke argument: {arg}, invocationId: {inv_id}, target: {target}, type: {type}"
f"async_invoke invoke argument: {arg}, invocationId: {inv_id}, target: {target}, type: {type}"
)
await self._async_send_json(
{
Expand Down Expand Up @@ -436,9 +436,7 @@ def __init__(

async def initialize_websockets(self) -> None:
"""Initialize both websocket connections"""
# ic-dev21 get token from device hub
await self.refresh_token(self.devicehub, get_new_token=True)
# ic-dev21 get token from challenge hub
await self.refresh_token(self.challengehub, get_new_token=True)

async def refresh_token(
Expand Down

0 comments on commit 60e5297

Please sign in to comment.