Skip to content

Commit

Permalink
Merge pull request #19 from andrey-git/strict_typing
Browse files Browse the repository at this point in the history
Strict typing
  • Loading branch information
gjohansson-ST authored May 26, 2022
2 parents 6feaada + 205419a commit a43417b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
60 changes: 34 additions & 26 deletions pysensibo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ async def async_get_devices_data(self) -> SensiboData:
devices.append(device)

device_data: dict[str, SensiboDevice] = {}
dev: dict
dev: dict[str, Any]
for dev in devices:
unique_id = dev["id"]
mac = dev["macAddress"]
name = dev["room"]["name"]
measure: dict = dev["measurements"]
measure: dict[str, Any] = dev["measurements"]
temperature = measure.get("temperature")
humidity = measure.get("humidity")
ac_states: dict = dev["acState"]
ac_states: dict[str, Any] = dev["acState"]
target_temperature = ac_states.get("targetTemperature")
hvac_mode = ac_states.get("mode")
running = ac_states.get("on")
Expand All @@ -75,7 +75,9 @@ async def async_get_devices_data(self) -> SensiboData:
hvac_modes = list(capabilities["modes"])
if hvac_modes:
hvac_modes.append("off")
current_capabilities: dict = capabilities["modes"][ac_states.get("mode")]
current_capabilities: dict[str, Any] = capabilities["modes"][
ac_states.get("mode")
]
fan_modes = current_capabilities.get("fanLevels")
swing_modes = current_capabilities.get("swing")
horizontal_swing_modes = current_capabilities.get("horizontalSwing")
Expand Down Expand Up @@ -116,7 +118,7 @@ async def async_get_devices_data(self) -> SensiboData:
fw_type = dev["firmwareType"]
model = dev["productModel"]

calibration: dict = dev["sensorsCalibration"]
calibration: dict[str, float] = dev["sensorsCalibration"]
calibration_temp = calibration.get("temperature")
calibration_hum = calibration.get("humidity")

Expand All @@ -128,10 +130,10 @@ async def async_get_devices_data(self) -> SensiboData:

motion_sensors: dict[str, MotionSensor] = {}
if dev["motionSensors"]:
sensor: dict
sensor: dict[str, Any]
for sensor in dev["motionSensors"]:
measurement: dict = sensor["measurements"]
connection: dict = sensor["connectionStatus"]
measurement: dict[str, Any] = sensor["measurements"]
connection: dict[str, Any] = sensor["connectionStatus"]
motion_sensors[sensor["id"]] = MotionSensor(
id=sensor["id"],
alive=connection.get("isAlive"),
Expand All @@ -147,12 +149,14 @@ async def async_get_devices_data(self) -> SensiboData:
)

# Add information for pure devices
pure_conf: dict = dev["pureBoostConfig"] if dev["pureBoostConfig"] else {}
pure_boost_enabled = None
pure_sensitivity = None
pure_ac_integration = None
pure_geo_integration = None
pure_measure_integration = None
pure_conf: dict[str, Any] = (
dev["pureBoostConfig"] if dev["pureBoostConfig"] else {}
)
pure_boost_enabled: bool | None = None
pure_sensitivity: str | None = None
pure_ac_integration: bool | None = None
pure_geo_integration: bool | None = None
pure_measure_integration: bool | None = None
if dev["productModel"] == "pure":
pure_boost_enabled = pure_conf.get("enabled", False)
pure_sensitivity = pure_conf.get("sensitivity", "off")
Expand All @@ -170,26 +174,30 @@ async def async_get_devices_data(self) -> SensiboData:
)

# Filters
filters: dict = dev["filtersCleaning"] if dev["filtersCleaning"] else {}
filter_clean = filters.get("shouldCleanFilters", False)
clean_time: dict = filters.get("lastFiltersCleanTime") or {}
filter_last_reset = clean_time.get("time") if clean_time else None
filters: dict[str, Any] = (
dev["filtersCleaning"] if dev["filtersCleaning"] else {}
)
filter_clean: bool = filters.get("shouldCleanFilters", False)
clean_time: dict[str, Any] = filters.get("lastFiltersCleanTime") or {}
filter_last_reset: str | None = (
clean_time.get("time") if clean_time else None
)

# Timer
timer: dict = dev["timer"] if dev["timer"] else {}
timer: dict[str, Any] = dev["timer"] if dev["timer"] else {}
timer_on = None
timer_id = None
timer_state_on = None
timer_time = None
if dev["productModel"] != "pure":
timer_on = timer.get("isEnabled", False)
timer_id = timer.get("id")
timer_state: dict | None = timer.get("acState")
timer_state: dict[str, Any] | None = timer.get("acState")
timer_state_on = timer_state.get("on") if timer_state else None
timer_time = timer.get("targetTime")

# Smartmode
smart: dict = dev["smartMode"] if dev["smartMode"] else {}
smart: dict[str, Any] = dev["smartMode"] if dev["smartMode"] else {}
smart_on = None
if dev["productModel"] != "pure":
smart_on = smart.get("enabled", False)
Expand Down Expand Up @@ -464,7 +472,7 @@ async def _get(
except Exception as error:
if retry is False:
await asyncio.sleep(5)
return self._get(path, params, True)
return await self._get(path, params, True)
raise error

async def _put(
Expand All @@ -483,7 +491,7 @@ async def _put(
except Exception as error:
if retry is False:
await asyncio.sleep(5)
return self._put(path, params, data, True)
return await self._put(path, params, data, True)
raise error

async def _post(
Expand All @@ -502,7 +510,7 @@ async def _post(
except Exception as error:
if retry is False:
await asyncio.sleep(5)
return self._post(path, params, data, True)
return await self._post(path, params, data, True)
raise error

async def _patch(
Expand All @@ -521,7 +529,7 @@ async def _patch(
except Exception as error:
if retry is False:
await asyncio.sleep(5)
return self._patch(path, params, data, True)
return await self._patch(path, params, data, True)
raise error

async def _delete(
Expand All @@ -536,7 +544,7 @@ async def _delete(
except Exception as error:
if retry is False:
await asyncio.sleep(5)
return self._delete(path, params, True)
return await self._delete(path, params, True)
raise error

async def _response(self, resp: ClientResponse) -> dict[str, Any]:
Expand Down
18 changes: 9 additions & 9 deletions pysensibo/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class SensiboDevice:
horizontal_swing_mode: str | None
light_mode: str | None
available: bool
hvac_modes: list[str | None]
fan_modes: list[str | None] | None
swing_modes: list[str | None] | None
horizontal_swing_modes: list[str | None] | None
light_modes: list[str | None] | None
hvac_modes: list[str] | None
fan_modes: list[str] | None
swing_modes: list[str] | None
horizontal_swing_modes: list[str] | None
light_modes: list[str] | None
temp_unit: str | None
temp_list: list[int]
temp_step: int
Expand Down Expand Up @@ -67,8 +67,8 @@ class SensiboDevice:
smart_type: str | None
smart_low_temp_threshold: float | None
smart_high_temp_threshold: float | None
smart_low_state: dict | None
smart_high_state: dict | None
smart_low_state: dict[str, Any] | None
smart_high_state: dict[str, Any] | None
filter_clean: bool
filter_last_reset: str | None

Expand Down Expand Up @@ -97,7 +97,7 @@ class Schedules:
id: str
enabled: bool
state_on: bool | None
state_full: dict
days: list
state_full: dict[str, Any]
days: list[str]
time: str
next_utc: str
Empty file added pysensibo/py.typed
Empty file.
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
print(find_packages())
setup(
name="pysensibo",
version="1.0.14",
version="1.0.15",
description="asyncio-friendly python API for Sensibo",
long_description="asyncio-friendly python API for Sensibo"
"(https://sensibo.com). Requires Python 3.4+",
Expand All @@ -24,8 +24,9 @@
],
keywords="Sensibo",
install_requires=["aiohttp"],
zip_safe=True,
zip_safe=False,
author="andrey-git",
author_email="[email protected]",
packages=find_packages(),
package_data={"pysensibo": ["py.typed"]},
)

0 comments on commit a43417b

Please sign in to comment.