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

Convert IKEA Starkvind fan speed attribute #3088

Merged
merged 2 commits into from
May 28, 2024
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
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
Loading