mirror of
https://github.com/home-assistant/core.git
synced 2025-10-16 07:09:27 +00:00
Fix homekit_controller tests to avoid global aid generation (#119852)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
"""Basic checks for HomeKitclimate."""
|
||||
|
||||
from collections.abc import Callable
|
||||
|
||||
from aiohomekit.model.characteristics import (
|
||||
ActivationStateValues,
|
||||
CharacteristicsTypes,
|
||||
@@ -21,7 +23,7 @@ from homeassistant.components.climate import (
|
||||
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
|
||||
|
||||
# Test thermostat devices
|
||||
|
||||
@@ -73,9 +75,13 @@ def create_thermostat_service_min_max(accessory):
|
||||
char.maxValue = 1
|
||||
|
||||
|
||||
async def test_climate_respect_supported_op_modes_1(hass: HomeAssistant) -> None:
|
||||
async def test_climate_respect_supported_op_modes_1(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that climate respects minValue/maxValue hints."""
|
||||
helper = await setup_test_component(hass, create_thermostat_service_min_max)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_thermostat_service_min_max
|
||||
)
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes["hvac_modes"] == ["off", "heat"]
|
||||
|
||||
@@ -88,16 +94,22 @@ def create_thermostat_service_valid_vals(accessory):
|
||||
char.valid_values = [0, 1, 2]
|
||||
|
||||
|
||||
async def test_climate_respect_supported_op_modes_2(hass: HomeAssistant) -> None:
|
||||
async def test_climate_respect_supported_op_modes_2(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that climate respects validValue hints."""
|
||||
helper = await setup_test_component(hass, create_thermostat_service_valid_vals)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_thermostat_service_valid_vals
|
||||
)
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes["hvac_modes"] == ["off", "heat", "cool"]
|
||||
|
||||
|
||||
async def test_climate_change_thermostat_state(hass: HomeAssistant) -> None:
|
||||
async def test_climate_change_thermostat_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can turn a HomeKit thermostat on and off again."""
|
||||
helper = await setup_test_component(hass, create_thermostat_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_thermostat_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -178,9 +190,11 @@ async def test_climate_change_thermostat_state(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_climate_check_min_max_values_per_mode(hass: HomeAssistant) -> None:
|
||||
async def test_climate_check_min_max_values_per_mode(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we we get the appropriate min/max values for each mode."""
|
||||
helper = await setup_test_component(hass, create_thermostat_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_thermostat_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -213,9 +227,11 @@ async def test_climate_check_min_max_values_per_mode(hass: HomeAssistant) -> Non
|
||||
assert climate_state.attributes["max_temp"] == 40
|
||||
|
||||
|
||||
async def test_climate_change_thermostat_temperature(hass: HomeAssistant) -> None:
|
||||
async def test_climate_change_thermostat_temperature(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can turn a HomeKit thermostat on and off again."""
|
||||
helper = await setup_test_component(hass, create_thermostat_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_thermostat_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -244,9 +260,11 @@ async def test_climate_change_thermostat_temperature(hass: HomeAssistant) -> Non
|
||||
)
|
||||
|
||||
|
||||
async def test_climate_change_thermostat_temperature_range(hass: HomeAssistant) -> None:
|
||||
async def test_climate_change_thermostat_temperature_range(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can set separate heat and cool setpoints in heat_cool mode."""
|
||||
helper = await setup_test_component(hass, create_thermostat_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_thermostat_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -278,10 +296,10 @@ async def test_climate_change_thermostat_temperature_range(hass: HomeAssistant)
|
||||
|
||||
|
||||
async def test_climate_change_thermostat_temperature_range_iphone(
|
||||
hass: HomeAssistant,
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can set all three set points at once (iPhone heat_cool mode support)."""
|
||||
helper = await setup_test_component(hass, create_thermostat_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_thermostat_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -313,10 +331,10 @@ async def test_climate_change_thermostat_temperature_range_iphone(
|
||||
|
||||
|
||||
async def test_climate_cannot_set_thermostat_temp_range_in_wrong_mode(
|
||||
hass: HomeAssistant,
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we cannot set range values when not in heat_cool mode."""
|
||||
helper = await setup_test_component(hass, create_thermostat_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_thermostat_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -372,10 +390,12 @@ def create_thermostat_single_set_point_auto(accessory):
|
||||
|
||||
|
||||
async def test_climate_check_min_max_values_per_mode_sspa_device(
|
||||
hass: HomeAssistant,
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test appropriate min/max values for each mode on sspa devices."""
|
||||
helper = await setup_test_component(hass, create_thermostat_single_set_point_auto)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_thermostat_single_set_point_auto
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -408,9 +428,13 @@ async def test_climate_check_min_max_values_per_mode_sspa_device(
|
||||
assert climate_state.attributes["max_temp"] == 35
|
||||
|
||||
|
||||
async def test_climate_set_thermostat_temp_on_sspa_device(hass: HomeAssistant) -> None:
|
||||
async def test_climate_set_thermostat_temp_on_sspa_device(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test setting temperature in different modes on device with single set point in auto."""
|
||||
helper = await setup_test_component(hass, create_thermostat_single_set_point_auto)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_thermostat_single_set_point_auto
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -462,9 +486,13 @@ async def test_climate_set_thermostat_temp_on_sspa_device(hass: HomeAssistant) -
|
||||
)
|
||||
|
||||
|
||||
async def test_climate_set_mode_via_temp(hass: HomeAssistant) -> None:
|
||||
async def test_climate_set_mode_via_temp(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test setting temperature and mode at same tims."""
|
||||
helper = await setup_test_component(hass, create_thermostat_single_set_point_auto)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_thermostat_single_set_point_auto
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -503,9 +531,11 @@ async def test_climate_set_mode_via_temp(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_climate_change_thermostat_humidity(hass: HomeAssistant) -> None:
|
||||
async def test_climate_change_thermostat_humidity(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can turn a HomeKit thermostat on and off again."""
|
||||
helper = await setup_test_component(hass, create_thermostat_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_thermostat_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -534,9 +564,11 @@ async def test_climate_change_thermostat_humidity(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_climate_read_thermostat_state(hass: HomeAssistant) -> None:
|
||||
async def test_climate_read_thermostat_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can read the state of a HomeKit thermostat accessory."""
|
||||
helper = await setup_test_component(hass, create_thermostat_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_thermostat_service)
|
||||
|
||||
# Simulate that heating is on
|
||||
await helper.async_update(
|
||||
@@ -591,9 +623,11 @@ async def test_climate_read_thermostat_state(hass: HomeAssistant) -> None:
|
||||
assert state.state == HVACMode.HEAT_COOL
|
||||
|
||||
|
||||
async def test_hvac_mode_vs_hvac_action(hass: HomeAssistant) -> None:
|
||||
async def test_hvac_mode_vs_hvac_action(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Check that we haven't conflated hvac_mode and hvac_action."""
|
||||
helper = await setup_test_component(hass, create_thermostat_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_thermostat_service)
|
||||
|
||||
# Simulate that current temperature is above target temp
|
||||
# Heating might be on, but hvac_action currently 'off'
|
||||
@@ -628,9 +662,11 @@ async def test_hvac_mode_vs_hvac_action(hass: HomeAssistant) -> None:
|
||||
assert state.attributes["hvac_action"] == "heating"
|
||||
|
||||
|
||||
async def test_hvac_mode_vs_hvac_action_current_mode_wrong(hass: HomeAssistant) -> None:
|
||||
async def test_hvac_mode_vs_hvac_action_current_mode_wrong(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Check that we cope with buggy HEATING_COOLING_CURRENT."""
|
||||
helper = await setup_test_component(hass, create_thermostat_service)
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_thermostat_service)
|
||||
|
||||
await helper.async_update(
|
||||
ServicesTypes.THERMOSTAT,
|
||||
@@ -692,9 +728,13 @@ def create_heater_cooler_service_min_max(accessory):
|
||||
char.maxValue = 2
|
||||
|
||||
|
||||
async def test_heater_cooler_respect_supported_op_modes_1(hass: HomeAssistant) -> None:
|
||||
async def test_heater_cooler_respect_supported_op_modes_1(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that climate respects minValue/maxValue hints."""
|
||||
helper = await setup_test_component(hass, create_heater_cooler_service_min_max)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_heater_cooler_service_min_max
|
||||
)
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes["hvac_modes"] == ["heat", "cool", "off"]
|
||||
|
||||
@@ -707,16 +747,24 @@ def create_theater_cooler_service_valid_vals(accessory):
|
||||
char.valid_values = [1, 2]
|
||||
|
||||
|
||||
async def test_heater_cooler_respect_supported_op_modes_2(hass: HomeAssistant) -> None:
|
||||
async def test_heater_cooler_respect_supported_op_modes_2(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that climate respects validValue hints."""
|
||||
helper = await setup_test_component(hass, create_theater_cooler_service_valid_vals)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_theater_cooler_service_valid_vals
|
||||
)
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes["hvac_modes"] == ["heat", "cool", "off"]
|
||||
|
||||
|
||||
async def test_heater_cooler_change_thermostat_state(hass: HomeAssistant) -> None:
|
||||
async def test_heater_cooler_change_thermostat_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can change the operational mode."""
|
||||
helper = await setup_test_component(hass, create_heater_cooler_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_heater_cooler_service
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -771,12 +819,16 @@ async def test_heater_cooler_change_thermostat_state(hass: HomeAssistant) -> Non
|
||||
)
|
||||
|
||||
|
||||
async def test_can_turn_on_after_off(hass: HomeAssistant) -> None:
|
||||
async def test_can_turn_on_after_off(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we always force device from inactive to active when setting mode.
|
||||
|
||||
This is a regression test for #81863.
|
||||
"""
|
||||
helper = await setup_test_component(hass, create_heater_cooler_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_heater_cooler_service
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -806,9 +858,13 @@ async def test_can_turn_on_after_off(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_heater_cooler_change_thermostat_temperature(hass: HomeAssistant) -> None:
|
||||
async def test_heater_cooler_change_thermostat_temperature(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can change the target temperature."""
|
||||
helper = await setup_test_component(hass, create_heater_cooler_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_heater_cooler_service
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -849,9 +905,13 @@ async def test_heater_cooler_change_thermostat_temperature(hass: HomeAssistant)
|
||||
)
|
||||
|
||||
|
||||
async def test_heater_cooler_change_fan_speed(hass: HomeAssistant) -> None:
|
||||
async def test_heater_cooler_change_fan_speed(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can change the target fan speed."""
|
||||
helper = await setup_test_component(hass, create_heater_cooler_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_heater_cooler_service
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -897,9 +957,13 @@ async def test_heater_cooler_change_fan_speed(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_heater_cooler_read_fan_speed(hass: HomeAssistant) -> None:
|
||||
async def test_heater_cooler_read_fan_speed(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can read the state of a HomeKit thermostat accessory."""
|
||||
helper = await setup_test_component(hass, create_heater_cooler_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_heater_cooler_service
|
||||
)
|
||||
|
||||
# Simulate that fan speed is off
|
||||
await helper.async_update(
|
||||
@@ -946,9 +1010,13 @@ async def test_heater_cooler_read_fan_speed(hass: HomeAssistant) -> None:
|
||||
assert state.attributes["fan_mode"] == "high"
|
||||
|
||||
|
||||
async def test_heater_cooler_read_thermostat_state(hass: HomeAssistant) -> None:
|
||||
async def test_heater_cooler_read_thermostat_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can read the state of a HomeKit thermostat accessory."""
|
||||
helper = await setup_test_component(hass, create_heater_cooler_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_heater_cooler_service
|
||||
)
|
||||
|
||||
# Simulate that heating is on
|
||||
await helper.async_update(
|
||||
@@ -1000,9 +1068,13 @@ async def test_heater_cooler_read_thermostat_state(hass: HomeAssistant) -> None:
|
||||
assert state.state == HVACMode.HEAT_COOL
|
||||
|
||||
|
||||
async def test_heater_cooler_hvac_mode_vs_hvac_action(hass: HomeAssistant) -> None:
|
||||
async def test_heater_cooler_hvac_mode_vs_hvac_action(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Check that we haven't conflated hvac_mode and hvac_action."""
|
||||
helper = await setup_test_component(hass, create_heater_cooler_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_heater_cooler_service
|
||||
)
|
||||
|
||||
# Simulate that current temperature is above target temp
|
||||
# Heating might be on, but hvac_action currently 'off'
|
||||
@@ -1039,9 +1111,13 @@ async def test_heater_cooler_hvac_mode_vs_hvac_action(hass: HomeAssistant) -> No
|
||||
assert state.attributes["hvac_action"] == "heating"
|
||||
|
||||
|
||||
async def test_heater_cooler_change_swing_mode(hass: HomeAssistant) -> None:
|
||||
async def test_heater_cooler_change_swing_mode(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can change the swing mode."""
|
||||
helper = await setup_test_component(hass, create_heater_cooler_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_heater_cooler_service
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -1070,9 +1146,13 @@ async def test_heater_cooler_change_swing_mode(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_heater_cooler_turn_off(hass: HomeAssistant) -> None:
|
||||
async def test_heater_cooler_turn_off(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that both hvac_action and hvac_mode return "off" when turned off."""
|
||||
helper = await setup_test_component(hass, create_heater_cooler_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_heater_cooler_service
|
||||
)
|
||||
|
||||
# Simulate that the device is turned off but CURRENT_HEATER_COOLER_STATE still returns HEATING/COOLING
|
||||
await helper.async_update(
|
||||
@@ -1090,7 +1170,9 @@ async def test_heater_cooler_turn_off(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 switch unique id."""
|
||||
aid = get_next_aid()
|
||||
@@ -1099,7 +1181,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_heater_cooler_service)
|
||||
await setup_test_component(hass, aid, create_heater_cooler_service)
|
||||
assert (
|
||||
entity_registry.async_get(climate_entry.entity_id).unique_id
|
||||
== f"00:00:00:00:00:00_{aid}_8"
|
||||
|
Reference in New Issue
Block a user