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

Add attributes for the AirPurifier #419

Merged
merged 6 commits into from
Feb 5, 2022
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
7 changes: 6 additions & 1 deletion pytradfri/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
ATTR_BLIND_TRIGGER = "5523"

ATTR_AIR_PURIFIER_MODE: Final = "5900"
ATTR_AIR_PURIFIER_MODE_AUTO: Final = 1
ATTR_AIR_PURIFIER_FILTER_RUNTIME: Final = "5902"
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
ATTR_AIR_PURIFIER_FILTER_STATUS: Final = "5903"
ATTR_AIR_PURIFIER_FILTER_LIFETIME_TOTAL: Final = "5904"
ATTR_AIR_PURIFIER_CONTROLS_LOCKED: Final = "5905"
ATTR_AIR_PURIFIER_LEDS_OFF: Final = "5906"
ATTR_AIR_PURIFIER_AIR_QUALITY: Final = "5907"
ATTR_AIR_PURIFIER_FAN_SPEED: Final = "5908"
ATTR_AIR_PURIFIER_MOTOR_RUNTIME_TOTAL: Final = "5909"
ATTR_AIR_PURIFIER_FILTER_LIFETIME_REMAINING: Final = "5910"
ATTR_AIR_PURIFIER_MODE_AUTO: Final = 1

ATTR_CERTIFICATE_PEM = "9096"
ATTR_CERTIFICATE_PROV = "9092"
Expand Down
84 changes: 57 additions & 27 deletions pytradfri/device/air_purifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
ATTR_AIR_PURIFIER_AIR_QUALITY,
ATTR_AIR_PURIFIER_CONTROLS_LOCKED,
ATTR_AIR_PURIFIER_FAN_SPEED,
ATTR_AIR_PURIFIER_FILTER_LIFETIME_REMAINING,
ATTR_AIR_PURIFIER_FILTER_LIFETIME_TOTAL,
ATTR_AIR_PURIFIER_FILTER_RUNTIME,
ATTR_AIR_PURIFIER_FILTER_STATUS,
ATTR_AIR_PURIFIER_LEDS_OFF,
ATTR_AIR_PURIFIER_MODE,
ATTR_AIR_PURIFIER_MODE_AUTO,
ATTR_AIR_PURIFIER_MOTOR_RUNTIME_TOTAL,
ROOT_AIR_PURIFIER,
)
from ..resource import TypeRawList
Expand Down Expand Up @@ -48,26 +53,20 @@ def __init__(self, device: Device, index: int) -> None:
self.index = index

@property
def raw(self) -> TypeAirPurifier:
"""Return raw data that it represents."""
return cast(
TypeAirPurifier,
cast(TypeRawList, self.device.raw)[ROOT_AIR_PURIFIER][self.index],
)

@property
def is_auto_mode(self) -> bool:
"""
Return auto mode on or off.
def air_quality(self) -> int:
"""Get the current air quality measured by the air purifier.

Auto mode sets the fan speed automatically based on the air quality.
0..35: Good
36..85: OK
86..: Not good
65535: If the fan is off or during measuring time after turning on
"""
return self.raw[ATTR_AIR_PURIFIER_MODE] == ATTR_AIR_PURIFIER_MODE_AUTO
return self.raw[ATTR_AIR_PURIFIER_AIR_QUALITY]

@property
def state(self) -> bool:
"""Return device state, ie on or off."""
return self.raw[ATTR_AIR_PURIFIER_MODE] > 0
def controls_locked(self) -> bool:
"""Return True if physical controls on the air purifier are locked."""
return self.raw[ATTR_AIR_PURIFIER_CONTROLS_LOCKED] == 1

@property
def fan_speed(self) -> int:
Expand All @@ -79,22 +78,53 @@ def fan_speed(self) -> int:
return self.raw[ATTR_AIR_PURIFIER_FAN_SPEED]

@property
def controls_locked(self) -> bool:
"""Return True if physical controls on the air purifier are locked."""
return self.raw[ATTR_AIR_PURIFIER_CONTROLS_LOCKED] == 1
def filter_lifetime_remaining(self) -> int:
"""Return remaining lifetime of filter, expressed in minutes."""
return self.raw[ATTR_AIR_PURIFIER_FILTER_LIFETIME_REMAINING]

@property
def filter_lifetime_total(self) -> int:
"""Return total lifetime of filter, expressed in minutes."""
return self.raw[ATTR_AIR_PURIFIER_FILTER_LIFETIME_TOTAL]

@property
def filter_runtime(self) -> int:
"""Return filter runtime, expressed in minutes."""
return self.raw[ATTR_AIR_PURIFIER_FILTER_RUNTIME]

@property
def filter_status(self) -> int:
"""Return filter status."""
return self.raw[ATTR_AIR_PURIFIER_FILTER_STATUS]

@property
def is_auto_mode(self) -> bool:
"""
Return auto mode on or off.

Auto mode sets the fan speed automatically based on the air quality.
"""
return self.raw[ATTR_AIR_PURIFIER_MODE] == ATTR_AIR_PURIFIER_MODE_AUTO

@property
def leds_off(self) -> bool:
"""Return True if led's on the air purifier are turned off."""
return self.raw[ATTR_AIR_PURIFIER_LEDS_OFF] == 1

@property
def air_quality(self) -> int:
"""Get the current air quality measured by the air purifier.
def motor_runtime_total(self) -> int:
"""Return runtime of fan motor, expressed in minutes."""
return self.raw[ATTR_AIR_PURIFIER_MOTOR_RUNTIME_TOTAL]

0..35: Good
36..85: OK
86..: Not good
65535: If the fan is off or during measuring time after turning on
"""
return self.raw[ATTR_AIR_PURIFIER_AIR_QUALITY]
@property
def raw(self) -> TypeAirPurifier:
"""Return raw data that it represents."""
return cast(
TypeAirPurifier,
cast(TypeRawList, self.device.raw)[ROOT_AIR_PURIFIER][self.index],
)

@property
def state(self) -> bool:
"""Return device state, ie on or off."""
return self.raw[ATTR_AIR_PURIFIER_MODE] > 0
35 changes: 35 additions & 0 deletions tests/test_air_purifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,38 @@ def test_leds_off(device):

air_purifier = device.air_purifier_control.air_purifiers[0]
assert not air_purifier.leds_off


def test_motor_runtime_total(device):
"""Test motor's total runtime."""

air_purifier = device.air_purifier_control.air_purifiers[0]
assert air_purifier.motor_runtime_total == 2


def test_filter_lifetime_total(device):
"""Test filter's total life time."""

air_purifier = device.air_purifier_control.air_purifiers[0]
assert air_purifier.filter_lifetime_total == 259200


def test_filter_status(device):
"""Test filter status."""

air_purifier = device.air_purifier_control.air_purifiers[0]
assert air_purifier.filter_status == 0


def test_filter_lifetime_remaining(device):
"""Test remaining life of filter."""

air_purifier = device.air_purifier_control.air_purifiers[0]
assert air_purifier.filter_lifetime_remaining == 259198


def test_filter_runtime(device):
"""Test filter's run time."""

air_purifier = device.air_purifier_control.air_purifiers[0]
assert air_purifier.filter_runtime == 2