From 31606db3c963987cba4e0134301f324632ad991d Mon Sep 17 00:00:00 2001 From: fustom Date: Fri, 10 Jan 2025 14:09:14 +0100 Subject: [PATCH] Fix python errors (#167) --- ariston/__init__.py | 4 ++-- ariston/ariston_api.py | 4 ++-- ariston/base_device.py | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ariston/__init__.py b/ariston/__init__.py index de5e34f..3f3b64c 100644 --- a/ariston/__init__.py +++ b/ariston/__init__.py @@ -49,11 +49,11 @@ async def async_connect( self.api = AristonAPI(username, password, api_url, user_agent) return await self.api.async_connect() - async def async_discover(self) -> Optional[list[dict[str, Any]]]: + async def async_discover(self) -> list[dict[str, Any]]: """Retreive ariston devices from the cloud""" if self.api is None: _LOGGER.exception("Call async_connect first") - return None + return [] cloud_devices = await _async_discover(self.api) self.cloud_devices = cloud_devices return cloud_devices diff --git a/ariston/ariston_api.py b/ariston/ariston_api.py index 7b70c60..5127ffa 100644 --- a/ariston/ariston_api.py +++ b/ariston/ariston_api.py @@ -466,8 +466,8 @@ def __request( case 404: return None case 429: - content = response.content.read_nowait() - raise Exception(response.status, content) + content = response.content.decode() + raise Exception(response.status_code, content) case _: if not is_retry: time.sleep(5) diff --git a/ariston/base_device.py b/ariston/base_device.py index c257acd..ec667f8 100644 --- a/ariston/base_device.py +++ b/ariston/base_device.py @@ -38,7 +38,7 @@ def __init__( self.consumptions_sequences: list[dict[str, Any]] = list() self.data: dict[str, Any] = dict() self.consumption_sequence_last_changed_utc: dt.datetime = ( - dt.datetime.utcfromtimestamp(0).replace(tzinfo=dt.timezone.utc) + dt.datetime.fromtimestamp(0, dt.UTC).replace(tzinfo=dt.timezone.utc) ) self.gw: str = self.attributes.get(DeviceAttribute.GW, "") self.bus_errors_list: list[dict[str, Any]] = [] @@ -318,7 +318,7 @@ def _set_energy_features(self): def are_device_features_available( self, - device_features: Optional[list[DeviceFeatures | CustomDeviceFeatures | DeviceAttribute]], + device_features: Optional[list[str]], system_types: Optional[list[SystemType]], whe_types: Optional[list[WheType]], ) -> bool: @@ -332,9 +332,9 @@ def are_device_features_available( if device_features is not None: for device_feature in device_features: if ( - self.features.get(str(device_feature)) is not True - and self.custom_features.get(str(device_feature)) is not True - and self.attributes.get(str(device_feature)) is not True + self.features.get(device_feature) is not True + and self.custom_features.get(device_feature) is not True + and self.attributes.get(device_feature) is not True ): return False