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,7 +1,10 @@
|
|||
"""Basic checks for HomeKitSwitch."""
|
||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
|
||||
from homeassistant.components.homekit_controller.const import KNOWN_DEVICES
|
||||
|
||||
from tests.components.homekit_controller.common import FakeService, setup_test_component
|
||||
from tests.components.homekit_controller.common import setup_test_component
|
||||
|
||||
LIGHT_ON = ("lightbulb", "on")
|
||||
LIGHT_BRIGHTNESS = ("lightbulb", "brightness")
|
||||
|
@ -10,37 +13,37 @@ LIGHT_SATURATION = ("lightbulb", "saturation")
|
|||
LIGHT_COLOR_TEMP = ("lightbulb", "color-temperature")
|
||||
|
||||
|
||||
def create_lightbulb_service():
|
||||
def create_lightbulb_service(accessory):
|
||||
"""Define lightbulb characteristics."""
|
||||
service = FakeService("public.hap.service.lightbulb")
|
||||
service = accessory.add_service(ServicesTypes.LIGHTBULB)
|
||||
|
||||
on_char = service.add_characteristic("on")
|
||||
on_char = service.add_char(CharacteristicsTypes.ON)
|
||||
on_char.value = 0
|
||||
|
||||
brightness = service.add_characteristic("brightness")
|
||||
brightness = service.add_char(CharacteristicsTypes.BRIGHTNESS)
|
||||
brightness.value = 0
|
||||
|
||||
return service
|
||||
|
||||
|
||||
def create_lightbulb_service_with_hs():
|
||||
def create_lightbulb_service_with_hs(accessory):
|
||||
"""Define a lightbulb service with hue + saturation."""
|
||||
service = create_lightbulb_service()
|
||||
service = create_lightbulb_service(accessory)
|
||||
|
||||
hue = service.add_characteristic("hue")
|
||||
hue = service.add_char(CharacteristicsTypes.HUE)
|
||||
hue.value = 0
|
||||
|
||||
saturation = service.add_characteristic("saturation")
|
||||
saturation = service.add_char(CharacteristicsTypes.SATURATION)
|
||||
saturation.value = 0
|
||||
|
||||
return service
|
||||
|
||||
|
||||
def create_lightbulb_service_with_color_temp():
|
||||
def create_lightbulb_service_with_color_temp(accessory):
|
||||
"""Define a lightbulb service with color temp."""
|
||||
service = create_lightbulb_service()
|
||||
service = create_lightbulb_service(accessory)
|
||||
|
||||
color_temp = service.add_characteristic("color-temperature")
|
||||
color_temp = service.add_char(CharacteristicsTypes.COLOR_TEMPERATURE)
|
||||
color_temp.value = 0
|
||||
|
||||
return service
|
||||
|
@ -48,8 +51,7 @@ def create_lightbulb_service_with_color_temp():
|
|||
|
||||
async def test_switch_change_light_state(hass, utcnow):
|
||||
"""Test that we can turn a HomeKit light on and off again."""
|
||||
bulb = create_lightbulb_service_with_hs()
|
||||
helper = await setup_test_component(hass, [bulb])
|
||||
helper = await setup_test_component(hass, create_lightbulb_service_with_hs)
|
||||
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
|
@ -71,8 +73,7 @@ async def test_switch_change_light_state(hass, utcnow):
|
|||
|
||||
async def test_switch_change_light_state_color_temp(hass, utcnow):
|
||||
"""Test that we can turn change color_temp."""
|
||||
bulb = create_lightbulb_service_with_color_temp()
|
||||
helper = await setup_test_component(hass, [bulb])
|
||||
helper = await setup_test_component(hass, create_lightbulb_service_with_color_temp)
|
||||
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
|
@ -87,8 +88,7 @@ async def test_switch_change_light_state_color_temp(hass, utcnow):
|
|||
|
||||
async def test_switch_read_light_state(hass, utcnow):
|
||||
"""Test that we can read the state of a HomeKit light accessory."""
|
||||
bulb = create_lightbulb_service_with_hs()
|
||||
helper = await setup_test_component(hass, [bulb])
|
||||
helper = await setup_test_component(hass, create_lightbulb_service_with_hs)
|
||||
|
||||
# Initial state is that the light is off
|
||||
state = await helper.poll_and_get_state()
|
||||
|
@ -112,8 +112,7 @@ async def test_switch_read_light_state(hass, utcnow):
|
|||
|
||||
async def test_switch_read_light_state_color_temp(hass, utcnow):
|
||||
"""Test that we can read the color_temp of a light accessory."""
|
||||
bulb = create_lightbulb_service_with_color_temp()
|
||||
helper = await setup_test_component(hass, [bulb])
|
||||
helper = await setup_test_component(hass, create_lightbulb_service_with_color_temp)
|
||||
|
||||
# Initial state is that the light is off
|
||||
state = await helper.poll_and_get_state()
|
||||
|
@ -132,8 +131,7 @@ async def test_switch_read_light_state_color_temp(hass, utcnow):
|
|||
|
||||
async def test_light_becomes_unavailable_but_recovers(hass, utcnow):
|
||||
"""Test transition to and from unavailable state."""
|
||||
bulb = create_lightbulb_service_with_color_temp()
|
||||
helper = await setup_test_component(hass, [bulb])
|
||||
helper = await setup_test_component(hass, create_lightbulb_service_with_color_temp)
|
||||
|
||||
# Initial state is that the light is off
|
||||
state = await helper.poll_and_get_state()
|
||||
|
@ -158,8 +156,7 @@ async def test_light_becomes_unavailable_but_recovers(hass, utcnow):
|
|||
|
||||
async def test_light_unloaded(hass, utcnow):
|
||||
"""Test entity and HKDevice are correctly unloaded."""
|
||||
bulb = create_lightbulb_service_with_color_temp()
|
||||
helper = await setup_test_component(hass, [bulb])
|
||||
helper = await setup_test_component(hass, create_lightbulb_service_with_color_temp)
|
||||
|
||||
# Initial state is that the light is off
|
||||
state = await helper.poll_and_get_state()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue