Improve fans in homekit_controller (#74440)

This commit is contained in:
J. Nick Koston 2022-07-05 09:25:30 -05:00 committed by GitHub
parent 809f101f55
commit f6cb2833ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 205 additions and 198 deletions

View file

@ -1,4 +1,4 @@
"""Basic checks for HomeKit motion sensors and contact sensors."""
"""Basic checks for HomeKit fans."""
from aiohomekit.model.characteristics import CharacteristicsTypes
from aiohomekit.model.services import ServicesTypes
@ -41,6 +41,20 @@ def create_fanv2_service(accessory):
swing_mode.value = 0
def create_fanv2_service_non_standard_rotation_range(accessory):
"""Define fan v2 with a non-standard rotation range."""
service = accessory.add_service(ServicesTypes.FAN_V2)
cur_state = service.add_char(CharacteristicsTypes.ACTIVE)
cur_state.value = 0
speed = service.add_char(CharacteristicsTypes.ROTATION_SPEED)
speed.value = 0
speed.minValue = 0
speed.maxValue = 3
speed.minStep = 1
def create_fanv2_service_with_min_step(accessory):
"""Define fan v2 characteristics as per HAP spec."""
service = accessory.add_service(ServicesTypes.FAN_V2)
@ -730,3 +744,64 @@ async def test_v2_oscillate_read(hass, utcnow):
ServicesTypes.FAN_V2, {CharacteristicsTypes.SWING_MODE: 1}
)
assert state.attributes["oscillating"] is True
async def test_v2_set_percentage_non_standard_rotation_range(hass, utcnow):
"""Test that we set fan speed with a non-standard rotation range."""
helper = await setup_test_component(
hass, create_fanv2_service_non_standard_rotation_range
)
await helper.async_update(ServicesTypes.FAN_V2, {CharacteristicsTypes.ACTIVE: 1})
await hass.services.async_call(
"fan",
"set_percentage",
{"entity_id": "fan.testdevice", "percentage": 100},
blocking=True,
)
helper.async_assert_service_values(
ServicesTypes.FAN_V2,
{
CharacteristicsTypes.ROTATION_SPEED: 3,
},
)
await hass.services.async_call(
"fan",
"set_percentage",
{"entity_id": "fan.testdevice", "percentage": 66},
blocking=True,
)
helper.async_assert_service_values(
ServicesTypes.FAN_V2,
{
CharacteristicsTypes.ROTATION_SPEED: 2,
},
)
await hass.services.async_call(
"fan",
"set_percentage",
{"entity_id": "fan.testdevice", "percentage": 33},
blocking=True,
)
helper.async_assert_service_values(
ServicesTypes.FAN_V2,
{
CharacteristicsTypes.ROTATION_SPEED: 1,
},
)
await hass.services.async_call(
"fan",
"set_percentage",
{"entity_id": "fan.testdevice", "percentage": 0},
blocking=True,
)
helper.async_assert_service_values(
ServicesTypes.FAN_V2,
{
CharacteristicsTypes.ACTIVE: 0,
},
)