From 014fae57caf415bb3fb543bda7606e3e988fe008 Mon Sep 17 00:00:00 2001 From: Philipp Piwo Date: Sun, 7 Apr 2024 20:32:51 +0200 Subject: [PATCH] fix lint and test issues --- iolite_client/client.py | 4 ++-- iolite_client/entity.py | 3 +++ iolite_client/entity_factory.py | 24 ++++++++++++++++++------ iolite_client/oauth_handler.py | 14 +++++++++++--- scripts/example.py | 2 +- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/iolite_client/client.py b/iolite_client/client.py index 86fea2e..b1163d6 100755 --- a/iolite_client/client.py +++ b/iolite_client/client.py @@ -309,7 +309,7 @@ async def async_set_property(self, device, property: str, value: float): await asyncio.create_task(self._fetch_application([request])) def set_temp(self, device, value: float): - asyncio.run(self.async_set_property(device, 'heatingTemperatureSetting', value)) + asyncio.run(self.async_set_property(device, "heatingTemperatureSetting", value)) def set_blind_level(self, device, value: float): - asyncio.run(self.async_set_property(device, 'blindLevel', value)) + asyncio.run(self.async_set_property(device, "blindLevel", value)) diff --git a/iolite_client/entity.py b/iolite_client/entity.py index 257da07..a05788a 100644 --- a/iolite_client/entity.py +++ b/iolite_client/entity.py @@ -29,6 +29,7 @@ def get_type(cls) -> str: class Switch(Device): pass + class Blind(Device): def __init__( self, @@ -41,6 +42,7 @@ def __init__( super().__init__(identifier, name, place_identifier, manufacturer) self.blind_level = blind_level + class HumiditySensor(Device): def __init__( self, @@ -95,6 +97,7 @@ def __init__( self.device_status = device_status self.current_env_temp = current_env_temp + class Heating(Entity): def __init__( self, diff --git a/iolite_client/entity_factory.py b/iolite_client/entity_factory.py index e65e2e9..71360e6 100644 --- a/iolite_client/entity_factory.py +++ b/iolite_client/entity_factory.py @@ -1,4 +1,14 @@ -from iolite_client.entity import Device, Heating, Lamp, RadiatorValve, InFloorValve, Room, Switch, Blind, HumiditySensor +from iolite_client.entity import ( + Blind, + Device, + Heating, + HumiditySensor, + InFloorValve, + Lamp, + RadiatorValve, + Room, + Switch, +) from iolite_client.exceptions import UnsupportedDeviceError @@ -50,7 +60,7 @@ def create_heating(payload: dict) -> Heating: def _create_device(identifier: str, type_name: str, payload: dict): place_identifier = payload["placeIdentifier"] - model_name = payload["modelName"] + model_name = payload.get("modelName", None) if type_name == "Lamp": return Lamp( identifier, @@ -76,8 +86,10 @@ def _create_device(identifier: str, type_name: str, payload: dict): properties = payload["properties"] current_env_temp = _get_prop(properties, "currentEnvironmentTemperature") - if model_name.startswith("38de6001c3ad"): - heating_temperature_setting = _get_prop(properties, "heatingTemperatureSetting") + if model_name is not None and model_name.startswith("38de6001c3ad"): + heating_temperature_setting = _get_prop( + properties, "heatingTemperatureSetting" + ) device_status = _get_prop(properties, "deviceStatus") return InFloorValve( identifier, @@ -113,7 +125,7 @@ def _create_device(identifier: str, type_name: str, payload: dict): payload["friendlyName"], place_identifier, payload["manufacturer"], - blind_level + blind_level, ) elif type_name == "HumiditySensor": properties = payload["properties"] @@ -126,7 +138,7 @@ def _create_device(identifier: str, type_name: str, payload: dict): place_identifier, payload["manufacturer"], current_env_temp, - humidity_level + humidity_level, ) else: raise UnsupportedDeviceError(type_name, identifier, payload) diff --git a/iolite_client/oauth_handler.py b/iolite_client/oauth_handler.py index 3e4b6cf..e09f282 100644 --- a/iolite_client/oauth_handler.py +++ b/iolite_client/oauth_handler.py @@ -78,7 +78,9 @@ def get_new_access_token(self, refresh_token: str) -> dict: :param refresh_token: The refresh token :return: dict containing access token, and new refresh token """ - query = OAuthHandlerHelper.get_new_access_token_query(refresh_token, self.client_id) + query = OAuthHandlerHelper.get_new_access_token_query( + refresh_token, self.client_id + ) response = requests.post( f"{BASE_URL}/ui/token?{query}", auth=(self.username, self.password) ) @@ -101,7 +103,11 @@ def get_sid(self, access_token: str) -> str: class AsyncOAuthHandler: def __init__( - self, username: str, password: str, web_session: aiohttp.ClientSession, client_id: str = CLIENT_ID + self, + username: str, + password: str, + web_session: aiohttp.ClientSession, + client_id: str = CLIENT_ID, ): self.username = username self.password = password @@ -129,7 +135,9 @@ async def get_new_access_token(self, refresh_token: str) -> dict: :param refresh_token: The refresh token :return: dict containing access token, and new refresh token """ - query = OAuthHandlerHelper.get_new_access_token_query(refresh_token, self.client_id) + query = OAuthHandlerHelper.get_new_access_token_query( + refresh_token, self.client_id + ) response = await self.web_session.post( f"{BASE_URL}/ui/token?{query}", auth=aiohttp.BasicAuth(self.username, self.password), diff --git a/scripts/example.py b/scripts/example.py index 54e1659..593aa6f 100644 --- a/scripts/example.py +++ b/scripts/example.py @@ -4,7 +4,7 @@ from environs import Env from iolite_client.client import Client -from iolite_client.entity import RadiatorValve, Blind, HumiditySensor, InFloorValve +from iolite_client.entity import Blind, HumiditySensor, InFloorValve, RadiatorValve from iolite_client.oauth_handler import LocalOAuthStorage, OAuthHandler, OAuthWrapper env = Env()