mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Fix homekit_controller tests to avoid global aid generation (#119852)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
"""Basic checks for HomeKit Humidifier/Dehumidifier."""
|
||||
|
||||
from collections.abc import Callable
|
||||
|
||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
|
||||
@@ -7,7 +9,7 @@ from homeassistant.components.humidifier import DOMAIN, MODE_AUTO, MODE_NORMAL
|
||||
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_humidifier_service(accessory):
|
||||
@@ -64,9 +66,11 @@ def create_dehumidifier_service(accessory):
|
||||
return service
|
||||
|
||||
|
||||
async def test_humidifier_active_state(hass: HomeAssistant) -> None:
|
||||
async def test_humidifier_active_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can turn a HomeKit humidifier on and off again."""
|
||||
helper = await setup_test_component(hass, create_humidifier_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_humidifier_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "turn_on", {"entity_id": helper.entity_id}, blocking=True
|
||||
@@ -87,9 +91,13 @@ async def test_humidifier_active_state(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_dehumidifier_active_state(hass: HomeAssistant) -> None:
|
||||
async def test_dehumidifier_active_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can turn a HomeKit dehumidifier on and off again."""
|
||||
helper = await setup_test_component(hass, create_dehumidifier_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_dehumidifier_service
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "turn_on", {"entity_id": helper.entity_id}, blocking=True
|
||||
@@ -110,9 +118,11 @@ async def test_dehumidifier_active_state(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_humidifier_read_humidity(hass: HomeAssistant) -> None:
|
||||
async def test_humidifier_read_humidity(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can read the state of a HomeKit humidifier accessory."""
|
||||
helper = await setup_test_component(hass, create_humidifier_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_humidifier_service)
|
||||
|
||||
state = await helper.async_update(
|
||||
ServicesTypes.HUMIDIFIER_DEHUMIDIFIER,
|
||||
@@ -149,9 +159,13 @@ async def test_humidifier_read_humidity(hass: HomeAssistant) -> None:
|
||||
assert state.state == "off"
|
||||
|
||||
|
||||
async def test_dehumidifier_read_humidity(hass: HomeAssistant) -> None:
|
||||
async def test_dehumidifier_read_humidity(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can read the state of a HomeKit dehumidifier accessory."""
|
||||
helper = await setup_test_component(hass, create_dehumidifier_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_dehumidifier_service
|
||||
)
|
||||
|
||||
state = await helper.async_update(
|
||||
ServicesTypes.HUMIDIFIER_DEHUMIDIFIER,
|
||||
@@ -186,9 +200,11 @@ async def test_dehumidifier_read_humidity(hass: HomeAssistant) -> None:
|
||||
assert state.attributes["humidity"] == 40
|
||||
|
||||
|
||||
async def test_humidifier_set_humidity(hass: HomeAssistant) -> None:
|
||||
async def test_humidifier_set_humidity(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can set the state of a HomeKit humidifier accessory."""
|
||||
helper = await setup_test_component(hass, create_humidifier_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_humidifier_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -202,9 +218,13 @@ async def test_humidifier_set_humidity(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_dehumidifier_set_humidity(hass: HomeAssistant) -> None:
|
||||
async def test_dehumidifier_set_humidity(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can set the state of a HomeKit dehumidifier accessory."""
|
||||
helper = await setup_test_component(hass, create_dehumidifier_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_dehumidifier_service
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -218,9 +238,11 @@ async def test_dehumidifier_set_humidity(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_humidifier_set_mode(hass: HomeAssistant) -> None:
|
||||
async def test_humidifier_set_mode(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can set the mode of a HomeKit humidifier accessory."""
|
||||
helper = await setup_test_component(hass, create_humidifier_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_humidifier_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -251,9 +273,13 @@ async def test_humidifier_set_mode(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_dehumidifier_set_mode(hass: HomeAssistant) -> None:
|
||||
async def test_dehumidifier_set_mode(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can set the mode of a HomeKit dehumidifier accessory."""
|
||||
helper = await setup_test_component(hass, create_dehumidifier_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_dehumidifier_service
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -284,9 +310,11 @@ async def test_dehumidifier_set_mode(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_humidifier_read_only_mode(hass: HomeAssistant) -> None:
|
||||
async def test_humidifier_read_only_mode(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can read the state of a HomeKit humidifier accessory."""
|
||||
helper = await setup_test_component(hass, create_humidifier_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_humidifier_service)
|
||||
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes["mode"] == "normal"
|
||||
@@ -324,9 +352,13 @@ async def test_humidifier_read_only_mode(hass: HomeAssistant) -> None:
|
||||
assert state.attributes["mode"] == "normal"
|
||||
|
||||
|
||||
async def test_dehumidifier_read_only_mode(hass: HomeAssistant) -> None:
|
||||
async def test_dehumidifier_read_only_mode(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can read the state of a HomeKit dehumidifier accessory."""
|
||||
helper = await setup_test_component(hass, create_dehumidifier_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_dehumidifier_service
|
||||
)
|
||||
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes["mode"] == "normal"
|
||||
@@ -364,9 +396,11 @@ async def test_dehumidifier_read_only_mode(hass: HomeAssistant) -> None:
|
||||
assert state.attributes["mode"] == "normal"
|
||||
|
||||
|
||||
async def test_humidifier_target_humidity_modes(hass: HomeAssistant) -> None:
|
||||
async def test_humidifier_target_humidity_modes(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can read the state of a HomeKit humidifier accessory."""
|
||||
helper = await setup_test_component(hass, create_humidifier_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_humidifier_service)
|
||||
|
||||
state = await helper.async_update(
|
||||
ServicesTypes.HUMIDIFIER_DEHUMIDIFIER,
|
||||
@@ -409,9 +443,13 @@ async def test_humidifier_target_humidity_modes(hass: HomeAssistant) -> None:
|
||||
assert state.attributes["humidity"] == 37
|
||||
|
||||
|
||||
async def test_dehumidifier_target_humidity_modes(hass: HomeAssistant) -> None:
|
||||
async def test_dehumidifier_target_humidity_modes(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can read the state of a HomeKit dehumidifier accessory."""
|
||||
helper = await setup_test_component(hass, create_dehumidifier_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_dehumidifier_service
|
||||
)
|
||||
|
||||
state = await helper.async_update(
|
||||
ServicesTypes.HUMIDIFIER_DEHUMIDIFIER,
|
||||
@@ -457,7 +495,9 @@ async def test_dehumidifier_target_humidity_modes(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
async def test_migrate_entity_ids(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
get_next_aid: Callable[[], int],
|
||||
) -> None:
|
||||
"""Test that we can migrate humidifier entity ids."""
|
||||
aid = get_next_aid()
|
||||
@@ -467,7 +507,7 @@ async def test_migrate_entity_ids(
|
||||
"homekit_controller",
|
||||
f"homekit-00:00:00:00:00:00-{aid}-8",
|
||||
)
|
||||
await setup_test_component(hass, create_humidifier_service)
|
||||
await setup_test_component(hass, aid, create_humidifier_service)
|
||||
assert (
|
||||
entity_registry.async_get(humidifier_entry.entity_id).unique_id
|
||||
== f"00:00:00:00:00:00_{aid}_8"
|
||||
|
||||
Reference in New Issue
Block a user