mirror of
https://github.com/Andre0512/pyhOn.git
synced 2024-12-22 18:55:32 +00:00
Improve logging
This commit is contained in:
parent
3e3fc7ad66
commit
ba208ffd98
|
@ -3,6 +3,7 @@ import logging
|
||||||
import re
|
import re
|
||||||
import secrets
|
import secrets
|
||||||
import urllib
|
import urllib
|
||||||
|
from pprint import pformat
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
|
|
||||||
from yarl import URL
|
from yarl import URL
|
||||||
|
@ -118,11 +119,14 @@ class HonAuth:
|
||||||
) as response:
|
) as response:
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
try:
|
try:
|
||||||
return (await response.json())["events"][0]["attributes"]["values"][
|
data = await response.json()
|
||||||
"url"
|
return data["events"][0]["attributes"]["values"]["url"]
|
||||||
]
|
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
pass
|
pass
|
||||||
|
except KeyError:
|
||||||
|
_LOGGER.error(
|
||||||
|
"Can't get login url - %s", pformat(await response.json())
|
||||||
|
)
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Unable to login: %s\n%s", response.status, await response.text()
|
"Unable to login: %s\n%s", response.status, await response.text()
|
||||||
)
|
)
|
||||||
|
@ -133,7 +137,10 @@ class HonAuth:
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
_LOGGER.error("Unable to get token: %s", resp.status)
|
_LOGGER.error("Unable to get token: %s", resp.status)
|
||||||
return False
|
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:
|
async with self._session.get(url[0]) as resp:
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
_LOGGER.error("Unable to get token: %s", resp.status)
|
_LOGGER.error("Unable to get token: %s", resp.status)
|
||||||
|
@ -188,5 +195,6 @@ class HonAuth:
|
||||||
if resp.status >= 400:
|
if resp.status >= 400:
|
||||||
return False
|
return False
|
||||||
data = await resp.json()
|
data = await resp.json()
|
||||||
self._id_token = data["id_token"]
|
self._id_token = data["id_token"]
|
||||||
self._access_token = data["access_token"]
|
self._access_token = data["access_token"]
|
||||||
|
return True
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -7,7 +7,7 @@ with open("README.md", "r") as f:
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="pyhOn",
|
name="pyhOn",
|
||||||
version="0.5.0",
|
version="0.6.0",
|
||||||
author="Andre Basche",
|
author="Andre Basche",
|
||||||
description="Control hOn devices with python",
|
description="Control hOn devices with python",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
|
|
Loading…
Reference in a new issue