Skip to content

Commit

Permalink
Convert IKEA Starkvind fan speed attribute (#3088)
Browse files Browse the repository at this point in the history
  • Loading branch information
freundTech committed May 28, 2024
1 parent 6f5a939 commit 5434dfb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
28 changes: 28 additions & 0 deletions tests/test_ikea.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from tests.common import ClusterListener
import zhaquirks
import zhaquirks.ikea.starkvind
from zhaquirks.ikea.starkvind import IkeaAirpurifier

zhaquirks.setup()

Expand Down Expand Up @@ -85,6 +86,33 @@ def test_ikea_starkvind_v2(assert_signature_matches_quirk):
assert_signature_matches_quirk(zhaquirks.ikea.starkvind.IkeaSTARKVIND_v2, signature)


@pytest.mark.parametrize("attribute", ["fan_speed", "fan_mode"])
@pytest.mark.parametrize("value,expected", [
(0, 0), # off
(1, 1), # auto
(10, 2),
(20, 4),
(50, 10),
]
)
async def test_fan_speed_mode_update(zigpy_device_from_quirk, attribute, value, expected):
"""Test reading the fan speed and mode."""

starkvind_device = zigpy_device_from_quirk(zhaquirks.ikea.starkvind.IkeaSTARKVIND)
assert starkvind_device.model == "STARKVIND Air purifier"

ikea_cluster = starkvind_device.endpoints[1].in_clusters[
zhaquirks.ikea.starkvind.IkeaAirpurifier.cluster_id
]
ikea_listener = ClusterListener(ikea_cluster)

attr_id = getattr(IkeaAirpurifier.AttributeDefs, attribute).id

ikea_cluster.update_attribute(attr_id, value)
assert len(ikea_listener.attribute_updates) == 1
assert ikea_listener.attribute_updates[0] == (attr_id, expected)


async def test_pm25_cluster_read(zigpy_device_from_quirk):
"""Test reading from PM25 cluster."""

Expand Down
6 changes: 3 additions & 3 deletions zhaquirks/ikea/starkvind.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def _update_attribute(self, attrid, value):
value is not None and value < 5500
): # > 5500 = out of scale; if value is 65535 (0xFFFF), device is off
self.endpoint.device.pm25_bus.listener_event("update_state", value)
elif attrid == 0x0006:
if value > 9 and value < 51:
value = value / 5
elif attrid in (0x0006, 0x0007):
if value >= 10 and value <= 50:
value = value // 5
super()._update_attribute(attrid, value)

async def write_attributes(
Expand Down

0 comments on commit 5434dfb

Please sign in to comment.