diff --git a/pyhon/api.py b/pyhon/api.py index d6172df..d018c67 100644 --- a/pyhon/api.py +++ b/pyhon/api.py @@ -1,3 +1,4 @@ +import asyncio import json import logging import secrets @@ -6,20 +7,20 @@ from typing import List import aiohttp as aiohttp -import const -from auth import HonAuth -from device import HonDevice +from pyhon import const +from pyhon.auth import HonAuth +from pyhon.device import HonDevice _LOGGER = logging.getLogger() class HonConnection: - def __init__(self, email, password) -> None: + def __init__(self, email, password, session=None) -> None: super().__init__() self._email = email self._password = password self._request_headers = {"Content-Type": "application/json"} - self._session = None + self._session = session self._devices = [] self._mobile_id = secrets.token_hex(8) @@ -51,7 +52,13 @@ class HonConnection: headers=await self._headers) as resp: try: 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: _LOGGER.error("No JSON Data after GET: %s", await resp.text()) return False diff --git a/pyhon/auth.py b/pyhon/auth.py index bfc6b0a..333df2a 100644 --- a/pyhon/auth.py +++ b/pyhon/auth.py @@ -7,7 +7,7 @@ from urllib import parse import aiohttp as aiohttp -import const +from pyhon import const _LOGGER = logging.getLogger() diff --git a/pyhon/commands.py b/pyhon/commands.py index ed7c515..84333af 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -1,4 +1,4 @@ -from parameter import HonParameterFixed, HonParameterEnum, HonParameterRange +from pyhon.parameter import HonParameterFixed, HonParameterEnum, HonParameterRange class HonCommand: diff --git a/pyhon/device.py b/pyhon/device.py index 0b59ea2..bdeb974 100644 --- a/pyhon/device.py +++ b/pyhon/device.py @@ -1,4 +1,4 @@ -from commands import HonCommand +from pyhon.commands import HonCommand class HonDevice: @@ -147,3 +147,6 @@ class HonDevice: async def load_statistics(self): self._statistics = await self._connector.load_statistics(self) + + async def update(self): + await self.load_attributes() diff --git a/setup.py b/setup.py index c49de9f..7710e44 100644 --- a/setup.py +++ b/setup.py @@ -1,22 +1,21 @@ #!/usr/bin/env python3 -from setuptools import setup +from setuptools import setup, find_packages with open("README.md", "r") as f: long_description = f.read() setup( name="pyhon", - version="0.0.1", + version="0.0.5", author="Andre Basche", - description="Control Haier devices with pyhon", + description="Control hOn devices with python", long_description=long_description, long_description_content_type='text/markdown', url="https://github.com/Andre0512/pyhon", license="MIT", platforms="any", - package_dir={"": "pyhon"}, - packages=[""], + packages=find_packages(), include_package_data=True, python_requires=">=3.10", install_requires=["aiohttp"]