Improve fans in homekit_controller (#74440)
This commit is contained in:
parent
809f101f55
commit
f6cb2833ca
9 changed files with 205 additions and 198 deletions
|
@ -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,
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue