From 279539265b55f7726a9d375231801ceb07aa11dc Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 10 Jun 2025 12:38:25 +0200 Subject: [PATCH] Use async_load_fixture in modern_forms tests (#146011) --- tests/components/modern_forms/__init__.py | 48 +++++++++++++++-------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/tests/components/modern_forms/__init__.py b/tests/components/modern_forms/__init__.py index 5882eaf1ec9..3887e470c3f 100644 --- a/tests/components/modern_forms/__init__.py +++ b/tests/components/modern_forms/__init__.py @@ -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}, )