From 79a121263f2044ea24b86b25a0d2c3def44039e8 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Mon, 6 Mar 2023 18:57:08 +0100 Subject: [PATCH] Fix connection issues --- .gitignore | 2 +- README.md | 4 ++-- pyhon/api.py | 6 +++++- pyhon/appliances/wm.py | 3 ++- setup.py | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 6b7bc8d..6440f3c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ venv/ __pycache__/ dist/ **/*.egg-info/ -test.py +test* diff --git a/README.md b/README.md index 06a3c81..58fd35a 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ [![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 - 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 - Downloads](https://img.shields.io/pypi/dm/pyhOn)](https://pypistats.org/packages/pyhOn) +[![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) Control your Haier appliances with python! The idea behind this library is, to make the use of all available commands as simple as possible. diff --git a/pyhon/api.py b/pyhon/api.py index 7d147b2..8979344 100644 --- a/pyhon/api.py +++ b/pyhon/api.py @@ -84,7 +84,7 @@ class HonConnection: return {} return result - async def load_attributes(self, device: HonDevice): + async def load_attributes(self, device: HonDevice, loop=False): params = { "macAddress": device.mac_address, "applianceType": device.appliance_type_name, @@ -92,6 +92,10 @@ class HonConnection: } url = f"{const.API_URL}/commands/v1/context" async with self._session.get(url, params=params, headers=await self._headers) as response: + if response.status_code >= 400 and not loop: + _LOGGER.error("%s - Error %s - %s", url, response.status_code, await response.text) + await self.setup() + return await self.load_attributes(device, loop=True) return (await response.json()).get("payload", {}) async def load_statistics(self, device: HonDevice): diff --git a/pyhon/appliances/wm.py b/pyhon/appliances/wm.py index cc216df..5adc80d 100644 --- a/pyhon/appliances/wm.py +++ b/pyhon/appliances/wm.py @@ -3,5 +3,6 @@ class Appliance: self._data = data def get(self): - self._data["connected"] = self._data["lastConnEvent.category"] == "CONNECTED" + if self._data["lastConnEvent.category"] == "DISCONNECTED": + self._data["machMode"] = "0" return self._data diff --git a/setup.py b/setup.py index 931b05b..c5cfc0c 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.2.4", + version="0.2.5", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,