Compare commits

...

2 Commits

Author SHA1 Message Date
43d61ab853 Show more command data 2023-03-06 19:45:46 +01:00
79a121263f Fix connection issues 2023-03-06 18:57:08 +01:00
9 changed files with 30 additions and 15 deletions

2
.gitignore vendored
View File

@ -3,4 +3,4 @@ venv/
__pycache__/ __pycache__/
dist/ dist/
**/*.egg-info/ **/*.egg-info/
test.py test*

View File

@ -4,8 +4,8 @@
[![PyPI - Status](https://img.shields.io/pypi/status/pyhOn)](https://pypi.org/project/pyhOn) [![PyPI - Status](https://img.shields.io/pypi/status/pyhOn)](https://pypi.org/project/pyhOn)
[![PyPI](https://img.shields.io/pypi/v/pyhOn?color=blue)](https://pypi.org/project/pyhOn) [![PyPI](https://img.shields.io/pypi/v/pyhOn?color=blue)](https://pypi.org/project/pyhOn)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyhOn)](https://www.python.org/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyhOn)](https://www.python.org/)
[![PyPI - License](https://img.shields.io/pypi/l/pyhOn)](https://github.com/Andre0512/pyhOn/blob/main/LICENCE) [![PyPI - License](https://img.shields.io/pypi/l/pyhOn)](https://github.com/Andre0512/pyhOn/blob/main/LICENSE)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/pyhOn)](https://pypistats.org/packages/pyhOn) [![PyPI - Downloads](https://img.shields.io/pypi/dm/pyhOn)](https://pypistats.org/packages/pyhon)
Control your Haier appliances with python! Control your Haier appliances with python!
The idea behind this library is, to make the use of all available commands as simple as possible. The idea behind this library is, to make the use of all available commands as simple as possible.

View File

@ -24,7 +24,7 @@ def get_arguments():
return vars(parser.parse_args()) return vars(parser.parse_args())
# yaml.dump() would be done the same, but needs an additional import... # yaml.dump() would be done the same, but needs an additional dependency...
def pretty_print(data, key="", intend=0, is_list=False): def pretty_print(data, key="", intend=0, is_list=False):
if type(data) is list: if type(data) is list:
if key: if key:
@ -47,6 +47,18 @@ def pretty_print(data, key="", intend=0, is_list=False):
print(f"{' ' * intend}{'- ' if is_list else ''}{key}{': ' if key else ''}{data}") print(f"{' ' * intend}{'- ' if is_list else ''}{key}{': ' if key else ''}{data}")
def create_command(commands):
result = {}
for name, command in commands.items():
result[name] = {}
for parameter, data in command.parameters.items():
if data.typology == "enum":
result[name][parameter] = data.values
if data.typology == "range":
result[name][parameter] = {"min": data.min, "max": data.max, "step": data.step}
return result
async def main(): async def main():
args = get_arguments() args = get_arguments()
if not (user := args["user"]): if not (user := args["user"]):

View File

@ -84,7 +84,7 @@ class HonConnection:
return {} return {}
return result return result
async def load_attributes(self, device: HonDevice): async def load_attributes(self, device: HonDevice, loop=False):
params = { params = {
"macAddress": device.mac_address, "macAddress": device.mac_address,
"applianceType": device.appliance_type_name, "applianceType": device.appliance_type_name,
@ -92,6 +92,10 @@ class HonConnection:
} }
url = f"{const.API_URL}/commands/v1/context" url = f"{const.API_URL}/commands/v1/context"
async with self._session.get(url, params=params, headers=await self._headers) as response: async with self._session.get(url, params=params, headers=await self._headers) as response:
if response.status >= 400 and not loop:
_LOGGER.error("%s - Error %s - %s", url, response.status, await response.text)
await self.setup()
return await self.load_attributes(device, loop=True)
return (await response.json()).get("payload", {}) return (await response.json()).get("payload", {})
async def load_statistics(self, device: HonDevice): async def load_statistics(self, device: HonDevice):

View File

@ -3,5 +3,6 @@ class Appliance:
self._data = data self._data = data
def get(self): def get(self):
self._data["connected"] = self._data["lastConnEvent.category"] == "CONNECTED" if self._data["lastConnEvent.category"] == "DISCONNECTED":
self._data["machMode"] = "0"
return self._data return self._data

View File

@ -31,18 +31,15 @@ class HonCommand:
@property @property
def parameters(self): def parameters(self):
result = {key: parameter.value for key, parameter in self._parameters.items()} return self._parameters
if self._multi:
result |= {"program": self._category}
return result
@property @property
def ancillary_parameters(self): def ancillary_parameters(self):
return {key: parameter.value for key, parameter in self._ancillary_parameters.items()} return {key: parameter.value for key, parameter in self._ancillary_parameters.items()}
async def send(self): async def send(self):
return await self._connector.send_command(self._device, self._name, self.parameters, parameters = {name: parameter.value for name, parameter in self._parameters}
self.ancillary_parameters) return await self._connector.send_command(self._device, self._name, parameters, self.ancillary_parameters)
def get_programs(self): def get_programs(self):
return self._multi return self._multi

View File

@ -162,7 +162,7 @@ class HonDevice:
result = {} result = {}
for name, command in self._commands.items(): for name, command in self._commands.items():
for key, parameter in command.parameters.items(): for key, parameter in command.parameters.items():
result[f"{name}.{key}"] = parameter result[f"{name}.{key}"] = parameter.value
return result return result
async def load_attributes(self): async def load_attributes(self):

View File

@ -113,6 +113,7 @@ class HonParameterProgram(HonParameterEnum):
self._command = command self._command = command
self._value = command._category self._value = command._category
self._values = command._multi self._values = command._multi
self._typology = "enum"
@property @property
def value(self): def value(self):

View File

@ -7,7 +7,7 @@ with open("README.md", "r") as f:
setup( setup(
name="pyhOn", name="pyhOn",
version="0.2.4", version="0.2.6",
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,
@ -23,7 +23,7 @@ setup(
python_requires=">=3.10", python_requires=">=3.10",
install_requires=["aiohttp"], install_requires=["aiohttp"],
classifiers=[ classifiers=[
"Development Status :: 3 - Alpha", "Development Status :: 4 - Beta",
"Environment :: Console", "Environment :: Console",
"License :: OSI Approved :: MIT License", "License :: OSI Approved :: MIT License",
"Natural Language :: English", "Natural Language :: English",