Improve
This commit is contained in:
		
							
								
								
									
										19
									
								
								pyhon/api.py
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								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
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ from urllib import parse
 | 
			
		||||
 | 
			
		||||
import aiohttp as aiohttp
 | 
			
		||||
 | 
			
		||||
import const
 | 
			
		||||
from pyhon import const
 | 
			
		||||
 | 
			
		||||
_LOGGER = logging.getLogger()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
from parameter import HonParameterFixed, HonParameterEnum, HonParameterRange
 | 
			
		||||
from pyhon.parameter import HonParameterFixed, HonParameterEnum, HonParameterRange
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class HonCommand:
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								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"]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user