From afb5b8c3ea53ed62e6922f95c8563517e13b9d9c Mon Sep 17 00:00:00 2001 From: addshore Date: Wed, 10 Jul 2024 12:39:18 +0100 Subject: [PATCH 1/2] Update for new hOn login https://github.com/Andre0512/hon/issues/230 --- pyhon/connection/auth.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pyhon/connection/auth.py b/pyhon/connection/auth.py index 2096010..3ab491c 100644 --- a/pyhon/connection/auth.py +++ b/pyhon/connection/auth.py @@ -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: From 3f39be53f31885fb84d72f91fb4123c2e39e7156 Mon Sep 17 00:00:00 2001 From: addshore Date: Wed, 10 Jul 2024 12:47:30 +0100 Subject: [PATCH 2/2] Bump 0.17.5 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 115205d..1e8e2fc 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r", encoding="utf-8") as f: setup( name="pyhOn", - version="0.17.4", + version="0.17.5", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,