Skip to content

Commit

Permalink
refactor: use slots to fortify device classes. (#22)
Browse files Browse the repository at this point in the history
* Correct model number.

I took a final glance at the packaging before putting them away. It says H35i,
not i35 on it.

* cleanup: Use slots to strongly type the device classes.
rainwoodman authored Dec 2, 2024
1 parent 0cd972c commit c67c501
Showing 3 changed files with 25 additions and 75 deletions.
2 changes: 2 additions & 0 deletions src/blueair_api/callbacks.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@


class CallbacksMixin:
__slots__ = ['_callbacks']

def _setup_callbacks(self):
self._callbacks = set()

61 changes: 20 additions & 41 deletions src/blueair_api/device.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dataclasses
import logging

from .callbacks import CallbacksMixin
@@ -6,25 +7,27 @@
_LOGGER = logging.getLogger(__name__)


@dataclasses.dataclass(init=False, slots=True)
class Device(CallbacksMixin):
uuid: str = None
name: str = None
timezone: str = None
compatibility: str = None
model: str = None
mac: str = None
firmware: str = None
mcu_firmware: str = None
wlan_driver: str = None
room_location: str = None
api: HttpBlueair
uuid: str | None = None
name: str | None = None
timezone: str | None = None
compatibility: str | None = None
model: str | None = None
mac: str | None = None
firmware: str | None = None
mcu_firmware: str | None = None
wlan_driver: str | None = None
room_location: str | None = None

brightness: int = None
child_lock: bool = None
night_mode: bool = None
fan_speed: int = None
fan_mode: str = None
filter_expired: bool = None
wifi_working: bool = None
brightness: int | None = None
child_lock: bool | None = None
night_mode: bool | None = None
fan_speed: int | None = None
fan_mode: str | None = None
filter_expired: bool | None = None
wifi_working: bool | None = None

def __init__(
self,
@@ -73,27 +76,3 @@ async def refresh(self):

async def set_fan_speed(self, new_speed):
await self.api.set_fan_speed(self.uuid, new_speed)

def __repr__(self):
return {
"uuid": self.uuid,
"name": self.name,
"timezone": self.timezone,
"compatibility": self.compatibility,
"model": self.model,
"mac": self.mac,
"firmware": self.firmware,
"mcu_firmware": self.mcu_firmware,
"wlan_driver": self.wlan_driver,
"room_location": self.room_location,
"brightness": self.brightness,
"child_lock": self.child_lock,
"night_mode": self.night_mode,
"fan_speed": self.fan_speed,
"filter_expired": self.filter_expired,
"fan_mode": self.fan_mode,
"wifi_working": self.wifi_working,
}

def __str__(self):
return f"{self.__repr__()}"
37 changes: 3 additions & 34 deletions src/blueair_api/device_aws.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dataclasses
import logging

from .callbacks import CallbacksMixin
@@ -7,8 +8,9 @@

_LOGGER = logging.getLogger(__name__)


@dataclasses.dataclass(init=False, slots=True)
class DeviceAws(CallbacksMixin):
api: HttpAwsBlueair
uuid: str = None
name: str = None
name_api: str = None
@@ -143,36 +145,3 @@ def model(self) -> ModelEnum:
return ModelEnum.MAX_311I
return ModelEnum.UNKNOWN

def __repr__(self):
return {
"uuid": self.uuid,
"name": self.name,
"type_name": self.type_name,
"sku": self.sku,
"name_api": self.name_api,
"mac": self.mac,
"firmware": self.firmware,
"mcu_firmware": self.mcu_firmware,
"serial_number": self.serial_number,
"brightness": self.brightness,
"child_lock": self.child_lock,
"fan_speed": self.fan_speed,
"fan_auto_mode": self.fan_auto_mode,
"running": self.running,
"night_mode": self.night_mode,
"germ_shield": self.germ_shield,
"pm1": self.pm1,
"pm2_5": self.pm2_5,
"pm10": self.pm10,
"tVOC": self.tVOC,
"temperature": self.temperature,
"humidity": self.humidity,
"filter_usage": self.filter_usage,
"wick_usage": self.wick_usage,
"wick_dry_mode": self.wick_dry_mode,
"auto_regulated_humidity": self.auto_regulated_humidity,
"water_shortage": self.water_shortage,
}

def __str__(self):
return f"{self.__repr__()}"

0 comments on commit c67c501

Please sign in to comment.