Fix homekit_controller tests to avoid global aid generation (#119852)
This commit is contained in:
parent
454ca0ce95
commit
e2276458ed
25 changed files with 792 additions and 344 deletions
|
@ -1,5 +1,7 @@
|
|||
"""Basic checks for HomeKitalarm_control_panel."""
|
||||
|
||||
from collections.abc import Callable
|
||||
|
||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
|
||||
|
@ -7,7 +9,7 @@ from homeassistant.const import STATE_UNAVAILABLE
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .common import get_next_aid, setup_test_component
|
||||
from .common import setup_test_component
|
||||
|
||||
|
||||
def create_window_covering_service(accessory):
|
||||
|
@ -113,9 +115,13 @@ def create_window_covering_service_with_none_tilt(accessory):
|
|||
tilt_target.maxValue = 0
|
||||
|
||||
|
||||
async def test_change_window_cover_state(hass: HomeAssistant) -> None:
|
||||
async def test_change_window_cover_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can turn a HomeKit alarm on and off again."""
|
||||
helper = await setup_test_component(hass, create_window_covering_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_window_covering_service
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "open_cover", {"entity_id": helper.entity_id}, blocking=True
|
||||
|
@ -138,9 +144,13 @@ async def test_change_window_cover_state(hass: HomeAssistant) -> None:
|
|||
)
|
||||
|
||||
|
||||
async def test_read_window_cover_state(hass: HomeAssistant) -> None:
|
||||
async def test_read_window_cover_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can read the state of a HomeKit alarm accessory."""
|
||||
helper = await setup_test_component(hass, create_window_covering_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_window_covering_service
|
||||
)
|
||||
|
||||
await helper.async_update(
|
||||
ServicesTypes.WINDOW_COVERING,
|
||||
|
@ -171,10 +181,12 @@ async def test_read_window_cover_state(hass: HomeAssistant) -> None:
|
|||
assert state.attributes["obstruction-detected"] is True
|
||||
|
||||
|
||||
async def test_read_window_cover_tilt_horizontal(hass: HomeAssistant) -> None:
|
||||
async def test_read_window_cover_tilt_horizontal(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that horizontal tilt is handled correctly."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_h_tilt
|
||||
hass, get_next_aid(), create_window_covering_service_with_h_tilt
|
||||
)
|
||||
|
||||
await helper.async_update(
|
||||
|
@ -186,10 +198,12 @@ async def test_read_window_cover_tilt_horizontal(hass: HomeAssistant) -> None:
|
|||
assert state.attributes["current_tilt_position"] == 83
|
||||
|
||||
|
||||
async def test_read_window_cover_tilt_horizontal_2(hass: HomeAssistant) -> None:
|
||||
async def test_read_window_cover_tilt_horizontal_2(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that horizontal tilt is handled correctly."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_h_tilt_2
|
||||
hass, get_next_aid(), create_window_covering_service_with_h_tilt_2
|
||||
)
|
||||
|
||||
await helper.async_update(
|
||||
|
@ -201,10 +215,12 @@ async def test_read_window_cover_tilt_horizontal_2(hass: HomeAssistant) -> None:
|
|||
assert state.attributes["current_tilt_position"] == 83
|
||||
|
||||
|
||||
async def test_read_window_cover_tilt_vertical(hass: HomeAssistant) -> None:
|
||||
async def test_read_window_cover_tilt_vertical(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that vertical tilt is handled correctly."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_v_tilt
|
||||
hass, get_next_aid(), create_window_covering_service_with_v_tilt
|
||||
)
|
||||
|
||||
await helper.async_update(
|
||||
|
@ -216,10 +232,12 @@ async def test_read_window_cover_tilt_vertical(hass: HomeAssistant) -> None:
|
|||
assert state.attributes["current_tilt_position"] == 83
|
||||
|
||||
|
||||
async def test_read_window_cover_tilt_vertical_2(hass: HomeAssistant) -> None:
|
||||
async def test_read_window_cover_tilt_vertical_2(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that vertical tilt is handled correctly."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_v_tilt_2
|
||||
hass, get_next_aid(), create_window_covering_service_with_v_tilt_2
|
||||
)
|
||||
|
||||
await helper.async_update(
|
||||
|
@ -231,10 +249,12 @@ async def test_read_window_cover_tilt_vertical_2(hass: HomeAssistant) -> None:
|
|||
assert state.attributes["current_tilt_position"] == 83
|
||||
|
||||
|
||||
async def test_read_window_cover_tilt_missing_tilt(hass: HomeAssistant) -> None:
|
||||
async def test_read_window_cover_tilt_missing_tilt(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that missing tilt is handled."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_none_tilt
|
||||
hass, get_next_aid(), create_window_covering_service_with_none_tilt
|
||||
)
|
||||
|
||||
await helper.async_update(
|
||||
|
@ -246,10 +266,12 @@ async def test_read_window_cover_tilt_missing_tilt(hass: HomeAssistant) -> None:
|
|||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_write_window_cover_tilt_horizontal(hass: HomeAssistant) -> None:
|
||||
async def test_write_window_cover_tilt_horizontal(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that horizontal tilt is written correctly."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_h_tilt
|
||||
hass, get_next_aid(), create_window_covering_service_with_h_tilt
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
|
@ -267,10 +289,12 @@ async def test_write_window_cover_tilt_horizontal(hass: HomeAssistant) -> None:
|
|||
)
|
||||
|
||||
|
||||
async def test_write_window_cover_tilt_horizontal_2(hass: HomeAssistant) -> None:
|
||||
async def test_write_window_cover_tilt_horizontal_2(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that horizontal tilt is written correctly."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_h_tilt_2
|
||||
hass, get_next_aid(), create_window_covering_service_with_h_tilt_2
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
|
@ -288,10 +312,12 @@ async def test_write_window_cover_tilt_horizontal_2(hass: HomeAssistant) -> None
|
|||
)
|
||||
|
||||
|
||||
async def test_write_window_cover_tilt_vertical(hass: HomeAssistant) -> None:
|
||||
async def test_write_window_cover_tilt_vertical(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that vertical tilt is written correctly."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_v_tilt
|
||||
hass, get_next_aid(), create_window_covering_service_with_v_tilt
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
|
@ -309,10 +335,12 @@ async def test_write_window_cover_tilt_vertical(hass: HomeAssistant) -> None:
|
|||
)
|
||||
|
||||
|
||||
async def test_write_window_cover_tilt_vertical_2(hass: HomeAssistant) -> None:
|
||||
async def test_write_window_cover_tilt_vertical_2(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that vertical tilt is written correctly."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_v_tilt_2
|
||||
hass, get_next_aid(), create_window_covering_service_with_v_tilt_2
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
|
@ -330,10 +358,12 @@ async def test_write_window_cover_tilt_vertical_2(hass: HomeAssistant) -> None:
|
|||
)
|
||||
|
||||
|
||||
async def test_window_cover_stop(hass: HomeAssistant) -> None:
|
||||
async def test_window_cover_stop(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that vertical tilt is written correctly."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_v_tilt
|
||||
hass, get_next_aid(), create_window_covering_service_with_v_tilt
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
|
@ -366,9 +396,13 @@ def create_garage_door_opener_service(accessory):
|
|||
return service
|
||||
|
||||
|
||||
async def test_change_door_state(hass: HomeAssistant) -> None:
|
||||
async def test_change_door_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can turn open and close a HomeKit garage door."""
|
||||
helper = await setup_test_component(hass, create_garage_door_opener_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_garage_door_opener_service
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "open_cover", {"entity_id": helper.entity_id}, blocking=True
|
||||
|
@ -391,9 +425,13 @@ async def test_change_door_state(hass: HomeAssistant) -> None:
|
|||
)
|
||||
|
||||
|
||||
async def test_read_door_state(hass: HomeAssistant) -> None:
|
||||
async def test_read_door_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can read the state of a HomeKit garage door."""
|
||||
helper = await setup_test_component(hass, create_garage_door_opener_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_garage_door_opener_service
|
||||
)
|
||||
|
||||
await helper.async_update(
|
||||
ServicesTypes.GARAGE_DOOR_OPENER,
|
||||
|
@ -432,7 +470,9 @@ async def test_read_door_state(hass: HomeAssistant) -> None:
|
|||
|
||||
|
||||
async def test_migrate_unique_id(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
get_next_aid: Callable[[], int],
|
||||
) -> None:
|
||||
"""Test a we can migrate a cover unique id."""
|
||||
aid = get_next_aid()
|
||||
|
@ -441,7 +481,7 @@ async def test_migrate_unique_id(
|
|||
"homekit_controller",
|
||||
f"homekit-00:00:00:00:00:00-{aid}-8",
|
||||
)
|
||||
await setup_test_component(hass, create_garage_door_opener_service)
|
||||
await setup_test_component(hass, aid, create_garage_door_opener_service)
|
||||
|
||||
assert (
|
||||
entity_registry.async_get(cover_entry.entity_id).unique_id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue