2023-01-30 12:40:07 +00:00
|
|
|
"""Typing helpers for Home Assistant tests."""
|
2024-03-08 15:36:11 +00:00
|
|
|
|
2023-01-30 12:40:07 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from collections.abc import Callable, Coroutine
|
2024-05-17 12:42:21 +00:00
|
|
|
from typing import TYPE_CHECKING, Any
|
2023-02-06 14:05:06 +00:00
|
|
|
from unittest.mock import MagicMock
|
2023-01-30 12:40:07 +00:00
|
|
|
|
|
|
|
from aiohttp import ClientWebSocketResponse
|
|
|
|
from aiohttp.test_utils import TestClient
|
|
|
|
|
2023-02-10 10:11:39 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
# Local import to avoid processing recorder module when running a
|
|
|
|
# testcase which does not use the recorder.
|
|
|
|
from homeassistant.components.recorder import Recorder
|
|
|
|
|
2023-02-10 15:23:26 +00:00
|
|
|
|
|
|
|
class MockHAClientWebSocket(ClientWebSocketResponse):
|
|
|
|
"""Protocol for a wrapped ClientWebSocketResponse."""
|
|
|
|
|
|
|
|
client: TestClient
|
|
|
|
send_json_auto_id: Callable[[dict[str, Any]], Coroutine[Any, Any, None]]
|
2024-04-28 16:50:15 +00:00
|
|
|
remove_device: Callable[[str, str], Coroutine[Any, Any, Any]]
|
2023-02-10 15:23:26 +00:00
|
|
|
|
|
|
|
|
2023-01-31 07:48:35 +00:00
|
|
|
ClientSessionGenerator = Callable[..., Coroutine[Any, Any, TestClient]]
|
2023-02-06 14:05:06 +00:00
|
|
|
MqttMockPahoClient = MagicMock
|
|
|
|
"""MagicMock for `paho.mqtt.client.Client`"""
|
|
|
|
MqttMockHAClient = MagicMock
|
|
|
|
"""MagicMock for `homeassistant.components.mqtt.MQTT`."""
|
|
|
|
MqttMockHAClientGenerator = Callable[..., Coroutine[Any, Any, MqttMockHAClient]]
|
|
|
|
"""MagicMock generator for `homeassistant.components.mqtt.MQTT`."""
|
2024-05-20 10:01:49 +00:00
|
|
|
type RecorderInstanceGenerator = Callable[..., Coroutine[Any, Any, Recorder]]
|
2023-02-10 10:11:39 +00:00
|
|
|
"""Instance generator for `homeassistant.components.recorder.Recorder`."""
|
2023-02-10 15:23:26 +00:00
|
|
|
WebSocketGenerator = Callable[..., Coroutine[Any, Any, MockHAClientWebSocket]]
|