Skip to content

Commit

Permalink
fix: prevent humidity sensors being created for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlb committed Nov 28, 2024
1 parent 9541505 commit 4e8db70
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 38 deletions.
22 changes: 15 additions & 7 deletions custom_components/ha_blueair/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
BinarySensorEntity,
)
from homeassistant.helpers.entity import EntityDescription
from blueair_api import ModelEnum

from .const import DOMAIN, DATA_DEVICES, DATA_AWS_DEVICES
from .blueair_data_update_coordinator import BlueairDataUpdateCoordinator
Expand All @@ -31,13 +32,20 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
]
entities = []
for device in aws_devices:
entities.extend(
[
BlueairFilterExpiredSensor(device),
BlueairOnlineSensor(device),
BlueairWaterShortageSensor(device),
]
)
if device.model == ModelEnum.HUMIDIFIER_I35:
entities.extend(
[
BlueairOnlineSensor(device),
BlueairWaterShortageSensor(device),
]
)
else:
entities.extend(
[
BlueairOnlineSensor(device),
BlueairFilterExpiredSensor(device),
]
)
async_add_entities(entities)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Blueair device object."""
import logging
from datetime import timedelta
import enum

from blueair_api import DeviceAws as BlueAirApiDeviceAws
from blueair_api import DeviceAws as BlueAirApiDeviceAws, ModelEnum
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.helpers.debounce import Debouncer
Expand All @@ -13,12 +12,6 @@
_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 Down Expand Up @@ -65,11 +58,8 @@ def manufacturer(self) -> str:

@property
def model(self) -> ModelEnum:
if self.blueair_api_device.sku == "111633":
return ModelEnum.HUMIDIFIER_I35
if self.blueair_api_device.sku == "105826":
return ModelEnum.PROTECT_7470I
return ModelEnum.UNKNOWN
"""Return api package enum of device model."""
return self.blueair_api_device.model

@property
def fan_speed(self) -> int:
Expand Down
3 changes: 0 additions & 3 deletions custom_components/ha_blueair/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Configuration Constants
DOMAIN: str = "ha_blueair"

Expand All @@ -16,5 +15,3 @@

DEFAULT_FAN_SPEED_PERCENTAGE = 50
FILTER_EXPIRED_THRESHOLD = 95


2 changes: 1 addition & 1 deletion custom_components/ha_blueair/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"documentation": "https://github.com/dahlb/ha_blueair",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/dahlb/ha_blueair/issues",
"requirements": ["blueair-api==1.11.0"],
"requirements": ["blueair-api==1.12.0"],
"version": "1.10.0"
}
5 changes: 2 additions & 3 deletions custom_components/ha_blueair/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
PERCENTAGE,
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
)

from blueair_api import ModelEnum

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


Expand Down Expand Up @@ -182,4 +182,3 @@ def native_value(self) -> float:
def available(self) -> bool:
"""Return True if entity is available."""
return self.native_value is not None

27 changes: 19 additions & 8 deletions custom_components/ha_blueair/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
SwitchEntity,
SwitchDeviceClass,
)
from blueair_api import ModelEnum

from .const import DOMAIN, DATA_AWS_DEVICES
from .blueair_aws_data_update_coordinator import BlueairAwsDataUpdateCoordinator
Expand All @@ -17,14 +18,23 @@ async def async_setup_entry(hass, _config_entry, async_add_entities):
]
entities = []
for device in aws_devices:
entities.extend(
[
BlueairChildLockSwitchEntity(device),
BlueairAutoFanModeSwitchEntity(device),
BlueairNightModeSwitchEntity(device),
BlueairWickDryModeSwitchEntity(device),
]
)
if device.model == ModelEnum.HUMIDIFIER_I35:
entities.extend(
[
BlueairChildLockSwitchEntity(device),
BlueairAutoFanModeSwitchEntity(device),
BlueairNightModeSwitchEntity(device),
BlueairWickDryModeSwitchEntity(device),
]
)
else:
entities.extend(
[
BlueairChildLockSwitchEntity(device),
BlueairAutoFanModeSwitchEntity(device),
BlueairNightModeSwitchEntity(device),
]
)
async_add_entities(entities)


Expand Down Expand Up @@ -89,6 +99,7 @@ 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

Expand Down
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
colorlog==6.9.0
homeassistant==2024.8.0
pip>=8.0.3,<24.4
ruff==0.8.0
blueair-api==1.10.0
blueair-api==1.12.0

0 comments on commit 4e8db70

Please sign in to comment.