mirror of
https://github.com/Andre0512/pyhOn.git
synced 2026-06-20 12:26:17 +02:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 59e3d9949f | |||
| 3f39be53f3 | |||
| afb5b8c3ea | |||
| 63752e13d6 |
@@ -78,6 +78,7 @@ class HonAPI:
|
||||
self._password,
|
||||
session=self._session,
|
||||
mobile_id=self._mobile_id,
|
||||
refresh_token=self._refresh_token,
|
||||
).create()
|
||||
return self
|
||||
|
||||
|
||||
@@ -120,18 +120,23 @@ class HonAuth:
|
||||
async with self._request.get(url) as response:
|
||||
text = await response.text()
|
||||
self._expires = datetime.utcnow()
|
||||
login_url: List[str] = re.findall("url = '(.+?)'", text)
|
||||
login_url: List[str] = re.findall("(?:url|href) ?= ?'(.+?)'", text)
|
||||
if not login_url:
|
||||
if "oauth/done#access_token=" in text:
|
||||
self._parse_token_data(text)
|
||||
raise exceptions.HonNoAuthenticationNeeded()
|
||||
await self._error_logger(response)
|
||||
# As of July 2024 the login page has changed, and we started getting a /NewhOnLogin based relative URL in JS to parse
|
||||
if login_url[0].startswith("/NewhOnLogin"):
|
||||
# Force use of the old login page to avoid having to make the new one work..
|
||||
login_url[0] = f"{const.AUTH_API}/s/login{login_url[0]}"
|
||||
return login_url[0]
|
||||
|
||||
async def _manual_redirect(self, url: str) -> str:
|
||||
async with self._request.get(url, allow_redirects=False) as response:
|
||||
if not (new_location := response.headers.get("Location", "")):
|
||||
await self._error_logger(response)
|
||||
new_location = response.headers.get("Location", "")
|
||||
if not new_location:
|
||||
return url
|
||||
return new_location
|
||||
|
||||
async def _handle_redirects(self, login_url: str) -> str:
|
||||
|
||||
@@ -62,6 +62,7 @@ class HonConnectionHandler(ConnectionHandler):
|
||||
await self.auth.refresh(self._refresh_token)
|
||||
if not (self.auth.cognito_token and self.auth.id_token):
|
||||
await self.auth.authenticate()
|
||||
self._refresh_token = self.auth.refresh_token
|
||||
headers["cognito-token"] = self.auth.cognito_token
|
||||
headers["id-token"] = self.auth.id_token
|
||||
return self._HEADERS | headers
|
||||
@@ -77,7 +78,7 @@ class HonConnectionHandler(ConnectionHandler):
|
||||
self.auth.token_expires_soon or response.status in [401, 403]
|
||||
) and loop == 0:
|
||||
_LOGGER.info("Try refreshing token...")
|
||||
await self.auth.refresh()
|
||||
await self.auth.refresh(self._refresh_token)
|
||||
async with self._intercept(
|
||||
method, url, *args, loop=loop + 1, **kwargs
|
||||
) as result:
|
||||
|
||||
@@ -35,6 +35,7 @@ class MQTTClient:
|
||||
async def create(self) -> "MQTTClient":
|
||||
await self._start()
|
||||
self._subscribe_appliances()
|
||||
await self.start_watchdog()
|
||||
return self
|
||||
|
||||
def _on_lifecycle_stopped(
|
||||
@@ -63,6 +64,7 @@ class MQTTClient:
|
||||
self,
|
||||
lifecycle_connection_failure_data: mqtt5.LifecycleConnectFailureData,
|
||||
) -> None:
|
||||
self._connection = False
|
||||
_LOGGER.info(
|
||||
"Lifecycle Connection Failure - %s", str(lifecycle_connection_failure_data)
|
||||
)
|
||||
@@ -88,7 +90,6 @@ class MQTTClient:
|
||||
parameter
|
||||
)
|
||||
appliance.sync_params_to_command("settings")
|
||||
self._hon.notify()
|
||||
elif topic and "disconnected" in topic:
|
||||
_LOGGER.info(
|
||||
"Disconnected %s: %s",
|
||||
@@ -101,6 +102,7 @@ class MQTTClient:
|
||||
_LOGGER.info("Connected %s", appliance.nick_name)
|
||||
elif topic and "discovery" in topic:
|
||||
_LOGGER.info("Discovered %s", appliance.nick_name)
|
||||
self._hon.notify()
|
||||
_LOGGER.info("%s - %s", topic, payload)
|
||||
|
||||
async def _start(self) -> None:
|
||||
@@ -133,7 +135,7 @@ class MQTTClient:
|
||||
|
||||
async def start_watchdog(self) -> None:
|
||||
if not self._watchdog_task or self._watchdog_task.done():
|
||||
await asyncio.create_task(self._watchdog())
|
||||
self._watchdog_task = asyncio.create_task(self._watchdog())
|
||||
|
||||
async def _watchdog(self) -> None:
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user