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: Add more i35 sensors and switches. #142

Merged
merged 11 commits into from
Nov 28, 2024
23 changes: 20 additions & 3 deletions custom_components/ha_blueair/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from .const import DOMAIN, DATA_DEVICES, DATA_AWS_DEVICES
from .blueair_data_update_coordinator import BlueairDataUpdateCoordinator
from .blueair_aws_data_update_coordinator import BlueairAwsDataUpdateCoordinator
from .entity import BlueairEntity


Expand All @@ -25,7 +26,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
)
async_add_entities(entities)

aws_devices: list[BlueairDataUpdateCoordinator] = hass.data[DOMAIN][
aws_devices: list[BlueairAwsDataUpdateCoordinator] = hass.data[DOMAIN][
DATA_AWS_DEVICES
]
entities = []
Expand All @@ -34,6 +35,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
[
BlueairFilterExpiredSensor(device),
BlueairOnlineSensor(device),
BlueairWaterShortageSensor(device),
]
)
async_add_entities(entities)
Expand All @@ -55,11 +57,11 @@ class BlueairFilterExpiredSensor(BlueairEntity, BinarySensorEntity):
_attr_icon = "mdi:air-filter"

def __init__(self, device):
"""Initialize the temperature sensor."""
self.entity_description = EntityDescription(
key=f"#{device.blueair_api_device.uuid}-filter-expired",
device_class=BinarySensorDeviceClass.PROBLEM,
)
"""Initialize the temperature sensor."""
super().__init__("Filter Expiration", device)

@property
Expand All @@ -72,11 +74,11 @@ class BlueairOnlineSensor(BlueairEntity, BinarySensorEntity):
_attr_icon = "mdi:wifi-check"

def __init__(self, device):
"""Initialize the temperature sensor."""
self.entity_description = EntityDescription(
key=f"#{device.blueair_api_device.uuid}-online",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
)
"""Initialize the temperature sensor."""
super().__init__("Online", device)

@property
Expand All @@ -90,3 +92,18 @@ def icon(self) -> str | None:
return self._attr_icon
else:
return "mdi:wifi-strength-outline"

class BlueairWaterShortageSensor(BlueairEntity, BinarySensorEntity):
_attr_icon = "mdi:water-alert-outline"

def __init__(self, device):
self.entity_description = EntityDescription(
key=f"#{device.blueair_api_device.uuid}-water-shortage",
device_class=BinarySensorDeviceClass.PROBLEM,
)
super().__init__("Water Shortage", device)

@property
def is_on(self) -> bool | None:
"""Return true if the binary sensor is on."""
return self._device.water_shortage
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Blueair device object."""
import logging
from datetime import timedelta

import enum

from blueair_api import DeviceAws as BlueAirApiDeviceAws
from asyncio import sleep
Expand All @@ -13,6 +13,11 @@
_LOGGER = logging.getLogger(__name__)


class ModelEnum(enum.StrEnum):
UNKNOWN = "Unknown"
HUMIDIFIER_I35 = "Blueair Humidifier i35"
PROTECT_7470I = "Blueair Protect 7470i"

class BlueairAwsDataUpdateCoordinator(DataUpdateCoordinator):
"""Blueair device object."""

Expand All @@ -23,7 +28,6 @@ def __init__(
self.hass: HomeAssistant = hass
self.blueair_api_device: BlueAirApiDeviceAws = blueair_api_device
self._manufacturer: str = "BlueAir"

super().__init__(
hass,
_LOGGER,
Expand Down Expand Up @@ -56,14 +60,27 @@ def manufacturer(self) -> str:
return self._manufacturer

@property
def model(self) -> str:
return "protect?"
def model(self) -> ModelEnum:
if (self.blueair_api_device.type_name == "Humidifier" and
self.blueair_api_device.sku == "111633"):
return ModelEnum.HUMIDIFIER_I35
if self.blueair_api_device.sku == "105826":
return ModelEnum.PROTECT_7470I
return ModelEnum.UNKNOWN

@property
def fan_speed(self) -> int:
"""Return the current fan speed."""
return self.blueair_api_device.fan_speed

@property
def speed_count(self) -> int:
"""Return the max fan speed."""
if self.model == ModelEnum.HUMIDIFIER_I35:
dahlb marked this conversation as resolved.
Show resolved Hide resolved
return 64
else:
return 100

@property
def is_on(self) -> False:
"""Return the current fan state."""
Expand Down Expand Up @@ -118,11 +135,21 @@ def online(self) -> bool:
def fan_auto_mode(self) -> bool:
return self.blueair_api_device.fan_auto_mode

@property
def wick_dry_mode(self) -> bool:
return self.blueair_api_device.wick_dry_mode

@property
def water_shortage(self) -> bool:
return self.blueair_api_device.water_shortage

@property
def filter_expired(self) -> bool:
"""Return the current filter status."""
return (self.blueair_api_device.filter_usage is not None
and self.blueair_api_device.filter_usage >= 95)
if self.blueair_api_device.filter_usage is not None:
return self.blueair_api_device.filter_usage >= 95
if self.blueair_api_device.wick_usage is not None:
return self.blueair_api_device.wick_usage >= 95

async def set_fan_speed(self, new_speed) -> None:
self.blueair_api_device.fan_speed = new_speed
Expand Down Expand Up @@ -159,3 +186,9 @@ async def set_fan_auto_mode(self, value) -> None:
await self.blueair_api_device.set_fan_auto_mode(value)
await sleep(5)
await self.async_refresh()

async def set_wick_dry_mode(self, value) -> None:
self.blueair_api_device.wick_dry_mode = value
await self.blueair_api_device.set_wick_dry_mode(value)
await sleep(5)
await self.async_refresh()
11 changes: 6 additions & 5 deletions custom_components/ha_blueair/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ def is_on(self) -> int:
@property
def percentage(self) -> int:
"""Return the current speed percentage."""
return self._device.fan_speed
return int(self._device.fan_speed / self._device.speed_count * 100)

async def async_set_percentage(self, percentage: int) -> None:
await self._device.set_fan_speed(percentage)
await self._device.set_fan_speed(int(percentage / 100 * self._device.speed_count))
self.async_write_ha_state()

async def async_turn_off(self, **kwargs: any) -> None:
Expand All @@ -125,10 +125,11 @@ async def async_turn_on(
) -> None:
await self._device.set_running(True)
self.async_write_ha_state()
if percentage is not None:
await self.async_set_percentage(percentage=percentage)
if percentage is None:
percentage = 50
await self.async_set_percentage(percentage=percentage)

@property
def speed_count(self) -> int:
"""Return the number of speeds the fan supports."""
return 100
return self._device.speed_count
1 change: 0 additions & 1 deletion custom_components/ha_blueair/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
"documentation": "https://github.com/dahlb/ha_blueair",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/dahlb/ha_blueair/issues",
"requirements": ["blueair-api==1.9.5"],
"version": "1.9.6"
}
16 changes: 11 additions & 5 deletions custom_components/ha_blueair/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


from .const import DOMAIN, DATA_AWS_DEVICES
from .blueair_data_update_coordinator import BlueairDataUpdateCoordinator
from .blueair_aws_data_update_coordinator import BlueairAwsDataUpdateCoordinator, ModelEnum
from .entity import BlueairEntity


Expand All @@ -20,17 +20,23 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
DATA_AWS_DEVICES
]
entities = []

for device in aws_devices:
entities.extend(
[
if device.model in (ModelEnum.UNKNOWN, ModelEnum.PROTECT_7470I):
entities.extend([
BlueairTemperatureSensor(device),
BlueairHumiditySensor(device),
BlueairVOCSensor(device),
BlueairPM1Sensor(device),
BlueairPM10Sensor(device),
BlueairPM25Sensor(device),
]
)
])
elif device.model == ModelEnum.HUMIDIFIER_I35:
entities.extend([
BlueairTemperatureSensor(device),
BlueairHumiditySensor(device),
])

async_add_entities(entities)


Expand Down
24 changes: 24 additions & 0 deletions custom_components/ha_blueair/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async def async_setup_entry(hass, _config_entry, async_add_entities):
BlueairChildLockSwitchEntity(device),
BlueairAutoFanModeSwitchEntity(device),
BlueairNightModeSwitchEntity(device),
BlueairWickDryModeSwitchEntity(device),
]
)
async_add_entities(entities)
Expand Down Expand Up @@ -87,3 +88,26 @@ async def async_turn_on(self, **kwargs):
async def async_turn_off(self, **kwargs):
await self._device.set_night_mode(False)
self.async_write_ha_state()

class BlueairWickDryModeSwitchEntity(BlueairEntity, SwitchEntity):
_attr_device_class = SwitchDeviceClass.SWITCH

def __init__(self, device):
super().__init__("Wick Dry Mode", device)

@property
def is_on(self) -> int | None:
return self._device.wick_dry_mode

@property
def available(self) -> bool:
"""Return True if entity is available."""
return self._device.wick_dry_mode is not None

async def async_turn_on(self, **kwargs):
await self._device.set_wick_dry_mode(True)
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
await self._device.set_wick_dry_mode(False)
self.async_write_ha_state()
Loading