Improve logging

This commit is contained in:
Andre Basche 2023-04-10 06:42:40 +02:00
parent 3e3fc7ad66
commit ba208ffd98
2 changed files with 15 additions and 7 deletions

View file

@ -3,6 +3,7 @@ import logging
import re
import secrets
import urllib
from pprint import pformat
from urllib import parse
from yarl import URL
@ -118,11 +119,14 @@ class HonAuth:
) as response:
if response.status == 200:
try:
return (await response.json())["events"][0]["attributes"]["values"][
"url"
]
data = await response.json()
return data["events"][0]["attributes"]["values"]["url"]
except json.JSONDecodeError:
pass
except KeyError:
_LOGGER.error(
"Can't get login url - %s", pformat(await response.json())
)
_LOGGER.error(
"Unable to login: %s\n%s", response.status, await response.text()
)
@ -133,7 +137,10 @@ class HonAuth:
if resp.status != 200:
_LOGGER.error("Unable to get token: %s", resp.status)
return False
url = re.findall("href\\s*=\\s*[\"'](.*?)[\"']", await resp.text())
url = re.findall("href\\s*=\\s*[\"'](http.+?)[\"']", await resp.text())
if not url:
_LOGGER.error("Can't get login url - \n%s", await resp.text())
raise PermissionError
async with self._session.get(url[0]) as resp:
if resp.status != 200:
_LOGGER.error("Unable to get token: %s", resp.status)
@ -190,3 +197,4 @@ class HonAuth:
data = await resp.json()
self._id_token = data["id_token"]
self._access_token = data["access_token"]
return True

View file

@ -7,7 +7,7 @@ with open("README.md", "r") as f:
setup(
name="pyhOn",
version="0.5.0",
version="0.6.0",
author="Andre Basche",
description="Control hOn devices with python",
long_description=long_description,