Refactor homekit_controller to be fully asynchronous (#32111)
* Port homekit_controller to aiohomekit * Remove succeed() test helper * Remove fail() test helper
This commit is contained in:
parent
a1a835cf54
commit
df9363610c
31 changed files with 560 additions and 583 deletions
|
@ -1,25 +1,28 @@
|
|||
"""Basic checks for HomeKitLock."""
|
||||
from tests.components.homekit_controller.common import FakeService, setup_test_component
|
||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
|
||||
from tests.components.homekit_controller.common import setup_test_component
|
||||
|
||||
LOCK_CURRENT_STATE = ("lock-mechanism", "lock-mechanism.current-state")
|
||||
LOCK_TARGET_STATE = ("lock-mechanism", "lock-mechanism.target-state")
|
||||
|
||||
|
||||
def create_lock_service():
|
||||
def create_lock_service(accessory):
|
||||
"""Define a lock characteristics as per page 219 of HAP spec."""
|
||||
service = FakeService("public.hap.service.lock-mechanism")
|
||||
service = accessory.add_service(ServicesTypes.LOCK_MECHANISM)
|
||||
|
||||
cur_state = service.add_characteristic("lock-mechanism.current-state")
|
||||
cur_state = service.add_char(CharacteristicsTypes.LOCK_MECHANISM_CURRENT_STATE)
|
||||
cur_state.value = 0
|
||||
|
||||
targ_state = service.add_characteristic("lock-mechanism.target-state")
|
||||
targ_state = service.add_char(CharacteristicsTypes.LOCK_MECHANISM_TARGET_STATE)
|
||||
targ_state.value = 0
|
||||
|
||||
# According to the spec, a battery-level characteristic is normally
|
||||
# part of a separate service. However as the code was written (which
|
||||
# predates this test) the battery level would have to be part of the lock
|
||||
# service as it is here.
|
||||
targ_state = service.add_characteristic("battery-level")
|
||||
targ_state = service.add_char(CharacteristicsTypes.BATTERY_LEVEL)
|
||||
targ_state.value = 50
|
||||
|
||||
return service
|
||||
|
@ -27,8 +30,7 @@ def create_lock_service():
|
|||
|
||||
async def test_switch_change_lock_state(hass, utcnow):
|
||||
"""Test that we can turn a HomeKit lock on and off again."""
|
||||
lock = create_lock_service()
|
||||
helper = await setup_test_component(hass, [lock])
|
||||
helper = await setup_test_component(hass, create_lock_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
"lock", "lock", {"entity_id": "lock.testdevice"}, blocking=True
|
||||
|
@ -43,8 +45,7 @@ async def test_switch_change_lock_state(hass, utcnow):
|
|||
|
||||
async def test_switch_read_lock_state(hass, utcnow):
|
||||
"""Test that we can read the state of a HomeKit lock accessory."""
|
||||
lock = create_lock_service()
|
||||
helper = await setup_test_component(hass, [lock])
|
||||
helper = await setup_test_component(hass, create_lock_service)
|
||||
|
||||
helper.characteristics[LOCK_CURRENT_STATE].value = 0
|
||||
helper.characteristics[LOCK_TARGET_STATE].value = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue