diff --git a/tests/components/esphome/conftest.py b/tests/components/esphome/conftest.py index 2786ed8324c..08a581be6d9 100644 --- a/tests/components/esphome/conftest.py +++ b/tests/components/esphome/conftest.py @@ -4,9 +4,9 @@ from __future__ import annotations import asyncio from asyncio import Event -from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine +from collections.abc import AsyncGenerator, Callable, Coroutine, Generator from pathlib import Path -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, Protocol from unittest.mock import AsyncMock, MagicMock, Mock, patch from aioesphomeapi import ( @@ -48,6 +48,46 @@ if TYPE_CHECKING: from aioesphomeapi.api_pb2 import SubscribeLogsResponse +class MockGenericDeviceEntryType(Protocol): + """Mock ESPHome device entry type.""" + + async def __call__( + self, + mock_client: APIClient, + entity_info: list[EntityInfo], + user_service: list[UserService], + states: list[EntityState], + mock_storage: bool = ..., + ) -> MockConfigEntry: + """Mock an ESPHome device entry.""" + + +class MockESPHomeDeviceType(Protocol): + """Mock ESPHome device type.""" + + async def __call__( + self, + mock_client: APIClient, + entity_info: list[EntityInfo] | None = ..., + user_service: list[UserService] | None = ..., + states: list[EntityState] | None = ..., + entry: MockConfigEntry | None = ..., + device_info: dict[str, Any] | None = ..., + mock_storage: bool = ..., + ) -> MockESPHomeDevice: + """Mock an ESPHome device.""" + + +class MockBluetoothEntryType(Protocol): + """Mock ESPHome bluetooth entry type.""" + + async def __call__( + self, + bluetooth_proxy_feature_flags: BluetoothProxyFeature, + ) -> MockESPHomeDevice: + """Mock an ESPHome bluetooth entry.""" + + _ONE_SECOND = 16000 * 2 # 16Khz 16-bit @@ -133,7 +173,7 @@ async def init_integration( @pytest.fixture -def mock_client(mock_device_info) -> APIClient: +def mock_client(mock_device_info) -> Generator[APIClient]: """Mock APIClient.""" mock_client = Mock(spec=APIClient) @@ -573,7 +613,7 @@ async def mock_voice_assistant_api_entry(mock_voice_assistant_entry) -> MockConf async def mock_bluetooth_entry( hass: HomeAssistant, mock_client: APIClient, -): +) -> MockBluetoothEntryType: """Set up an ESPHome entry with bluetooth.""" async def _mock_bluetooth_entry( @@ -608,7 +648,9 @@ async def mock_bluetooth_entry( @pytest.fixture -async def mock_bluetooth_entry_with_raw_adv(mock_bluetooth_entry) -> MockESPHomeDevice: +async def mock_bluetooth_entry_with_raw_adv( + mock_bluetooth_entry: MockBluetoothEntryType, +) -> MockESPHomeDevice: """Set up an ESPHome entry with bluetooth and raw advertisements.""" return await mock_bluetooth_entry( bluetooth_proxy_feature_flags=BluetoothProxyFeature.PASSIVE_SCAN @@ -622,7 +664,7 @@ async def mock_bluetooth_entry_with_raw_adv(mock_bluetooth_entry) -> MockESPHome @pytest.fixture async def mock_bluetooth_entry_with_legacy_adv( - mock_bluetooth_entry, + mock_bluetooth_entry: MockBluetoothEntryType, ) -> MockESPHomeDevice: """Set up an ESPHome entry with bluetooth with legacy advertisements.""" return await mock_bluetooth_entry( @@ -638,10 +680,7 @@ async def mock_bluetooth_entry_with_legacy_adv( async def mock_generic_device_entry( hass: HomeAssistant, hass_storage: dict[str, Any], -) -> Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockConfigEntry], -]: +) -> MockGenericDeviceEntryType: """Set up an ESPHome entry and return the MockConfigEntry.""" async def _mock_device_entry( @@ -670,10 +709,7 @@ async def mock_generic_device_entry( async def mock_esphome_device( hass: HomeAssistant, hass_storage: dict[str, Any], -) -> Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], -]: +) -> MockESPHomeDeviceType: """Set up an ESPHome entry and return the MockESPHomeDevice.""" async def _mock_device( diff --git a/tests/components/esphome/test_alarm_control_panel.py b/tests/components/esphome/test_alarm_control_panel.py index a3bfc72f3e2..5a90086eac0 100644 --- a/tests/components/esphome/test_alarm_control_panel.py +++ b/tests/components/esphome/test_alarm_control_panel.py @@ -26,11 +26,13 @@ from homeassistant.components.esphome.alarm_control_panel import EspHomeACPFeatu from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN from homeassistant.core import HomeAssistant +from .conftest import MockGenericDeviceEntryType + async def test_generic_alarm_control_panel_requires_code( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic alarm_control_panel entity that requires a code.""" entity_info = [ @@ -163,7 +165,7 @@ async def test_generic_alarm_control_panel_requires_code( async def test_generic_alarm_control_panel_no_code( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic alarm_control_panel entity that does not require a code.""" entity_info = [ @@ -209,7 +211,7 @@ async def test_generic_alarm_control_panel_no_code( async def test_generic_alarm_control_panel_missing_state( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic alarm_control_panel entity that is missing state.""" entity_info = [ diff --git a/tests/components/esphome/test_assist_satellite.py b/tests/components/esphome/test_assist_satellite.py index dddbbcc45f1..50ce362d7b6 100644 --- a/tests/components/esphome/test_assist_satellite.py +++ b/tests/components/esphome/test_assist_satellite.py @@ -1,7 +1,6 @@ """Test ESPHome voice assistant server.""" import asyncio -from collections.abc import Awaitable, Callable from dataclasses import replace import io import socket @@ -10,12 +9,9 @@ import wave from aioesphomeapi import ( APIClient, - EntityInfo, - EntityState, MediaPlayerFormatPurpose, MediaPlayerInfo, MediaPlayerSupportedFormat, - UserService, VoiceAssistantAnnounceFinished, VoiceAssistantAudioSettings, VoiceAssistantCommandFlag, @@ -51,7 +47,7 @@ from homeassistant.helpers import device_registry as dr, intent as intent_helper from homeassistant.helpers.network import get_url from .common import get_satellite_entity -from .conftest import MockESPHomeDevice +from .conftest import MockESPHomeDeviceType from tests.components.tts.common import MockResultStream @@ -72,13 +68,10 @@ def mock_wav() -> bytes: async def test_no_satellite_without_voice_assistant( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test that an assist satellite entity is not created if a voice assistant is not present.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -95,16 +88,13 @@ async def test_pipeline_api_audio( hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, mock_wav: bytes, ) -> None: """Test a complete pipeline run with API audio (over the TCP connection).""" conversation_id = "test-conversation-id" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -404,10 +394,7 @@ async def test_pipeline_api_audio( async def test_pipeline_udp_audio( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, mock_wav: bytes, ) -> None: """Test a complete pipeline run with legacy UDP audio. @@ -417,7 +404,7 @@ async def test_pipeline_udp_audio( """ conversation_id = "test-conversation-id" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -617,10 +604,7 @@ async def test_udp_errors() -> None: async def test_pipeline_media_player( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, mock_wav: bytes, ) -> None: """Test a complete pipeline run with the TTS response sent to a media player instead of a speaker. @@ -630,7 +614,7 @@ async def test_pipeline_media_player( """ conversation_id = "test-conversation-id" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -772,14 +756,11 @@ async def test_timer_events( hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test that injecting timer events results in the correct api client calls.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -846,14 +827,11 @@ async def test_unknown_timer_event( hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test that unknown (new) timer event types do not result in api calls.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -893,14 +871,11 @@ async def test_unknown_timer_event( async def test_streaming_tts_errors( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, mock_wav: bytes, ) -> None: """Test error conditions for _stream_tts_audio function.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -978,13 +953,10 @@ async def test_streaming_tts_errors( async def test_tts_format_from_media_player( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test that the text-to-speech format is pulled from the first media player.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[ MediaPlayerInfo( @@ -1048,13 +1020,10 @@ async def test_tts_format_from_media_player( async def test_tts_minimal_format_from_media_player( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test text-to-speech format when media player only specifies the codec.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[ MediaPlayerInfo( @@ -1115,13 +1084,10 @@ async def test_tts_minimal_format_from_media_player( async def test_announce_message( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test announcement with message.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -1192,14 +1158,11 @@ async def test_announce_message( async def test_announce_media_id( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, device_registry: dr.DeviceRegistry, ) -> None: """Test announcement with media id.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[ MediaPlayerInfo( @@ -1292,13 +1255,10 @@ async def test_announce_media_id( async def test_announce_message_with_preannounce( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test announcement with message and preannounce media id.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -1369,13 +1329,10 @@ async def test_announce_message_with_preannounce( async def test_non_default_supported_features( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test that the start conversation and announce are not set by default.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -1398,13 +1355,10 @@ async def test_non_default_supported_features( async def test_start_conversation_message( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test start conversation with message.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -1494,14 +1448,11 @@ async def test_start_conversation_message( async def test_start_conversation_media_id( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, device_registry: dr.DeviceRegistry, ) -> None: """Test start conversation with media id.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[ MediaPlayerInfo( @@ -1613,13 +1564,10 @@ async def test_start_conversation_media_id( async def test_start_conversation_message_with_preannounce( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test start conversation with message and preannounce media id.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -1709,13 +1657,10 @@ async def test_start_conversation_message_with_preannounce( async def test_satellite_unloaded_on_disconnect( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test that the assist satellite platform is unloaded on disconnect.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -1744,13 +1689,10 @@ async def test_satellite_unloaded_on_disconnect( async def test_pipeline_abort( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test aborting a pipeline (no further processing).""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -1821,10 +1763,7 @@ async def test_pipeline_abort( async def test_get_set_configuration( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test getting and setting the satellite configuration.""" expected_config = AssistSatelliteConfiguration( @@ -1837,7 +1776,7 @@ async def test_get_set_configuration( ) mock_client.get_voice_assistant_configuration.return_value = expected_config - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -1874,10 +1813,7 @@ async def test_get_set_configuration( async def test_wake_word_select( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test wake word select.""" device_config = AssistSatelliteConfiguration( @@ -1901,7 +1837,7 @@ async def test_wake_word_select( mock_client.set_voice_assistant_configuration = AsyncMock(side_effect=wrapper) - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], diff --git a/tests/components/esphome/test_binary_sensor.py b/tests/components/esphome/test_binary_sensor.py index 9965c26f2e3..fee285ea312 100644 --- a/tests/components/esphome/test_binary_sensor.py +++ b/tests/components/esphome/test_binary_sensor.py @@ -1,23 +1,12 @@ """Test ESPHome binary sensors.""" -from collections.abc import Awaitable, Callable - -from aioesphomeapi import ( - APIClient, - BinarySensorInfo, - BinarySensorState, - EntityInfo, - EntityState, - UserService, -) +from aioesphomeapi import APIClient, BinarySensorInfo, BinarySensorState import pytest from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNKNOWN from homeassistant.core import HomeAssistant -from .conftest import MockESPHomeDevice - -from tests.common import MockConfigEntry +from .conftest import MockESPHomeDeviceType, MockGenericDeviceEntryType @pytest.mark.parametrize( @@ -27,10 +16,7 @@ async def test_binary_sensor_generic_entity( hass: HomeAssistant, mock_client: APIClient, binary_state: tuple[bool, str], - mock_generic_device_entry: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockConfigEntry], - ], + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic binary_sensor entity.""" entity_info = [ @@ -58,10 +44,7 @@ async def test_binary_sensor_generic_entity( async def test_status_binary_sensor( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockConfigEntry], - ], + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic binary_sensor entity.""" entity_info = [ @@ -89,10 +72,7 @@ async def test_status_binary_sensor( async def test_binary_sensor_missing_state( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockConfigEntry], - ], + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic binary_sensor that is missing state.""" entity_info = [ @@ -119,10 +99,7 @@ async def test_binary_sensor_missing_state( async def test_binary_sensor_has_state_false( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a generic binary_sensor where has_state is false.""" entity_info = [ diff --git a/tests/components/esphome/test_camera.py b/tests/components/esphome/test_camera.py index 87b86b039fd..b03d2bb7983 100644 --- a/tests/components/esphome/test_camera.py +++ b/tests/components/esphome/test_camera.py @@ -1,21 +1,12 @@ """Test ESPHome cameras.""" -from collections.abc import Awaitable, Callable - -from aioesphomeapi import ( - APIClient, - CameraInfo, - CameraState as ESPHomeCameraState, - EntityInfo, - EntityState, - UserService, -) +from aioesphomeapi import APIClient, CameraInfo, CameraState as ESPHomeCameraState from homeassistant.components.camera import CameraState from homeassistant.const import STATE_UNAVAILABLE from homeassistant.core import HomeAssistant -from .conftest import MockESPHomeDevice +from .conftest import MockESPHomeDeviceType from tests.typing import ClientSessionGenerator @@ -30,10 +21,7 @@ SMALLEST_VALID_JPEG_BYTES = bytes.fromhex(SMALLEST_VALID_JPEG) async def test_camera_single_image( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, hass_client: ClientSessionGenerator, ) -> None: """Test a generic camera single image request.""" @@ -78,10 +66,7 @@ async def test_camera_single_image( async def test_camera_single_image_unavailable_before_requested( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, hass_client: ClientSessionGenerator, ) -> None: """Test a generic camera that goes unavailable before the request.""" @@ -119,10 +104,7 @@ async def test_camera_single_image_unavailable_before_requested( async def test_camera_single_image_unavailable_during_request( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, hass_client: ClientSessionGenerator, ) -> None: """Test a generic camera that goes unavailable before the request.""" @@ -164,10 +146,7 @@ async def test_camera_single_image_unavailable_during_request( async def test_camera_stream( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, hass_client: ClientSessionGenerator, ) -> None: """Test a generic camera stream.""" @@ -224,10 +203,7 @@ async def test_camera_stream( async def test_camera_stream_unavailable( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, hass_client: ClientSessionGenerator, ) -> None: """Test a generic camera stream when the device is disconnected.""" @@ -264,10 +240,7 @@ async def test_camera_stream_unavailable( async def test_camera_stream_with_disconnection( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, hass_client: ClientSessionGenerator, ) -> None: """Test a generic camera stream that goes unavailable during the request.""" diff --git a/tests/components/esphome/test_climate.py b/tests/components/esphome/test_climate.py index 03d2f78a5d2..739c2119bf0 100644 --- a/tests/components/esphome/test_climate.py +++ b/tests/components/esphome/test_climate.py @@ -44,9 +44,13 @@ from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant from homeassistant.exceptions import ServiceValidationError +from .conftest import MockGenericDeviceEntryType + async def test_climate_entity( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic climate entity.""" entity_info = [ @@ -94,7 +98,9 @@ async def test_climate_entity( async def test_climate_entity_with_step_and_two_point( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic climate entity.""" entity_info = [ @@ -168,7 +174,9 @@ async def test_climate_entity_with_step_and_two_point( async def test_climate_entity_with_step_and_target_temp( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic climate entity.""" entity_info = [ @@ -318,7 +326,9 @@ async def test_climate_entity_with_step_and_target_temp( async def test_climate_entity_with_humidity( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic climate entity with humidity.""" entity_info = [ @@ -378,7 +388,9 @@ async def test_climate_entity_with_humidity( async def test_climate_entity_with_inf_value( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic climate entity with infinite temp.""" entity_info = [ @@ -433,7 +445,7 @@ async def test_climate_entity_with_inf_value( async def test_climate_entity_attributes( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, snapshot: SnapshotAssertion, ) -> None: """Test a climate entity sets correct attributes.""" @@ -489,7 +501,7 @@ async def test_climate_entity_attributes( async def test_climate_entity_attribute_current_temperature_unsupported( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a climate entity with current temperature unsupported.""" entity_info = [ diff --git a/tests/components/esphome/test_config_flow.py b/tests/components/esphome/test_config_flow.py index 3e58244707d..53abf6fb3ab 100644 --- a/tests/components/esphome/test_config_flow.py +++ b/tests/components/esphome/test_config_flow.py @@ -1,6 +1,5 @@ """Test config flow.""" -from collections.abc import Awaitable, Callable from ipaddress import ip_address import json from typing import Any @@ -10,13 +9,10 @@ from aioesphomeapi import ( APIClient, APIConnectionError, DeviceInfo, - EntityInfo, - EntityState, InvalidAuthAPIError, InvalidEncryptionKeyAPIError, RequiresEncryptionAPIError, ResolveAPIError, - UserService, ) import aiohttp import pytest @@ -41,6 +37,7 @@ from homeassistant.helpers.service_info.mqtt import MqttServiceInfo from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo from . import VALID_NOISE_PSK +from .conftest import MockGenericDeviceEntryType from tests.common import MockConfigEntry @@ -1660,10 +1657,7 @@ async def test_zeroconf_no_encryption_key_via_dashboard( async def test_option_flow_allow_service_calls( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockConfigEntry], - ], + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test config flow options for allow service calls.""" entry = await mock_generic_device_entry( @@ -1708,10 +1702,7 @@ async def test_option_flow_allow_service_calls( async def test_option_flow_subscribe_logs( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockConfigEntry], - ], + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test config flow options with subscribe logs.""" entry = await mock_generic_device_entry( diff --git a/tests/components/esphome/test_cover.py b/tests/components/esphome/test_cover.py index 4cfe91c6dea..2ea789e9cc1 100644 --- a/tests/components/esphome/test_cover.py +++ b/tests/components/esphome/test_cover.py @@ -1,6 +1,5 @@ """Test ESPHome covers.""" -from collections.abc import Awaitable, Callable from unittest.mock import call from aioesphomeapi import ( @@ -8,9 +7,6 @@ from aioesphomeapi import ( CoverInfo, CoverOperation, CoverState as ESPHomeCoverState, - EntityInfo, - EntityState, - UserService, ) from homeassistant.components.cover import ( @@ -31,16 +27,13 @@ from homeassistant.components.cover import ( from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant -from .conftest import MockESPHomeDevice +from .conftest import MockESPHomeDeviceType async def test_cover_entity( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a generic cover entity.""" entity_info = [ @@ -168,10 +161,7 @@ async def test_cover_entity( async def test_cover_entity_without_position( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a generic cover entity without position, tilt, or stop.""" entity_info = [ diff --git a/tests/components/esphome/test_date.py b/tests/components/esphome/test_date.py index 2deb92775fb..4bf291c50f5 100644 --- a/tests/components/esphome/test_date.py +++ b/tests/components/esphome/test_date.py @@ -12,11 +12,13 @@ from homeassistant.components.date import ( from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN from homeassistant.core import HomeAssistant +from .conftest import MockGenericDeviceEntryType + async def test_generic_date_entity( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic date entity.""" entity_info = [ @@ -52,7 +54,7 @@ async def test_generic_date_entity( async def test_generic_date_missing_state( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic date entity with missing state.""" entity_info = [ diff --git a/tests/components/esphome/test_datetime.py b/tests/components/esphome/test_datetime.py index 3bdc196de95..1ccb101f581 100644 --- a/tests/components/esphome/test_datetime.py +++ b/tests/components/esphome/test_datetime.py @@ -12,11 +12,13 @@ from homeassistant.components.datetime import ( from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN from homeassistant.core import HomeAssistant +from .conftest import MockGenericDeviceEntryType + async def test_generic_datetime_entity( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic datetime entity.""" entity_info = [ @@ -55,7 +57,7 @@ async def test_generic_datetime_entity( async def test_generic_datetime_missing_state( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic datetime entity with missing state.""" entity_info = [ diff --git a/tests/components/esphome/test_entity.py b/tests/components/esphome/test_entity.py index 1184b345d14..71a9c16cee3 100644 --- a/tests/components/esphome/test_entity.py +++ b/tests/components/esphome/test_entity.py @@ -1,7 +1,6 @@ """Test ESPHome binary sensors.""" import asyncio -from collections.abc import Awaitable, Callable from typing import Any from unittest.mock import AsyncMock @@ -9,11 +8,8 @@ from aioesphomeapi import ( APIClient, BinarySensorInfo, BinarySensorState, - EntityInfo, - EntityState, SensorInfo, SensorState, - UserService, ) from homeassistant.const import ( @@ -28,7 +24,7 @@ from homeassistant.core import Event, EventStateChangedData, HomeAssistant, call from homeassistant.helpers import entity_registry as er from homeassistant.helpers.event import async_track_state_change_event -from .conftest import MockESPHomeDevice +from .conftest import MockESPHomeDevice, MockESPHomeDeviceType async def test_entities_removed( @@ -36,10 +32,7 @@ async def test_entities_removed( entity_registry: er.EntityRegistry, mock_client: APIClient, hass_storage: dict[str, Any], - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test entities are removed when static info changes.""" entity_info = [ @@ -131,10 +124,7 @@ async def test_entities_removed_after_reload( entity_registry: er.EntityRegistry, mock_client: APIClient, hass_storage: dict[str, Any], - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test entities and their registry entry are removed when static info changes after a reload.""" entity_info = [ @@ -263,10 +253,7 @@ async def test_entities_for_entire_platform_removed( entity_registry: er.EntityRegistry, mock_client: APIClient, hass_storage: dict[str, Any], - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test removing all entities for a specific platform when static info changes.""" entity_info = [ @@ -331,10 +318,7 @@ async def test_entities_for_entire_platform_removed( async def test_entity_info_object_ids( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test how object ids affect entity id.""" entity_info = [ @@ -361,10 +345,7 @@ async def test_deep_sleep_device( hass: HomeAssistant, mock_client: APIClient, hass_storage: dict[str, Any], - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a deep sleep device.""" entity_info = [ @@ -472,10 +453,7 @@ async def test_esphome_device_without_friendly_name( hass: HomeAssistant, mock_client: APIClient, hass_storage: dict[str, Any], - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a device without friendly_name set.""" entity_info = [ @@ -507,10 +485,7 @@ async def test_entity_without_name_device_with_friendly_name( hass: HomeAssistant, mock_client: APIClient, hass_storage: dict[str, Any], - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test name and entity_id for a device a friendly name and an entity without a name.""" entity_info = [ diff --git a/tests/components/esphome/test_entry_data.py b/tests/components/esphome/test_entry_data.py index 61d0688e641..886e5317462 100644 --- a/tests/components/esphome/test_entry_data.py +++ b/tests/components/esphome/test_entry_data.py @@ -12,12 +12,14 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er +from .conftest import MockGenericDeviceEntryType + async def test_migrate_entity_unique_id( hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic sensor entity unique id migration.""" entity_registry.async_get_or_create( @@ -60,7 +62,7 @@ async def test_migrate_entity_unique_id_downgrade_upgrade( hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test unique id migration prefers the original entity on downgrade upgrade.""" entity_registry.async_get_or_create( diff --git a/tests/components/esphome/test_fan.py b/tests/components/esphome/test_fan.py index 064b37b1ec1..a56ec1caeba 100644 --- a/tests/components/esphome/test_fan.py +++ b/tests/components/esphome/test_fan.py @@ -30,9 +30,13 @@ from homeassistant.components.fan import ( from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant +from .conftest import MockGenericDeviceEntryType + async def test_fan_entity_with_all_features_old_api( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic fan entity that uses the old api and has all features.""" entity_info = [ @@ -132,7 +136,9 @@ async def test_fan_entity_with_all_features_old_api( async def test_fan_entity_with_all_features_new_api( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic fan entity that uses the new api and has all features.""" mock_client.api_version = APIVersion(1, 4) @@ -284,7 +290,9 @@ async def test_fan_entity_with_all_features_new_api( async def test_fan_entity_with_no_features_new_api( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic fan entity that uses the new api and has no features.""" mock_client.api_version = APIVersion(1, 4) diff --git a/tests/components/esphome/test_light.py b/tests/components/esphome/test_light.py index e713bbbe630..d3302cab75c 100644 --- a/tests/components/esphome/test_light.py +++ b/tests/components/esphome/test_light.py @@ -38,11 +38,15 @@ from homeassistant.components.light import ( from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant +from .conftest import MockGenericDeviceEntryType + LIGHT_COLOR_CAPABILITY_UNKNOWN = 1 << 8 # 256 async def test_light_on_off( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic light entity that only supports on/off.""" mock_client.api_version = APIVersion(1, 7) @@ -82,7 +86,9 @@ async def test_light_on_off( async def test_light_brightness( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic light entity that only supports brightness.""" mock_client.api_version = APIVersion(1, 7) @@ -198,7 +204,9 @@ async def test_light_brightness( async def test_light_brightness_on_off( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic light entity that only supports brightness.""" mock_client.api_version = APIVersion(1, 7) @@ -266,7 +274,9 @@ async def test_light_brightness_on_off( async def test_light_legacy_white_converted_to_brightness( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic light entity that only supports legacy white.""" mock_client.api_version = APIVersion(1, 7) @@ -318,7 +328,9 @@ async def test_light_legacy_white_converted_to_brightness( async def test_light_legacy_white_with_rgb( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic light entity with rgb and white.""" mock_client.api_version = APIVersion(1, 7) @@ -380,7 +392,9 @@ async def test_light_legacy_white_with_rgb( async def test_light_brightness_on_off_with_unknown_color_mode( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic light entity that only supports brightness along with an unknown color mode.""" mock_client.api_version = APIVersion(1, 7) @@ -452,7 +466,9 @@ async def test_light_brightness_on_off_with_unknown_color_mode( async def test_light_on_and_brightness( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic light entity that supports on and on and brightness.""" mock_client.api_version = APIVersion(1, 7) @@ -495,7 +511,9 @@ async def test_light_on_and_brightness( async def test_rgb_color_temp_light( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic light that supports color temp and RGB.""" color_modes = [ @@ -591,7 +609,9 @@ async def test_rgb_color_temp_light( async def test_light_rgb( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic RGB light entity.""" mock_client.api_version = APIVersion(1, 7) @@ -708,7 +728,9 @@ async def test_light_rgb( async def test_light_rgbw( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic RGBW light entity.""" mock_client.api_version = APIVersion(1, 7) @@ -871,7 +893,9 @@ async def test_light_rgbw( async def test_light_rgbww_with_cold_warm_white_support( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic RGBWW light entity with cold warm white support.""" mock_client.api_version = APIVersion(1, 7) @@ -1111,7 +1135,9 @@ async def test_light_rgbww_with_cold_warm_white_support( async def test_light_rgbww_without_cold_warm_white_support( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic RGBWW light entity without cold warm white support.""" mock_client.api_version = APIVersion(1, 7) @@ -1341,7 +1367,9 @@ async def test_light_rgbww_without_cold_warm_white_support( async def test_light_color_temp( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic light entity that does supports color temp.""" mock_client.api_version = APIVersion(1, 7) @@ -1413,7 +1441,9 @@ async def test_light_color_temp( async def test_light_color_temp_no_mireds_set( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic color temp with no mireds set uses the defaults.""" mock_client.api_version = APIVersion(1, 7) @@ -1505,7 +1535,9 @@ async def test_light_color_temp_no_mireds_set( async def test_light_color_temp_legacy( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a legacy light entity that does supports color temp.""" mock_client.api_version = APIVersion(1, 7) @@ -1587,7 +1619,9 @@ async def test_light_color_temp_legacy( async def test_light_rgb_legacy( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a legacy light entity that supports rgb.""" mock_client.api_version = APIVersion(1, 5) @@ -1683,7 +1717,9 @@ async def test_light_rgb_legacy( async def test_light_effects( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic light entity that supports on and on and brightness.""" mock_client.api_version = APIVersion(1, 7) @@ -1735,7 +1771,9 @@ async def test_light_effects( async def test_only_cold_warm_white_support( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic light entity with only cold warm white support.""" mock_client.api_version = APIVersion(1, 7) @@ -1831,7 +1869,9 @@ async def test_only_cold_warm_white_support( async def test_light_no_color_modes( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic light entity with no color modes.""" mock_client.api_version = APIVersion(1, 7) diff --git a/tests/components/esphome/test_lock.py b/tests/components/esphome/test_lock.py index ae54b16d6e2..96c91b1d79f 100644 --- a/tests/components/esphome/test_lock.py +++ b/tests/components/esphome/test_lock.py @@ -20,9 +20,13 @@ from homeassistant.components.lock import ( from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant +from .conftest import MockGenericDeviceEntryType + async def test_lock_entity_no_open( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic lock entity that does not support open.""" entity_info = [ @@ -58,7 +62,9 @@ async def test_lock_entity_no_open( async def test_lock_entity_start_locked( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic lock entity that does not support open.""" entity_info = [ @@ -83,7 +89,9 @@ async def test_lock_entity_start_locked( async def test_lock_entity_supports_open( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic lock entity that supports open.""" entity_info = [ diff --git a/tests/components/esphome/test_manager.py b/tests/components/esphome/test_manager.py index 652d2453e05..ac7c7ce1d47 100644 --- a/tests/components/esphome/test_manager.py +++ b/tests/components/esphome/test_manager.py @@ -1,7 +1,6 @@ """Test ESPHome manager.""" import asyncio -from collections.abc import Awaitable, Callable import logging from unittest.mock import AsyncMock, Mock, call @@ -10,8 +9,6 @@ from aioesphomeapi import ( APIConnectionError, DeviceInfo, EncryptionPlaintextAPIError, - EntityInfo, - EntityState, HomeassistantServiceCall, InvalidAuthAPIError, InvalidEncryptionKeyAPIError, @@ -52,7 +49,7 @@ from homeassistant.helpers import ( from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo from homeassistant.setup import async_setup_component -from .conftest import MockESPHomeDevice +from .conftest import MockESPHomeDeviceType, MockGenericDeviceEntryType from tests.common import ( MockConfigEntry, @@ -65,10 +62,7 @@ from tests.common import ( async def test_esphome_device_subscribe_logs( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, caplog: pytest.LogCaptureFixture, ) -> None: """Test configuring a device to subscribe to logs.""" @@ -83,7 +77,7 @@ async def test_esphome_device_subscribe_logs( options={CONF_SUBSCRIBE_LOGS: True}, ) entry.add_to_hass(hass) - device: MockESPHomeDevice = await mock_esphome_device( + device = await mock_esphome_device( mock_client=mock_client, entry=entry, entity_info=[], @@ -142,10 +136,7 @@ async def test_esphome_device_subscribe_logs( async def test_esphome_device_service_calls_not_allowed( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, caplog: pytest.LogCaptureFixture, issue_registry: ir.IssueRegistry, ) -> None: @@ -153,7 +144,7 @@ async def test_esphome_device_service_calls_not_allowed( entity_info = [] states = [] user_service = [] - device: MockESPHomeDevice = await mock_esphome_device( + device = await mock_esphome_device( mock_client=mock_client, entity_info=entity_info, user_service=user_service, @@ -185,10 +176,7 @@ async def test_esphome_device_service_calls_allowed( hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, caplog: pytest.LogCaptureFixture, issue_registry: ir.IssueRegistry, ) -> None: @@ -200,7 +188,7 @@ async def test_esphome_device_service_calls_allowed( hass.config_entries.async_update_entry( mock_config_entry, options={CONF_ALLOW_SERVICE_CALLS: True} ) - device: MockESPHomeDevice = await mock_esphome_device( + device = await mock_esphome_device( mock_client=mock_client, entity_info=entity_info, user_service=user_service, @@ -345,10 +333,7 @@ async def test_esphome_device_service_calls_allowed( async def test_esphome_device_with_old_bluetooth( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, issue_registry: ir.IssueRegistry, ) -> None: """Test a device with old bluetooth creates an issue.""" @@ -375,10 +360,7 @@ async def test_esphome_device_with_old_bluetooth( async def test_esphome_device_with_password( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, issue_registry: ir.IssueRegistry, ) -> None: """Test a device with legacy password creates an issue.""" @@ -418,10 +400,7 @@ async def test_esphome_device_with_password( async def test_esphome_device_with_current_bluetooth( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, issue_registry: ir.IssueRegistry, ) -> None: """Test a device with recent bluetooth does not create an issue.""" @@ -450,7 +429,9 @@ async def test_esphome_device_with_current_bluetooth( @pytest.mark.usefixtures("mock_zeroconf") -async def test_unique_id_updated_to_mac(hass: HomeAssistant, mock_client) -> None: +async def test_unique_id_updated_to_mac( + hass: HomeAssistant, mock_client: APIClient +) -> None: """Test we update config entry unique ID to MAC address.""" entry = MockConfigEntry( domain=DOMAIN, @@ -871,13 +852,10 @@ async def test_failure_during_connect( async def test_state_subscription( mock_client: APIClient, hass: HomeAssistant, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test ESPHome subscribes to state changes.""" - device: MockESPHomeDevice = await mock_esphome_device( + device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -934,13 +912,10 @@ async def test_state_subscription( async def test_state_request( mock_client: APIClient, hass: HomeAssistant, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test ESPHome requests state change.""" - device: MockESPHomeDevice = await mock_esphome_device( + device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -962,10 +937,7 @@ async def test_state_request( async def test_debug_logging( mock_client: APIClient, hass: HomeAssistant, - mock_generic_device_entry: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockConfigEntry], - ], + mock_generic_device_entry: MockGenericDeviceEntryType, caplog: pytest.LogCaptureFixture, ) -> None: """Test enabling and disabling debug logging.""" @@ -991,10 +963,7 @@ async def test_debug_logging( async def test_esphome_device_with_dash_in_name_user_services( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a device with user services and a dash in the name.""" entity_info = [] @@ -1063,10 +1032,7 @@ async def test_esphome_device_with_dash_in_name_user_services( async def test_esphome_user_services_ignores_invalid_arg_types( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a device with user services and a dash in the name.""" entity_info = [] @@ -1128,10 +1094,7 @@ async def test_esphome_user_services_ignores_invalid_arg_types( async def test_esphome_user_service_fails( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test executing a user service fails due to disconnect.""" entity_info = [] @@ -1187,10 +1150,7 @@ async def test_esphome_user_service_fails( async def test_esphome_user_services_changes( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a device with user services that change arguments.""" entity_info = [] @@ -1269,10 +1229,7 @@ async def test_esphome_device_with_suggested_area( hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a device with suggested area.""" device = await mock_esphome_device( @@ -1294,10 +1251,7 @@ async def test_esphome_device_with_project( hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a device with a project.""" device = await mock_esphome_device( @@ -1321,10 +1275,7 @@ async def test_esphome_device_with_manufacturer( hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a device with a manufacturer.""" device = await mock_esphome_device( @@ -1346,10 +1297,7 @@ async def test_esphome_device_with_web_server( hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a device with a web server.""" device = await mock_esphome_device( @@ -1371,10 +1319,7 @@ async def test_esphome_device_with_ipv6_web_server( hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a device with a web server.""" entry = MockConfigEntry( @@ -1407,10 +1352,7 @@ async def test_esphome_device_with_compilation_time( hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a device with a compilation_time.""" device = await mock_esphome_device( @@ -1431,10 +1373,7 @@ async def test_esphome_device_with_compilation_time( async def test_disconnects_at_close_event( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test the device is disconnected at the close event.""" await mock_esphome_device( @@ -1465,10 +1404,7 @@ async def test_disconnects_at_close_event( async def test_start_reauth( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, error: Exception, ) -> None: """Test exceptions on connect error trigger reauth.""" @@ -1493,10 +1429,7 @@ async def test_start_reauth( async def test_no_reauth_wrong_mac( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, caplog: pytest.LogCaptureFixture, ) -> None: """Test exceptions on connect error trigger reauth.""" @@ -1529,10 +1462,7 @@ async def test_no_reauth_wrong_mac( async def test_entry_missing_unique_id( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test the unique id is added from storage if available.""" entry = MockConfigEntry( @@ -1554,10 +1484,7 @@ async def test_entry_missing_unique_id( async def test_entry_missing_bluetooth_mac_address( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test the bluetooth_mac_address is added if available.""" entry = MockConfigEntry( @@ -1583,16 +1510,13 @@ async def test_entry_missing_bluetooth_mac_address( async def test_device_adds_friendly_name( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, caplog: pytest.LogCaptureFixture, ) -> None: """Test a device with user services that change arguments.""" entity_info = [] states = [] - device: MockESPHomeDevice = await mock_esphome_device( + device = await mock_esphome_device( mock_client=mock_client, entity_info=entity_info, user_service=[], @@ -1633,10 +1557,7 @@ async def test_assist_in_progress_issue_deleted( mock_client: APIClient, entity_registry: er.EntityRegistry, issue_registry: ir.IssueRegistry, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test assist in progress entity and issue is deleted. diff --git a/tests/components/esphome/test_media_player.py b/tests/components/esphome/test_media_player.py index a425b730771..18a997dc09a 100644 --- a/tests/components/esphome/test_media_player.py +++ b/tests/components/esphome/test_media_player.py @@ -1,12 +1,9 @@ """Test ESPHome media_players.""" -from collections.abc import Awaitable, Callable from unittest.mock import AsyncMock, Mock, call, patch from aioesphomeapi import ( APIClient, - EntityInfo, - EntityState, MediaPlayerCommand, MediaPlayerEntityState, MediaPlayerFormatPurpose, @@ -41,14 +38,16 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr from homeassistant.setup import async_setup_component -from .conftest import MockESPHomeDevice +from .conftest import MockESPHomeDeviceType, MockGenericDeviceEntryType from tests.common import mock_platform from tests.typing import WebSocketGenerator async def test_media_player_entity( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic media_player entity.""" entity_info = [ @@ -160,7 +159,7 @@ async def test_media_player_entity_with_source( hass: HomeAssistant, mock_client: APIClient, hass_ws_client: WebSocketGenerator, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic media_player entity media source.""" await async_setup_component(hass, "media_source", {"media_source": {}}) @@ -293,13 +292,10 @@ async def test_media_player_proxy( hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a media_player entity with a proxy URL.""" - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[ MediaPlayerInfo( diff --git a/tests/components/esphome/test_number.py b/tests/components/esphome/test_number.py index 557425052f3..9a711f2766e 100644 --- a/tests/components/esphome/test_number.py +++ b/tests/components/esphome/test_number.py @@ -21,11 +21,13 @@ from homeassistant.const import ATTR_ENTITY_ID, ATTR_UNIT_OF_MEASUREMENT, STATE_ from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError +from .conftest import MockGenericDeviceEntryType + async def test_generic_number_entity( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic number entity.""" entity_info = [ @@ -65,7 +67,7 @@ async def test_generic_number_entity( async def test_generic_number_nan( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic number entity with nan state.""" entity_info = [ @@ -97,7 +99,7 @@ async def test_generic_number_nan( async def test_generic_number_with_unit_of_measurement_as_empty_string( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic number entity with nan state.""" entity_info = [ @@ -130,7 +132,7 @@ async def test_generic_number_with_unit_of_measurement_as_empty_string( async def test_generic_number_entity_set_when_disconnected( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic number entity.""" entity_info = [ diff --git a/tests/components/esphome/test_repairs.py b/tests/components/esphome/test_repairs.py index 5f6b75a3508..268b30f8b52 100644 --- a/tests/components/esphome/test_repairs.py +++ b/tests/components/esphome/test_repairs.py @@ -3,18 +3,9 @@ from __future__ import annotations import asyncio -from collections.abc import Awaitable, Callable from unittest.mock import AsyncMock -from aioesphomeapi import ( - APIClient, - BinarySensorInfo, - BinarySensorState, - DeviceInfo, - EntityInfo, - EntityState, - UserService, -) +from aioesphomeapi import APIClient, BinarySensorInfo, BinarySensorState, DeviceInfo import pytest from homeassistant.components.esphome import repairs @@ -29,7 +20,7 @@ from homeassistant.helpers import ( issue_registry as ir, ) -from .conftest import MockESPHomeDevice +from .conftest import MockESPHomeDeviceType from tests.common import MockConfigEntry from tests.components.repairs import ( @@ -135,10 +126,7 @@ async def test_device_conflict_migration( entity_registry: er.EntityRegistry, device_registry: dr.DeviceRegistry, caplog: pytest.LogCaptureFixture, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test migrating existing configuration to new hardware.""" entity_info = [ @@ -152,7 +140,7 @@ async def test_device_conflict_migration( ] states = [BinarySensorState(key=1, state=None)] user_service = [] - device: MockESPHomeDevice = await mock_esphome_device( + device = await mock_esphome_device( mock_client=mock_client, entity_info=entity_info, user_service=user_service, diff --git a/tests/components/esphome/test_select.py b/tests/components/esphome/test_select.py index e170a1a7f6d..09a8f739e71 100644 --- a/tests/components/esphome/test_select.py +++ b/tests/components/esphome/test_select.py @@ -1,17 +1,9 @@ """Test ESPHome selects.""" -from collections.abc import Awaitable, Callable from unittest.mock import call -from aioesphomeapi import ( - APIClient, - EntityInfo, - EntityState, - SelectInfo, - SelectState, - UserService, - VoiceAssistantFeature, -) +from aioesphomeapi import APIClient, SelectInfo, SelectState, VoiceAssistantFeature +import pytest from homeassistant.components.assist_satellite import ( AssistSatelliteConfiguration, @@ -26,12 +18,12 @@ from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE from homeassistant.core import HomeAssistant from .common import get_satellite_entity -from .conftest import MockESPHomeDevice +from .conftest import MockESPHomeDeviceType, MockGenericDeviceEntryType +@pytest.mark.usefixtures("mock_voice_assistant_v1_entry") async def test_pipeline_selector( hass: HomeAssistant, - mock_voice_assistant_v1_entry, ) -> None: """Test assist pipeline selector.""" @@ -40,9 +32,9 @@ async def test_pipeline_selector( assert state.state == "preferred" +@pytest.mark.usefixtures("mock_voice_assistant_v1_entry") async def test_vad_sensitivity_select( hass: HomeAssistant, - mock_voice_assistant_v1_entry, ) -> None: """Test VAD sensitivity select. @@ -54,9 +46,9 @@ async def test_vad_sensitivity_select( assert state.state == "default" +@pytest.mark.usefixtures("mock_voice_assistant_v1_entry") async def test_wake_word_select( hass: HomeAssistant, - mock_voice_assistant_v1_entry, ) -> None: """Test that wake word select is unavailable initially.""" state = hass.states.get("select.test_wake_word") @@ -65,7 +57,9 @@ async def test_wake_word_select( async def test_select_generic_entity( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic select entity.""" entity_info = [ @@ -101,10 +95,7 @@ async def test_select_generic_entity( async def test_wake_word_select_no_wake_words( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test wake word select is unavailable when there are no available wake word.""" device_config = AssistSatelliteConfiguration( @@ -114,7 +105,7 @@ async def test_wake_word_select_no_wake_words( ) mock_client.get_voice_assistant_configuration.return_value = device_config - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -139,10 +130,7 @@ async def test_wake_word_select_no_wake_words( async def test_wake_word_select_zero_max_wake_words( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test wake word select is unavailable max wake words is zero.""" device_config = AssistSatelliteConfiguration( @@ -154,7 +142,7 @@ async def test_wake_word_select_zero_max_wake_words( ) mock_client.get_voice_assistant_configuration.return_value = device_config - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -179,10 +167,7 @@ async def test_wake_word_select_zero_max_wake_words( async def test_wake_word_select_no_active_wake_words( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test wake word select uses first available wake word if none are active.""" device_config = AssistSatelliteConfiguration( @@ -195,7 +180,7 @@ async def test_wake_word_select_no_active_wake_words( ) mock_client.get_voice_assistant_configuration.return_value = device_config - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], diff --git a/tests/components/esphome/test_sensor.py b/tests/components/esphome/test_sensor.py index 76f71b53167..0c443dc5941 100644 --- a/tests/components/esphome/test_sensor.py +++ b/tests/components/esphome/test_sensor.py @@ -1,21 +1,17 @@ """Test ESPHome sensors.""" -from collections.abc import Awaitable, Callable import logging import math from aioesphomeapi import ( APIClient, EntityCategory as ESPHomeEntityCategory, - EntityInfo, - EntityState, LastResetType, SensorInfo, SensorState, SensorStateClass as ESPHomeSensorStateClass, TextSensorInfo, TextSensorState, - UserService, ) from homeassistant.components.sensor import ( @@ -33,16 +29,13 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er -from .conftest import MockESPHomeDevice +from .conftest import MockESPHomeDeviceType, MockGenericDeviceEntryType async def test_generic_numeric_sensor( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a generic sensor entity.""" logging.getLogger("homeassistant.components.esphome").setLevel(logging.DEBUG) @@ -99,7 +92,7 @@ async def test_generic_numeric_sensor_with_entity_category_and_icon( hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic sensor entity.""" entity_info = [ @@ -136,7 +129,7 @@ async def test_generic_numeric_sensor_state_class_measurement( hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic sensor entity.""" entity_info = [ @@ -173,7 +166,7 @@ async def test_generic_numeric_sensor_state_class_measurement( async def test_generic_numeric_sensor_device_class_timestamp( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a sensor entity that uses timestamp (epoch).""" entity_info = [ @@ -201,7 +194,7 @@ async def test_generic_numeric_sensor_device_class_timestamp( async def test_generic_numeric_sensor_legacy_last_reset_convert( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a state class of measurement with last reset type of auto is converted to total increasing.""" entity_info = [ @@ -229,7 +222,9 @@ async def test_generic_numeric_sensor_legacy_last_reset_convert( async def test_generic_numeric_sensor_no_state( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic numeric sensor that has no state.""" entity_info = [ @@ -254,7 +249,9 @@ async def test_generic_numeric_sensor_no_state( async def test_generic_numeric_sensor_nan_state( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic numeric sensor that has nan state.""" entity_info = [ @@ -279,7 +276,9 @@ async def test_generic_numeric_sensor_nan_state( async def test_generic_numeric_sensor_missing_state( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic numeric sensor that is missing state.""" entity_info = [ @@ -306,7 +305,7 @@ async def test_generic_numeric_sensor_missing_state( async def test_generic_text_sensor( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic text sensor entity.""" entity_info = [ @@ -331,7 +330,9 @@ async def test_generic_text_sensor( async def test_generic_text_sensor_missing_state( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic text sensor that is missing state.""" entity_info = [ @@ -358,7 +359,7 @@ async def test_generic_text_sensor_missing_state( async def test_generic_text_sensor_device_class_timestamp( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a sensor entity that uses timestamp (datetime).""" entity_info = [ @@ -387,7 +388,7 @@ async def test_generic_text_sensor_device_class_timestamp( async def test_generic_text_sensor_device_class_date( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a sensor entity that uses date (datetime).""" entity_info = [ @@ -414,7 +415,9 @@ async def test_generic_text_sensor_device_class_date( async def test_generic_numeric_sensor_empty_string_uom( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic numeric sensor that has an empty string as the uom.""" entity_info = [ diff --git a/tests/components/esphome/test_switch.py b/tests/components/esphome/test_switch.py index 561ac0b369f..b3c13ee2fe5 100644 --- a/tests/components/esphome/test_switch.py +++ b/tests/components/esphome/test_switch.py @@ -12,9 +12,13 @@ from homeassistant.components.switch import ( from homeassistant.const import ATTR_ENTITY_ID, STATE_ON from homeassistant.core import HomeAssistant +from .conftest import MockGenericDeviceEntryType + async def test_switch_generic_entity( - hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry + hass: HomeAssistant, + mock_client: APIClient, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic switch entity.""" entity_info = [ diff --git a/tests/components/esphome/test_text.py b/tests/components/esphome/test_text.py index 07157d98ac6..899b4a732ca 100644 --- a/tests/components/esphome/test_text.py +++ b/tests/components/esphome/test_text.py @@ -12,11 +12,13 @@ from homeassistant.components.text import ( from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN from homeassistant.core import HomeAssistant +from .conftest import MockGenericDeviceEntryType + async def test_generic_text_entity( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic text entity.""" entity_info = [ @@ -56,7 +58,7 @@ async def test_generic_text_entity( async def test_generic_text_entity_no_state( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic text entity that has no state.""" entity_info = [ @@ -87,7 +89,7 @@ async def test_generic_text_entity_no_state( async def test_generic_text_entity_missing_state( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic text entity that has no state.""" entity_info = [ diff --git a/tests/components/esphome/test_time.py b/tests/components/esphome/test_time.py index aaa18c77a47..543a903f0a9 100644 --- a/tests/components/esphome/test_time.py +++ b/tests/components/esphome/test_time.py @@ -12,11 +12,13 @@ from homeassistant.components.time import ( from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN from homeassistant.core import HomeAssistant +from .conftest import MockGenericDeviceEntryType + async def test_generic_time_entity( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic time entity.""" entity_info = [ @@ -52,7 +54,7 @@ async def test_generic_time_entity( async def test_generic_time_missing_state( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic time entity with missing state.""" entity_info = [ diff --git a/tests/components/esphome/test_update.py b/tests/components/esphome/test_update.py index a461f322088..c9b88d9fb57 100644 --- a/tests/components/esphome/test_update.py +++ b/tests/components/esphome/test_update.py @@ -1,18 +1,9 @@ """Test ESPHome update entities.""" -from collections.abc import Awaitable, Callable from typing import Any from unittest.mock import patch -from aioesphomeapi import ( - APIClient, - EntityInfo, - EntityState, - UpdateCommand, - UpdateInfo, - UpdateState, - UserService, -) +from aioesphomeapi import APIClient, UpdateCommand, UpdateInfo, UpdateState import pytest from homeassistant.components.esphome.dashboard import async_get_dashboard @@ -35,7 +26,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError -from .conftest import MockESPHomeDevice +from .conftest import MockESPHomeDeviceType, MockGenericDeviceEntryType @pytest.fixture(autouse=True) @@ -91,10 +82,7 @@ async def test_update_entity( expected_state: str, expected_attributes: dict[str, Any], mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test ESPHome update entity.""" mock_dashboard["configured"] = devices_payload @@ -199,10 +187,7 @@ async def test_update_entity( async def test_update_static_info( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, mock_dashboard: dict[str, Any], ) -> None: """Test ESPHome update entity.""" @@ -214,7 +199,7 @@ async def test_update_static_info( ] await async_get_dashboard(hass).async_refresh() - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=[], user_service=[], @@ -251,10 +236,7 @@ async def test_update_device_state_for_availability( has_deep_sleep: bool, mock_dashboard: dict[str, Any], mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test ESPHome update entity changes availability with the device.""" mock_dashboard["configured"] = [ @@ -283,10 +265,7 @@ async def test_update_device_state_for_availability( async def test_update_entity_dashboard_not_available_startup( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, mock_dashboard: dict[str, Any], ) -> None: """Test ESPHome update entity when dashboard is not available at startup.""" @@ -332,10 +311,7 @@ async def test_update_entity_dashboard_not_available_startup( async def test_update_entity_dashboard_discovered_after_startup_but_update_failed( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, mock_dashboard: dict[str, Any], ) -> None: """Test ESPHome update entity when dashboard is discovered after startup and the first update fails.""" @@ -382,10 +358,7 @@ async def test_update_entity_dashboard_discovered_after_startup_but_update_faile async def test_update_entity_not_present_without_dashboard( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test ESPHome update entity does not get created if there is no dashboard.""" await mock_esphome_device( @@ -402,10 +375,7 @@ async def test_update_entity_not_present_without_dashboard( async def test_update_becomes_available_at_runtime( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, mock_dashboard: dict[str, Any], ) -> None: """Test ESPHome update entity when the dashboard has no device at startup but gets them later.""" @@ -441,10 +411,7 @@ async def test_update_becomes_available_at_runtime( async def test_update_entity_not_present_with_dashboard_but_unknown_device( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, mock_dashboard: dict[str, Any], ) -> None: """Test ESPHome update entity does not get created if the device is unknown to the dashboard.""" @@ -476,7 +443,7 @@ async def test_update_entity_not_present_with_dashboard_but_unknown_device( async def test_generic_device_update_entity( hass: HomeAssistant, mock_client: APIClient, - mock_generic_device_entry, + mock_generic_device_entry: MockGenericDeviceEntryType, ) -> None: """Test a generic device update entity.""" entity_info = [ @@ -512,10 +479,7 @@ async def test_generic_device_update_entity( async def test_generic_device_update_entity_has_update( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a generic device update entity with an update.""" entity_info = [ @@ -537,7 +501,7 @@ async def test_generic_device_update_entity_has_update( ) ] user_service = [] - mock_device: MockESPHomeDevice = await mock_esphome_device( + mock_device = await mock_esphome_device( mock_client=mock_client, entity_info=entity_info, user_service=user_service, diff --git a/tests/components/esphome/test_valve.py b/tests/components/esphome/test_valve.py index 7a7e22b1713..bc5c77a62d6 100644 --- a/tests/components/esphome/test_valve.py +++ b/tests/components/esphome/test_valve.py @@ -1,13 +1,9 @@ """Test ESPHome valves.""" -from collections.abc import Awaitable, Callable from unittest.mock import call from aioesphomeapi import ( APIClient, - EntityInfo, - EntityState, - UserService, ValveInfo, ValveOperation, ValveState as ESPHomeValveState, @@ -26,16 +22,13 @@ from homeassistant.components.valve import ( from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant -from .conftest import MockESPHomeDevice +from .conftest import MockESPHomeDeviceType async def test_valve_entity( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a generic valve entity.""" entity_info = [ @@ -133,10 +126,7 @@ async def test_valve_entity( async def test_valve_entity_without_position( hass: HomeAssistant, mock_client: APIClient, - mock_esphome_device: Callable[ - [APIClient, list[EntityInfo], list[UserService], list[EntityState]], - Awaitable[MockESPHomeDevice], - ], + mock_esphome_device: MockESPHomeDeviceType, ) -> None: """Test a generic valve entity without position or stop.""" entity_info = [