Skip to content

Commit

Permalink
fix lint and test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thepiwo committed Apr 7, 2024
1 parent 928b6cc commit 014fae5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions iolite_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
3 changes: 3 additions & 0 deletions iolite_client/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def get_type(cls) -> str:
class Switch(Device):
pass


class Blind(Device):
def __init__(
self,
Expand All @@ -41,6 +42,7 @@ def __init__(
super().__init__(identifier, name, place_identifier, manufacturer)
self.blind_level = blind_level


class HumiditySensor(Device):
def __init__(
self,
Expand Down Expand Up @@ -95,6 +97,7 @@ def __init__(
self.device_status = device_status
self.current_env_temp = current_env_temp


class Heating(Entity):
def __init__(
self,
Expand Down
24 changes: 18 additions & 6 deletions iolite_client/entity_factory.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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"]
Expand All @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions iolite_client/oauth_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand All @@ -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
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion scripts/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 014fae5

Please sign in to comment.