Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: More i35 support #19

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ keywords = [

[project.urls]
"Homepage" = "https://github.com/dahlb/blueair_api"
"Bug Tracker" = "https://github.com/dahlb/blueair_api/issues"
"Bug Tracker" = "https://github.com/dahlb/blueair_api/issues"
9 changes: 8 additions & 1 deletion src/blueair_api/device_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class DeviceAws(CallbacksMixin):
name: str = None
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These attribute declarations typically do not mean anything in Python (some type checkers may use them, but due to backward compatibility its value is limited): I was mistyping water_shortage to wshortage and no checks were triggered.

To make typed properties we can declare

@property
def water_shortage(self) -> bool:
  """Returns True if the device reports a water shortage."""
  return safely_get_json_value(self._last_info['state'], ....)

That said I don't know whether the current style is conventional in homeassistant codebase. If you have no objections I will update the device_aws.py file to the strongly typed style (would require a update on the ha_blueair custom_component that I will file as well, since the attributes will be made read-only.

name_api: str = None
mac: str = None
type_name: str = None

sku: str = None
firmware: str = None
mcu_firmware: str = None
serial_number: str = None
Expand All @@ -36,7 +39,7 @@ class DeviceAws(CallbacksMixin):
# i35
wick_usage: int = None # percentage
wick_dry_mode: bool = None
wshortage: bool = None
water_shortage: bool = None
auto_regulated_humidity: int = None

def __init__(
Expand All @@ -55,6 +58,7 @@ def __init__(
_LOGGER.debug(f"creating blueair device aws: {self.uuid}")

async def refresh(self):
_LOGGER.debug(f"refreshing blueair device aws: {self.uuid}")
info = await self.api.device_info(self.name_api, self.uuid)
sensor_data = convert_api_array_to_dict(info["sensordata"])
self.pm1 = safely_get_json_value(sensor_data, "pm1", int)
Expand All @@ -68,6 +72,7 @@ async def refresh(self):
self.firmware = safely_get_json_value(info, "configuration.di.cfv")
self.mcu_firmware = safely_get_json_value(info, "configuration.di.mfv")
self.serial_number = safely_get_json_value(info, "configuration.di.ds")
self.sku = safely_get_json_value(info, "configuration.di.sku")

states = convert_api_array_to_dict(info["states"])
self.running = safely_get_json_value(states, "standby") is False
Expand All @@ -85,6 +90,7 @@ async def refresh(self):
self.water_shortage = safely_get_json_value(states, "wshortage", bool)

self.publish_updates()
_LOGGER.debug(f"refreshed blueair device aws: {self}")

async def set_brightness(self, value: int):
self.brightness = value
Expand Down Expand Up @@ -131,6 +137,7 @@ def __repr__(self):
"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,
Expand Down
8 changes: 5 additions & 3 deletions src/blueair_api/util_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def create_device(device):
uuid=device["uuid"],
name=device["name"],
mac=device["mac"],
type_name=device["type"],
)

devices = map(create_device, api_devices)
Expand Down Expand Up @@ -62,7 +61,10 @@ def create_device(device):
uuid=device["uuid"],
name_api=device["name"],
mac=device["mac"],
type_name=device["type"],
)

devices = map(create_device, api_devices)
return (api, list(devices))

devices = list(map(create_device, api_devices))

return (api, devices)