Use assert_device_name in the a-l integration tests

This commit is contained in:
J. Nick Koston
2026-10-20 05:29:33 -10:00
parent c0cbf9cdfd
commit cfe402366c
30 changed files with 70 additions and 98 deletions
@@ -8,6 +8,7 @@ import re
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
from .wait_utils import wait_or_fail
@@ -66,9 +67,7 @@ async def test_action_concurrent_reentry(
api_client_connected() as client,
):
# Verify device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "action-concurrent-reentry"
await assert_device_name(client, "action-concurrent-reentry")
# Wait for tests to complete with timeout
await wait_or_fail(test_complete, 8.0, "test timed out")
@@ -12,6 +12,7 @@ import re
from aioesphomeapi import SupportsResponseType, UserService, UserServiceArgType
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -69,9 +70,7 @@ async def test_api_action_responses(
api_client_connected() as client,
):
# Verify device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "api-action-responses-test"
await assert_device_name(client, "api-action-responses-test")
# List services
_, services = await client.list_entities_services()
+2 -3
View File
@@ -13,6 +13,7 @@ import re
from aioesphomeapi import UserService
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -79,9 +80,7 @@ async def test_api_action_timeout(
api_client_connected() as client,
):
# Verify device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "api-action-timeout-test"
await assert_device_name(client, "api-action-timeout-test")
# List services
_, services = await client.list_entities_services()
@@ -8,6 +8,7 @@ import re
from aioesphomeapi import UserService, UserServiceArgType
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -53,9 +54,7 @@ async def test_api_conditional_memory(
async with run_compiled(yaml_config, line_callback=check_output):
async with api_client_connected() as client:
# Verify device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "api-conditional-memory-test"
await assert_device_name(client, "api-conditional-memory-test")
# Wait for connection log
await asyncio.wait_for(connected_future, timeout=5.0)
@@ -8,6 +8,7 @@ import re
from aioesphomeapi import UserService, UserServiceArgType
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -67,9 +68,7 @@ async def test_api_custom_services(
api_client_connected() as client,
):
# Verify device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "api-custom-services-test"
await assert_device_name(client, "api-custom-services-test")
# List services
_, services = await client.list_entities_services()
+2 -3
View File
@@ -16,6 +16,7 @@ import re
from aioesphomeapi import HomeassistantServiceCall
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -184,9 +185,7 @@ async def test_api_homeassistant(
api_client_connected() as client,
):
# Verify device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "test-ha-api"
await assert_device_name(client, "test-ha-api")
# Store client reference for use in service call callback
client_ref.append(client)
@@ -13,6 +13,7 @@ import asyncio
from aioesphomeapi import ButtonInfo, HomeassistantServiceCall
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -59,8 +60,7 @@ async def test_api_homeassistant_action_no_subscriber(
await asyncio.wait_for(boot_warning_future, timeout=10.0)
async with api_client_connected() as client:
device_info = await client.device_info()
assert device_info.name == "test-ha-action-no-subscriber"
await assert_device_name(client, "test-ha-action-no-subscriber")
# on_client_connected fired at authentication, before this client
# subscribed to Home Assistant actions.
@@ -7,6 +7,7 @@ import asyncio
from aioesphomeapi import EntityState, NumberInfo, SelectInfo, TextInfo, TextSensorInfo
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -21,9 +22,7 @@ async def test_api_message_size_batching(
loop = asyncio.get_running_loop()
async with run_compiled(yaml_config), api_client_connected() as client:
# Verify we can get device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "message-size-batching-test"
await assert_device_name(client, "message-size-batching-test")
# List entities - this will batch various sized messages together
entity_info, services = await asyncio.wait_for(
+2 -3
View File
@@ -7,6 +7,7 @@ import re
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
from .wait_utils import wait_or_fail
@@ -49,9 +50,7 @@ async def test_api_string_lambda(
api_client_connected() as client,
):
# Verify device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "api-string-lambda-test"
await assert_device_name(client, "api-string-lambda-test")
# List services to find our test services
_, services = await client.list_entities_services()
+2 -3
View File
@@ -8,6 +8,7 @@ from typing import Any
from aioesphomeapi import LogLevel, SensorInfo
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -45,9 +46,7 @@ async def test_api_vv_logging(
client.subscribe_logs(on_log, log_level=LogLevel.LOG_LEVEL_VERY_VERBOSE)
# Wait for device to be ready
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "vv-logging-test"
await assert_device_name(client, "vv-logging-test")
# Subscribe to sensor states
states = {}
@@ -17,6 +17,7 @@ import pytest
from .conftest import run_binary_and_wait_for_port
from .const import KEY_ACTIVATION_DELAY, LOCALHOST, PROVISIONING_PSK, ZERO_PSK
from .state_utils import assert_device_name
from .types import (
APIClientConnectedFactory,
CompileFunction,
@@ -76,8 +77,7 @@ async def test_api_zero_psk_provisioning(
# The unprovisioned device accepts the all-zeros PSK; the handshake's
# ephemeral-ephemeral DH encrypts everything that follows
async with api_client_connected(noise_psk=ZERO_PSK) as client:
device_info = await client.device_info()
assert device_info.name == "zero-psk-provision-test"
device_info = await assert_device_name(client, "zero-psk-provision-test")
assert device_info.api_encryption_supported is True
assert device_info.api_encryption_provisionable is True
@@ -88,8 +88,7 @@ async def test_api_zero_psk_provisioning(
# The new key now works, and the device is no longer provisionable
async with api_client_connected(noise_psk=NEW_KEY.decode()) as client:
device_info = await client.device_info()
assert device_info.name == "zero-psk-provision-test"
device_info = await assert_device_name(client, "zero-psk-provision-test")
assert device_info.api_encryption_provisionable is False
# The zero PSK no longer works
@@ -126,8 +125,7 @@ async def test_api_zero_psk_provisioning_plaintext(
log_lines: list[str] = []
async with run_compiled(yaml_config, line_callback=log_lines.append):
async with api_client_connected() as client:
device_info = await client.device_info()
assert device_info.name == "zero-psk-plaintext-test"
await assert_device_name(client, "zero-psk-plaintext-test")
assert await client.noise_encryption_set_key(NEW_KEY) is True
@@ -138,7 +136,7 @@ async def test_api_zero_psk_provisioning_plaintext(
# The new key works; the zero PSK does not
async with api_client_connected(noise_psk=NEW_KEY.decode()) as client:
assert (await client.device_info()).name == "zero-psk-plaintext-test"
await assert_device_name(client, "zero-psk-plaintext-test")
with pytest.raises(InvalidEncryptionKeyAPIError):
async with api_client_connected(noise_psk=ZERO_PSK, timeout=5) as client:
@@ -17,7 +17,12 @@ import asyncio
import pytest
from .state_utils import InitialStateHelper, SensorStateCollector, require_entity
from .state_utils import (
InitialStateHelper,
SensorStateCollector,
assert_device_name,
require_entity,
)
from .types import APIClientConnectedFactory, RunCompiledFunction
from .wait_utils import wait_or_fail
@@ -38,9 +43,7 @@ async def test_binary_sensor_autorepeat_filter(
run_compiled(yaml_config),
api_client_connected() as client,
):
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "test-autorepeat-filter"
await assert_device_name(client, "test-autorepeat-filter")
entities, _ = await client.list_entities_services()
collector.build_key_mapping(entities)
@@ -14,7 +14,7 @@ import asyncio
from aioesphomeapi import BinarySensorInfo, BinarySensorState, EntityState
import pytest
from .state_utils import InitialStateHelper, require_entity
from .state_utils import InitialStateHelper, assert_device_name, require_entity
from .types import APIClientConnectedFactory, RunCompiledFunction
from .wait_utils import wait_or_fail
@@ -51,9 +51,7 @@ async def test_binary_sensor_invalidate_state(
api_client_connected() as client,
):
# Verify device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "test-binary-sensor-invalidate"
await assert_device_name(client, "test-binary-sensor-invalidate")
# Get entities
entities, _ = await client.list_entities_services()
+2 -3
View File
@@ -10,6 +10,7 @@ import time
from aioesphomeapi import EntityState, TextSensorState
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
from .wait_utils import wait_or_fail
@@ -22,9 +23,7 @@ async def test_build_info(
) -> None:
"""Test that build_info values are sane."""
async with run_compiled(yaml_config), api_client_connected() as client:
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "build-info-test"
device_info = await assert_device_name(client, "build-info-test")
# Verify compilation_time from device_info is present and parseable
# The format is ISO 8601 with timezone: "YYYY-MM-DD HH:MM:SS +ZZZZ"
+2 -3
View File
@@ -6,6 +6,7 @@ import asyncio
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -65,9 +66,7 @@ async def test_crc8_helper(
api_client_connected() as client,
):
# Verify device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "crc8-helper-test"
await assert_device_name(client, "crc8-helper-test")
# Wait for tests to complete with timeout
try:
@@ -15,6 +15,7 @@ import re
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
from .wait_utils import wait_or_fail
@@ -58,9 +59,7 @@ async def test_fnv1_hash_object_id(
run_compiled(yaml_config, line_callback=on_log_line),
api_client_connected() as client,
):
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "fnv1-hash-object-id-test"
await assert_device_name(client, "fnv1-hash-object-id-test")
# Wait for all tests to complete or timeout
await wait_or_fail(
+2 -3
View File
@@ -7,6 +7,7 @@ import re
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
from .wait_utils import wait_or_fail
@@ -41,9 +42,7 @@ async def test_fnv1a_hash(
run_compiled(yaml_config, line_callback=on_log_line),
api_client_connected() as client,
):
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "fnv1a-hash-test"
await assert_device_name(client, "fnv1a-hash-test")
# Wait for all tests to complete or timeout
await wait_or_fail(
@@ -7,6 +7,7 @@ import re
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -121,9 +122,7 @@ async def test_gpio_expander_cache(
api_client_connected() as client,
):
# Verify device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "gpio-expander-cache"
await assert_device_name(client, "gpio-expander-cache")
try:
await asyncio.wait_for(logs_done.wait(), timeout=5.0)
@@ -11,6 +11,7 @@ import re
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
from .wait_utils import wait_or_fail
@@ -59,9 +60,7 @@ async def test_host_logger_thread_safety(
api_client_connected() as client,
):
# Verify connection works
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "host-logger-thread-test"
await assert_device_name(client, "host-logger-thread-test")
# Get the button entity - find by name
entities, _ = await client.list_entities_services()
+2 -3
View File
@@ -4,6 +4,7 @@ from __future__ import annotations
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -17,6 +18,4 @@ async def test_host_mode_basic(
# Write, compile and run the ESPHome device, then connect to API
async with run_compiled(yaml_config), api_client_connected() as client:
# Verify we can get device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "host-test"
await assert_device_name(client, "host-test")
@@ -8,6 +8,7 @@ import time
from aioesphomeapi import EntityState
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
from .wait_utils import wait_or_fail
@@ -23,9 +24,7 @@ async def test_host_mode_batch_delay(
loop = asyncio.get_running_loop()
async with run_compiled(yaml_config), api_client_connected() as client:
# Verify we can get device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "host-batch-delay-test"
await assert_device_name(client, "host-batch-delay-test")
# Subscribe to state changes
states: dict[int, EntityState] = {}
@@ -7,6 +7,7 @@ import asyncio
from aioesphomeapi import EntityState, SelectInfo
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
from .wait_utils import wait_or_fail
@@ -27,9 +28,7 @@ async def test_host_mode_empty_string_options(
loop = asyncio.get_running_loop()
async with run_compiled(yaml_config), api_client_connected() as client:
# Verify we can get device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "host-empty-string-test"
await assert_device_name(client, "host-empty-string-test")
# Get list of entities - this will encode ListEntitiesSelectResponse messages
# with empty string options that would trigger the bug
@@ -5,6 +5,7 @@ from __future__ import annotations
from aioesphomeapi import InvalidEncryptionKeyAPIError
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
# The API key for noise encryption
@@ -25,9 +26,7 @@ async def test_host_mode_noise_encryption(
api_client_connected(noise_psk=NOISE_KEY) as client,
):
# If we can get device info, the encryption is working
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "host-noise-test"
await assert_device_name(client, "host-noise-test")
# List entities to ensure the encrypted connection is fully functional
entities = await client.list_entities_services()
@@ -4,6 +4,7 @@ from __future__ import annotations
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -23,6 +24,4 @@ async def test_host_mode_reconnect(
# Reconnect with a new client
async with api_client_connected() as client2:
device_info2 = await client2.device_info()
assert device_info2 is not None
assert device_info2.name == device_info.name
await assert_device_name(client2, device_info.name)
+4 -6
View File
@@ -31,6 +31,7 @@ from .const import (
ZERO_PSK,
)
from .host_prefs import force_safe_mode
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, CompileFunction, ConfigWriter
DEVICE_NAME = "host-ota-test"
@@ -284,15 +285,13 @@ async def test_host_ota_self_update(
dev.proc = proc
await _wait_for_port(LOCALHOST, dev.api_port, PORT_WAIT_TIMEOUT)
async with wait_and_connect_api_client(port=dev.api_port) as client:
info_before = await client.device_info()
assert info_before.name == DEVICE_NAME
info_before = await assert_device_name(client, DEVICE_NAME)
await dev.ota(None, None, "espota2 reported failure")
assert staged.is_set()
async with wait_and_connect_api_client(port=dev.api_port) as client:
info_after = await client.device_info()
assert info_after.name == info_before.name
await assert_device_name(client, info_before.name)
# Second OTA: catches FD_CLOEXEC regressions (EADDRINUSE on rebind).
await dev.ota(None, None, "second OTA failed -- listener leaked across execv")
@@ -603,5 +602,4 @@ async def test_host_ota_rejects_garbage(
assert proc.pid == pid_before
async with wait_and_connect_api_client(port=dev.api_port) as client:
info = await client.device_info()
assert info.name == DEVICE_NAME
await assert_device_name(client, DEVICE_NAME)
@@ -5,6 +5,7 @@ from __future__ import annotations
from aioesphomeapi import SelectInfo
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -18,9 +19,7 @@ async def test_large_message_batching(
# Write, compile and run the ESPHome device, then connect to API
async with run_compiled(yaml_config), api_client_connected() as client:
# Verify we can get device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "large-message-test"
await assert_device_name(client, "large-message-test")
# List entities - this will include our select with many options
entity_info, services = await client.list_entities_services()
@@ -29,6 +29,7 @@ import re
from aioesphomeapi import LogLevel
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
_ANSI = re.compile(r"\x1b\[[0-9;]*m")
@@ -52,9 +53,7 @@ async def test_logger_buffered_recursion_guard(
run_compiled(yaml_config),
api_client_connected() as client,
):
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "logger-recursion-test"
await assert_device_name(client, "logger-recursion-test")
# Subscribe over the API: this is the exact path that crashed in the field
# (the API log callback runs during the buffered drain). The API message field
@@ -7,6 +7,7 @@ import re
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
@@ -132,9 +133,7 @@ async def test_loop_disable_enable(
api_client_connected() as client,
):
# Verify we can connect and get device info
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "loop-test"
await assert_device_name(client, "loop-test")
# Wait for self_disable_10 to disable itself
try:
@@ -21,6 +21,7 @@ import re
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
from .wait_utils import wait_or_fail
@@ -44,9 +45,7 @@ async def test_loop_interval_decoupling(
run_compiled(yaml_config, line_callback=on_log_line),
api_client_connected() as client,
):
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "loop-interval-decouple"
await assert_device_name(client, "loop-interval-decouple")
loop_delta, sched_delta = await wait_or_fail(
measurement_done, 10.0, "MEASUREMENT_DONE marker never appeared"
@@ -21,6 +21,7 @@ import re
import pytest
from .state_utils import assert_device_name
from .types import APIClientConnectedFactory, RunCompiledFunction
from .wait_utils import wait_or_fail
@@ -44,9 +45,7 @@ async def test_loop_interval_default_not_pulled_forward(
run_compiled(yaml_config, line_callback=on_log_line),
api_client_connected() as client,
):
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "loop-default-not-pulled"
await assert_device_name(client, "loop-default-not-pulled")
loop_delta = await wait_or_fail(
measurement_done, 10.0, "MEASUREMENT_DONE marker never appeared"