Skip to content

Commit

Permalink
feat: provide filter life percentage remaining where available (#187)
Browse files Browse the repository at this point in the history
* Update sensor.py

* Update binary_sensor.py

* Update blueair_update_coordinator_device_aws.py

* Restore filter expired sensor

* Update blueair_update_coordinator_device.py

* Update blueair_update_coordinator_device_aws.py

* Update const.py

* Update blueair_update_coordinator_device_aws.py

* Update blueair_update_coordinator_device_aws.py

* Update blueair_update_coordinator_device.py

* Update blueair_update_coordinator.py
  • Loading branch information
emlove authored Jan 15, 2025
1 parent 67446a8 commit 0b652c6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 11 deletions.
12 changes: 11 additions & 1 deletion custom_components/ha_blueair/blueair_update_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,20 @@ def water_shortage(self) -> bool | None | NotImplemented:

@property
@abstractmethod
def filter_expired(self) -> bool | None:
def filter_expired(self) -> bool | None | NotImplemented:
"""Return the current filter status."""
pass

@property
@abstractmethod
def filter_life(self) -> int | None | NotImplemented:
pass

@property
@abstractmethod
def wick_life(self) -> int | None | NotImplemented:
pass

@property
@abstractmethod
def main_mode(self) -> int | None | NotImplemented:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ def model(self) -> str:
return self.blueair_api_device.compatibility

@property
def filter_expired(self) -> bool| None:
def filter_expired(self) -> bool | None | NotImplemented:
"""Return the current filter status."""
return self.blueair_api_device.filter_expired

@property
def filter_life(self) -> int | None | NotImplemented:
return NotImplemented

@property
def wick_life(self) -> int | None | NotImplemented:
return NotImplemented

@property
def fan_speed(self) -> int:
"""Return the current fan speed."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from blueair_api import ModelEnum

from .const import FILTER_EXPIRED_THRESHOLD
from .blueair_update_coordinator import BlueairUpdateCoordinator

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -122,14 +121,21 @@ def water_shortage(self) -> bool | None | NotImplemented:
return self.blueair_api_device.water_shortage

@property
def filter_expired(self) -> bool | None:
def filter_expired(self) -> bool | None | NotImplemented:
"""Returns the current filter status."""
if self.blueair_api_device.filter_usage_percentage not in (NotImplemented, None):
return (self.blueair_api_device.filter_usage_percentage >=
FILTER_EXPIRED_THRESHOLD)
if self.blueair_api_device.wick_usage_percentage not in (NotImplemented, None):
return (self.blueair_api_device.wick_usage_percentage >=
FILTER_EXPIRED_THRESHOLD)
return NotImplemented

@property
def filter_life(self) -> int | None | NotImplemented:
if self.blueair_api_device.filter_usage_percentage in (NotImplemented, None):
return self.blueair_api_device.filter_usage_percentage
return 100 - self.blueair_api_device.filter_usage_percentage

@property
def wick_life(self) -> int | None | NotImplemented:
if self.blueair_api_device.wick_usage_percentage in (NotImplemented, None):
return self.blueair_api_device.wick_usage_percentage
return 100 - self.blueair_api_device.wick_usage_percentage

@property
def main_mode(self) -> int | None | NotImplemented:
Expand Down
1 change: 0 additions & 1 deletion custom_components/ha_blueair/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class FanMode(Enum):
REGIONS = [REGION_USA, REGION_EU]

DEFAULT_FAN_SPEED_PERCENTAGE = 50
FILTER_EXPIRED_THRESHOLD = 95

# Custom Mode Constants
MODE_FAN_SPEED = "fan_speed"
Expand Down
24 changes: 24 additions & 0 deletions custom_components/ha_blueair/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
BlueairPM1Sensor,
BlueairPM10Sensor,
BlueairPM25Sensor,
BlueairFilterLifeSensor,
BlueairWickLifeSensor,
])


Expand Down Expand Up @@ -128,3 +130,25 @@ class BlueairCO2Sensor(BlueairSensor):
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
suggested_display_precision=0,
)


class BlueairFilterLifeSensor(BlueairSensor):
"""Monitors the filter remaining life"""
entity_description = SensorEntityDescription(
key="filter_life",
name="Filter Life",
native_unit_of_measurement=PERCENTAGE,
suggested_display_precision=0,
icon="mdi:air-filter",
)


class BlueairWickLifeSensor(BlueairSensor):
"""Monitors the wick remaining life"""
entity_description = SensorEntityDescription(
key="wick_life",
name="Wick Life",
native_unit_of_measurement=PERCENTAGE,
suggested_display_precision=0,
icon="mdi:air-filter",
)

0 comments on commit 0b652c6

Please sign in to comment.