mirror of
https://github.com/Andre0512/pyhOn.git
synced 2024-01-19 02:50:44 +00:00
Improve
This commit is contained in:
parent
cf481e5f13
commit
984d1b91b7
19
pyhon/api.py
19
pyhon/api.py
|
@ -1,3 +1,4 @@
|
||||||
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import secrets
|
import secrets
|
||||||
|
@ -6,20 +7,20 @@ from typing import List
|
||||||
|
|
||||||
import aiohttp as aiohttp
|
import aiohttp as aiohttp
|
||||||
|
|
||||||
import const
|
from pyhon import const
|
||||||
from auth import HonAuth
|
from pyhon.auth import HonAuth
|
||||||
from device import HonDevice
|
from pyhon.device import HonDevice
|
||||||
|
|
||||||
_LOGGER = logging.getLogger()
|
_LOGGER = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class HonConnection:
|
class HonConnection:
|
||||||
def __init__(self, email, password) -> None:
|
def __init__(self, email, password, session=None) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._email = email
|
self._email = email
|
||||||
self._password = password
|
self._password = password
|
||||||
self._request_headers = {"Content-Type": "application/json"}
|
self._request_headers = {"Content-Type": "application/json"}
|
||||||
self._session = None
|
self._session = session
|
||||||
self._devices = []
|
self._devices = []
|
||||||
self._mobile_id = secrets.token_hex(8)
|
self._mobile_id = secrets.token_hex(8)
|
||||||
|
|
||||||
|
@ -51,7 +52,13 @@ class HonConnection:
|
||||||
headers=await self._headers) as resp:
|
headers=await self._headers) as resp:
|
||||||
try:
|
try:
|
||||||
appliances = (await resp.json())["payload"]["appliances"]
|
appliances = (await resp.json())["payload"]["appliances"]
|
||||||
self._devices = [HonDevice(self, appliance) for appliance in appliances]
|
for appliance in appliances:
|
||||||
|
device = HonDevice(self, appliance)
|
||||||
|
await asyncio.gather(*[
|
||||||
|
device.load_attributes(),
|
||||||
|
device.load_commands(),
|
||||||
|
device.load_statistics()])
|
||||||
|
self._devices.append(device)
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
_LOGGER.error("No JSON Data after GET: %s", await resp.text())
|
_LOGGER.error("No JSON Data after GET: %s", await resp.text())
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -7,7 +7,7 @@ from urllib import parse
|
||||||
|
|
||||||
import aiohttp as aiohttp
|
import aiohttp as aiohttp
|
||||||
|
|
||||||
import const
|
from pyhon import const
|
||||||
|
|
||||||
_LOGGER = logging.getLogger()
|
_LOGGER = logging.getLogger()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from parameter import HonParameterFixed, HonParameterEnum, HonParameterRange
|
from pyhon.parameter import HonParameterFixed, HonParameterEnum, HonParameterRange
|
||||||
|
|
||||||
|
|
||||||
class HonCommand:
|
class HonCommand:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from commands import HonCommand
|
from pyhon.commands import HonCommand
|
||||||
|
|
||||||
|
|
||||||
class HonDevice:
|
class HonDevice:
|
||||||
|
@ -147,3 +147,6 @@ class HonDevice:
|
||||||
|
|
||||||
async def load_statistics(self):
|
async def load_statistics(self):
|
||||||
self._statistics = await self._connector.load_statistics(self)
|
self._statistics = await self._connector.load_statistics(self)
|
||||||
|
|
||||||
|
async def update(self):
|
||||||
|
await self.load_attributes()
|
||||||
|
|
9
setup.py
9
setup.py
|
@ -1,22 +1,21 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from setuptools import setup
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
with open("README.md", "r") as f:
|
with open("README.md", "r") as f:
|
||||||
long_description = f.read()
|
long_description = f.read()
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="pyhon",
|
name="pyhon",
|
||||||
version="0.0.1",
|
version="0.0.5",
|
||||||
author="Andre Basche",
|
author="Andre Basche",
|
||||||
description="Control Haier devices with pyhon",
|
description="Control hOn devices with python",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type='text/markdown',
|
long_description_content_type='text/markdown',
|
||||||
url="https://github.com/Andre0512/pyhon",
|
url="https://github.com/Andre0512/pyhon",
|
||||||
license="MIT",
|
license="MIT",
|
||||||
platforms="any",
|
platforms="any",
|
||||||
package_dir={"": "pyhon"},
|
packages=find_packages(),
|
||||||
packages=[""],
|
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
python_requires=">=3.10",
|
python_requires=">=3.10",
|
||||||
install_requires=["aiohttp"]
|
install_requires=["aiohttp"]
|
||||||
|
|
Loading…
Reference in a new issue