mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Use async_load_fixture in modern_forms tests (#146011)
This commit is contained in:
parent
4acad77437
commit
279539265b
@ -1,7 +1,9 @@
|
||||
"""Tests for the Modern Forms integration."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from collections.abc import Callable, Coroutine
|
||||
from functools import partial
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
from aiomodernforms.const import COMMAND_QUERY_STATIC_DATA
|
||||
|
||||
@ -9,40 +11,52 @@ from homeassistant.components.modern_forms.const import DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONTENT_TYPE_JSON
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
from tests.common import MockConfigEntry, async_load_fixture
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker, AiohttpClientMockResponse
|
||||
|
||||
|
||||
async def modern_forms_call_mock(method, url, data):
|
||||
async def modern_forms_call_mock(
|
||||
hass: HomeAssistant, method: str, url: str, data: dict[str, Any]
|
||||
) -> AiohttpClientMockResponse:
|
||||
"""Set up the basic returns based on info or status request."""
|
||||
if COMMAND_QUERY_STATIC_DATA in data:
|
||||
fixture = "modern_forms/device_info.json"
|
||||
fixture = "device_info.json"
|
||||
else:
|
||||
fixture = "modern_forms/device_status.json"
|
||||
fixture = "device_status.json"
|
||||
return AiohttpClientMockResponse(
|
||||
method=method, url=url, json=json.loads(load_fixture(fixture))
|
||||
method=method,
|
||||
url=url,
|
||||
json=json.loads(await async_load_fixture(hass, fixture, DOMAIN)),
|
||||
)
|
||||
|
||||
|
||||
async def modern_forms_no_light_call_mock(method, url, data):
|
||||
async def modern_forms_no_light_call_mock(
|
||||
hass: HomeAssistant, method: str, url: str, data: dict[str, Any]
|
||||
) -> AiohttpClientMockResponse:
|
||||
"""Set up the basic returns based on info or status request."""
|
||||
if COMMAND_QUERY_STATIC_DATA in data:
|
||||
fixture = "modern_forms/device_info_no_light.json"
|
||||
fixture = "device_info_no_light.json"
|
||||
else:
|
||||
fixture = "modern_forms/device_status_no_light.json"
|
||||
fixture = "device_status_no_light.json"
|
||||
return AiohttpClientMockResponse(
|
||||
method=method, url=url, json=json.loads(load_fixture(fixture))
|
||||
method=method,
|
||||
url=url,
|
||||
json=json.loads(await async_load_fixture(hass, fixture, DOMAIN)),
|
||||
)
|
||||
|
||||
|
||||
async def modern_forms_timers_set_mock(method, url, data):
|
||||
async def modern_forms_timers_set_mock(
|
||||
hass: HomeAssistant, method: str, url: str, data: dict[str, Any]
|
||||
) -> AiohttpClientMockResponse:
|
||||
"""Set up the basic returns based on info or status request."""
|
||||
if COMMAND_QUERY_STATIC_DATA in data:
|
||||
fixture = "modern_forms/device_info.json"
|
||||
fixture = "device_info.json"
|
||||
else:
|
||||
fixture = "modern_forms/device_status_timers_active.json"
|
||||
fixture = "device_status_timers_active.json"
|
||||
return AiohttpClientMockResponse(
|
||||
method=method, url=url, json=json.loads(load_fixture(fixture))
|
||||
method=method,
|
||||
url=url,
|
||||
json=json.loads(await async_load_fixture(hass, fixture, DOMAIN)),
|
||||
)
|
||||
|
||||
|
||||
@ -51,13 +65,15 @@ async def init_integration(
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
rgbw: bool = False,
|
||||
skip_setup: bool = False,
|
||||
mock_type: Callable = modern_forms_call_mock,
|
||||
mock_type: Callable[
|
||||
[str, str, dict[str, Any]], Coroutine[Any, Any, AiohttpClientMockResponse]
|
||||
] = modern_forms_call_mock,
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the Modern Forms integration in Home Assistant."""
|
||||
|
||||
aioclient_mock.post(
|
||||
"http://192.168.1.123:80/mf",
|
||||
side_effect=mock_type,
|
||||
side_effect=partial(mock_type, hass),
|
||||
headers={"Content-Type": CONTENT_TYPE_JSON},
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user