Skip to content

Commit 5434dfb

Browse files
authored
Convert IKEA Starkvind fan speed attribute (#3088)
1 parent 6f5a939 commit 5434dfb

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

tests/test_ikea.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from tests.common import ClusterListener
1111
import zhaquirks
1212
import zhaquirks.ikea.starkvind
13+
from zhaquirks.ikea.starkvind import IkeaAirpurifier
1314

1415
zhaquirks.setup()
1516

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

8788

89+
@pytest.mark.parametrize("attribute", ["fan_speed", "fan_mode"])
90+
@pytest.mark.parametrize("value,expected", [
91+
(0, 0), # off
92+
(1, 1), # auto
93+
(10, 2),
94+
(20, 4),
95+
(50, 10),
96+
]
97+
)
98+
async def test_fan_speed_mode_update(zigpy_device_from_quirk, attribute, value, expected):
99+
"""Test reading the fan speed and mode."""
100+
101+
starkvind_device = zigpy_device_from_quirk(zhaquirks.ikea.starkvind.IkeaSTARKVIND)
102+
assert starkvind_device.model == "STARKVIND Air purifier"
103+
104+
ikea_cluster = starkvind_device.endpoints[1].in_clusters[
105+
zhaquirks.ikea.starkvind.IkeaAirpurifier.cluster_id
106+
]
107+
ikea_listener = ClusterListener(ikea_cluster)
108+
109+
attr_id = getattr(IkeaAirpurifier.AttributeDefs, attribute).id
110+
111+
ikea_cluster.update_attribute(attr_id, value)
112+
assert len(ikea_listener.attribute_updates) == 1
113+
assert ikea_listener.attribute_updates[0] == (attr_id, expected)
114+
115+
88116
async def test_pm25_cluster_read(zigpy_device_from_quirk):
89117
"""Test reading from PM25 cluster."""
90118

zhaquirks/ikea/starkvind.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def _update_attribute(self, attrid, value):
6868
value is not None and value < 5500
6969
): # > 5500 = out of scale; if value is 65535 (0xFFFF), device is off
7070
self.endpoint.device.pm25_bus.listener_event("update_state", value)
71-
elif attrid == 0x0006:
72-
if value > 9 and value < 51:
73-
value = value / 5
71+
elif attrid in (0x0006, 0x0007):
72+
if value >= 10 and value <= 50:
73+
value = value // 5
7474
super()._update_attribute(attrid, value)
7575

7676
async def write_attributes(

0 commit comments

Comments
 (0)