From 9ef51a4fae978dc044de6c6daa7adae09118226d Mon Sep 17 00:00:00 2001 From: Erik Date: Mon, 19 Aug 2024 14:09:10 +0200 Subject: [PATCH 1/2] Prepare otbr.silabs_multiprotocol for multiple config entries --- .../components/hassio/addon_manager.py | 16 +++- .../components/matter/config_flow.py | 4 +- homeassistant/components/otbr/__init__.py | 4 +- .../components/otbr/silabs_multiprotocol.py | 74 +++++++++++++---- homeassistant/components/otbr/util.py | 2 + .../components/zwave_js/config_flow.py | 4 +- tests/components/hassio/test_addon_manager.py | 10 ++- tests/components/matter/test_config_flow.py | 69 ++++++++-------- tests/components/otbr/conftest.py | 3 + .../otbr/test_silabs_multiprotocol.py | 75 +++++++++++++++++- tests/components/zwave_js/test_config_flow.py | 79 ++++++++++--------- 11 files changed, 242 insertions(+), 98 deletions(-) diff --git a/homeassistant/components/hassio/addon_manager.py b/homeassistant/components/hassio/addon_manager.py index b3c43f16be1b14..4a43574e035846 100644 --- a/homeassistant/components/hassio/addon_manager.py +++ b/homeassistant/components/hassio/addon_manager.py @@ -65,6 +65,14 @@ async def wrapper( return handle_hassio_api_error +@dataclass +class AddonDiscoveryInfo: + """Represent the add-on discovery info.""" + + config: dict + uuid: str + + @dataclass class AddonInfo: """Represent the current add-on info state.""" @@ -125,7 +133,7 @@ def task_in_progress(self) -> bool: ) @api_error("Failed to get the {addon_name} add-on discovery info") - async def async_get_addon_discovery_info(self) -> dict: + async def async_get_addon_discovery_info(self) -> AddonDiscoveryInfo: """Return add-on discovery info.""" discovery_info = await async_get_addon_discovery_info( self._hass, self.addon_slug @@ -134,8 +142,10 @@ async def async_get_addon_discovery_info(self) -> dict: if not discovery_info: raise AddonError(f"Failed to get {self.addon_name} add-on discovery info") - discovery_info_config: dict = discovery_info["config"] - return discovery_info_config + return AddonDiscoveryInfo( + config=discovery_info["config"], + uuid=discovery_info["uuid"], + ) @api_error("Failed to get the {addon_name} add-on info") async def async_get_addon_info(self) -> AddonInfo: diff --git a/homeassistant/components/matter/config_flow.py b/homeassistant/components/matter/config_flow.py index ae71b7a17116f4..5620c26d3e49e8 100644 --- a/homeassistant/components/matter/config_flow.py +++ b/homeassistant/components/matter/config_flow.py @@ -119,12 +119,12 @@ async def _async_get_addon_discovery_info(self) -> dict: """Return add-on discovery info.""" addon_manager: AddonManager = get_addon_manager(self.hass) try: - discovery_info_config = await addon_manager.async_get_addon_discovery_info() + discovery_info = await addon_manager.async_get_addon_discovery_info() except AddonError as err: LOGGER.error(err) raise AbortFlow("addon_get_discovery_info_failed") from err - return discovery_info_config + return discovery_info.config async def async_step_start_addon( self, user_input: dict[str, Any] | None = None diff --git a/homeassistant/components/otbr/__init__.py b/homeassistant/components/otbr/__init__.py index 97c2f40eb9997e..b411612f77868d 100644 --- a/homeassistant/components/otbr/__init__.py +++ b/homeassistant/components/otbr/__init__.py @@ -33,7 +33,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up an Open Thread Border Router config entry.""" api = python_otbr_api.OTBR(entry.data["url"], async_get_clientsession(hass), 10) - otbrdata = OTBRData(entry.data["url"], api, entry.entry_id) + otbrdata = OTBRData( + entry.data["url"], api, entry.entry_id, entry.source, entry.unique_id or DOMAIN + ) try: border_agent_id = await otbrdata.get_border_agent_id() dataset_tlvs = await otbrdata.get_active_dataset_tlvs() diff --git a/homeassistant/components/otbr/silabs_multiprotocol.py b/homeassistant/components/otbr/silabs_multiprotocol.py index bd7eb9975580df..e97ef91390ca19 100644 --- a/homeassistant/components/otbr/silabs_multiprotocol.py +++ b/homeassistant/components/otbr/silabs_multiprotocol.py @@ -2,16 +2,21 @@ from __future__ import annotations +from collections.abc import Callable, Coroutine +from functools import wraps import logging +from typing import Any, Concatenate import aiohttp from python_otbr_api import tlv_parser from python_otbr_api.tlv_parser import MeshcopTLVType from homeassistant.components.homeassistant_hardware.silabs_multiprotocol_addon import ( + get_multiprotocol_addon_manager, is_multiprotocol_url, ) from homeassistant.components.thread import async_add_dataset +from homeassistant.config_entries import SOURCE_HASSIO from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError @@ -21,15 +26,59 @@ _LOGGER = logging.getLogger(__name__) -async def async_change_channel(hass: HomeAssistant, channel: int, delay: float) -> None: +def async_get_otbr_data[**_P, _R, _R_Def]( + retval: _R_Def, +) -> Callable[ + [Callable[Concatenate[HomeAssistant, OTBRData, _P], Coroutine[Any, Any, _R]]], + Callable[Concatenate[HomeAssistant, _P], Coroutine[Any, Any, _R | _R_Def]], +]: + """Decorate function to get OTBR data.""" + + def _async_get_otbr_data( + orig_func: Callable[ + Concatenate[HomeAssistant, OTBRData, _P], + Coroutine[Any, Any, _R], + ], + ) -> Callable[Concatenate[HomeAssistant, _P], Coroutine[Any, Any, _R | _R_Def]]: + """Decorate function to get OTBR data.""" + + @wraps(orig_func) + async def async_get_otbr_data_wrapper( + hass: HomeAssistant, *args: _P.args, **kwargs: _P.kwargs + ) -> _R | _R_Def: + """Fetch OTBR data and pass to orig_func.""" + if DOMAIN not in hass.data: + return retval + + multipan_manager = await get_multiprotocol_addon_manager(hass) + discovery_info = await multipan_manager.async_get_addon_discovery_info() + + data: OTBRData = hass.data[DOMAIN] + + if ( + data.entry_source != SOURCE_HASSIO + or data.entry_unique_id != discovery_info.uuid + ): + return retval + + return await orig_func(hass, data, *args, **kwargs) + + return async_get_otbr_data_wrapper + + return _async_get_otbr_data + + +@async_get_otbr_data(None) +async def async_change_channel( + hass: HomeAssistant, + data: OTBRData, + channel: int, + delay: float, +) -> None: """Set the channel to be used. Does nothing if not configured. """ - if DOMAIN not in hass.data: - return - - data: OTBRData = hass.data[DOMAIN] await data.set_channel(channel, delay) # Import the new dataset @@ -48,16 +97,12 @@ async def async_change_channel(hass: HomeAssistant, channel: int, delay: float) await async_add_dataset(hass, DOMAIN, dataset_tlvs_str) -async def async_get_channel(hass: HomeAssistant) -> int | None: +@async_get_otbr_data(None) +async def async_get_channel(hass: HomeAssistant, data: OTBRData) -> int | None: """Return the channel. Returns None if not configured. """ - if DOMAIN not in hass.data: - return None - - data: OTBRData = hass.data[DOMAIN] - try: dataset = await data.get_active_dataset() except ( @@ -74,13 +119,10 @@ async def async_get_channel(hass: HomeAssistant) -> int | None: return dataset.channel -async def async_using_multipan(hass: HomeAssistant) -> bool: +@async_get_otbr_data(False) +async def async_using_multipan(hass: HomeAssistant, data: OTBRData) -> bool: """Return if the multiprotocol device is used. Returns False if not configured. """ - if DOMAIN not in hass.data: - return False - - data: OTBRData = hass.data[DOMAIN] return is_multiprotocol_url(data.url) diff --git a/homeassistant/components/otbr/util.py b/homeassistant/components/otbr/util.py index 16cf3b60e37382..7fbd9117455c91 100644 --- a/homeassistant/components/otbr/util.py +++ b/homeassistant/components/otbr/util.py @@ -80,6 +80,8 @@ class OTBRData: url: str api: python_otbr_api.OTBR entry_id: str + entry_source: str + entry_unique_id: str @_handle_otbr_error async def factory_reset(self) -> None: diff --git a/homeassistant/components/zwave_js/config_flow.py b/homeassistant/components/zwave_js/config_flow.py index e73fa9fc3a799c..fed9a113e0fd28 100644 --- a/homeassistant/components/zwave_js/config_flow.py +++ b/homeassistant/components/zwave_js/config_flow.py @@ -333,12 +333,12 @@ async def _async_get_addon_discovery_info(self) -> dict: """Return add-on discovery info.""" addon_manager: AddonManager = get_addon_manager(self.hass) try: - discovery_info_config = await addon_manager.async_get_addon_discovery_info() + discovery_info = await addon_manager.async_get_addon_discovery_info() except AddonError as err: _LOGGER.error(err) raise AbortFlow("addon_get_discovery_info_failed") from err - return discovery_info_config + return discovery_info.config class ZWaveJSConfigFlow(BaseZwaveJSFlow, ConfigFlow, domain=DOMAIN): diff --git a/tests/components/hassio/test_addon_manager.py b/tests/components/hassio/test_addon_manager.py index 6a20c6eec885e5..1165c2406e637e 100644 --- a/tests/components/hassio/test_addon_manager.py +++ b/tests/components/hassio/test_addon_manager.py @@ -11,6 +11,7 @@ import pytest from homeassistant.components.hassio.addon_manager import ( + AddonDiscoveryInfo, AddonError, AddonInfo, AddonManager, @@ -210,9 +211,14 @@ async def test_get_addon_discovery_info( addon_manager: AddonManager, get_addon_discovery_info: AsyncMock ) -> None: """Test get addon discovery info.""" - get_addon_discovery_info.return_value = {"config": {"test_key": "test"}} + get_addon_discovery_info.return_value = { + "config": {"test_key": "test"}, + "uuid": "1234", + } - assert await addon_manager.async_get_addon_discovery_info() == {"test_key": "test"} + assert await addon_manager.async_get_addon_discovery_info() == AddonDiscoveryInfo( + config={"test_key": "test"}, uuid="1234" + ) assert get_addon_discovery_info.call_count == 1 diff --git a/tests/components/matter/test_config_flow.py b/tests/components/matter/test_config_flow.py index 642bfe0f804288..d88c20e2390f23 100644 --- a/tests/components/matter/test_config_flow.py +++ b/tests/components/matter/test_config_flow.py @@ -20,9 +20,12 @@ from tests.common import MockConfigEntry ADDON_DISCOVERY_INFO = { - "addon": "Matter Server", - "host": "host1", - "port": 5581, + "config": { + "addon": "Matter Server", + "host": "host1", + "port": 5581, + }, + "uuid": "1234", } ZEROCONF_INFO_TCP = ZeroconfServiceInfo( ip_address=ip_address("fd11:be53:8d46:0:729e:5a4f:539d:1ee6"), @@ -301,7 +304,7 @@ async def test_zeroconf_discovery_not_onboarded_not_supervisor( @pytest.mark.parametrize("zeroconf_info", [ZEROCONF_INFO_TCP, ZEROCONF_INFO_UDP]) -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_zeroconf_not_onboarded_already_discovered( hass: HomeAssistant, supervisor: MagicMock, @@ -339,7 +342,7 @@ async def test_zeroconf_not_onboarded_already_discovered( @pytest.mark.parametrize("zeroconf_info", [ZEROCONF_INFO_TCP, ZEROCONF_INFO_UDP]) -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_zeroconf_not_onboarded_running( hass: HomeAssistant, supervisor: MagicMock, @@ -371,7 +374,7 @@ async def test_zeroconf_not_onboarded_running( @pytest.mark.parametrize("zeroconf_info", [ZEROCONF_INFO_TCP, ZEROCONF_INFO_UDP]) -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_zeroconf_not_onboarded_installed( hass: HomeAssistant, supervisor: MagicMock, @@ -405,7 +408,7 @@ async def test_zeroconf_not_onboarded_installed( @pytest.mark.parametrize("zeroconf_info", [ZEROCONF_INFO_TCP, ZEROCONF_INFO_UDP]) -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_zeroconf_not_onboarded_not_installed( hass: HomeAssistant, supervisor: MagicMock, @@ -442,7 +445,7 @@ async def test_zeroconf_not_onboarded_not_installed( assert setup_entry.call_count == 1 -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_supervisor_discovery( hass: HomeAssistant, supervisor: MagicMock, @@ -456,7 +459,7 @@ async def test_supervisor_discovery( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -480,7 +483,7 @@ async def test_supervisor_discovery( @pytest.mark.parametrize( ("discovery_info", "error"), - [({"config": ADDON_DISCOVERY_INFO}, HassioAPIError())], + [(ADDON_DISCOVERY_INFO, HassioAPIError())], ) async def test_supervisor_discovery_addon_info_failed( hass: HomeAssistant, @@ -496,7 +499,7 @@ async def test_supervisor_discovery_addon_info_failed( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -513,7 +516,7 @@ async def test_supervisor_discovery_addon_info_failed( assert result["reason"] == "addon_info_failed" -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_clean_supervisor_discovery_on_user_create( hass: HomeAssistant, supervisor: MagicMock, @@ -527,7 +530,7 @@ async def test_clean_supervisor_discovery_on_user_create( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -590,7 +593,7 @@ async def test_abort_supervisor_discovery_with_existing_entry( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -620,7 +623,7 @@ async def test_abort_supervisor_discovery_with_existing_flow( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -673,7 +676,7 @@ async def test_supervisor_discovery_addon_not_running( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -722,7 +725,7 @@ async def test_supervisor_discovery_addon_not_installed( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -804,7 +807,7 @@ async def test_not_addon( assert setup_entry.call_count == 1 -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_addon_running( hass: HomeAssistant, supervisor: MagicMock, @@ -850,7 +853,7 @@ async def test_addon_running( ), [ ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, HassioAPIError(), None, None, @@ -859,7 +862,7 @@ async def test_addon_running( False, ), ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, None, CannotConnect(Exception("Boom")), None, @@ -877,7 +880,7 @@ async def test_addon_running( False, ), ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, None, None, HassioAPIError(), @@ -936,7 +939,7 @@ async def test_addon_running_failures( ), [ ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, HassioAPIError(), None, None, @@ -945,7 +948,7 @@ async def test_addon_running_failures( False, ), ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, None, CannotConnect(Exception("Boom")), None, @@ -963,7 +966,7 @@ async def test_addon_running_failures( False, ), ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, None, None, HassioAPIError(), @@ -1007,7 +1010,7 @@ async def test_addon_running_failures_zeroconf( assert result["reason"] == abort_reason -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_addon_running_already_configured( hass: HomeAssistant, supervisor: MagicMock, @@ -1045,7 +1048,7 @@ async def test_addon_running_already_configured( assert setup_entry.call_count == 1 -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_addon_installed( hass: HomeAssistant, supervisor: MagicMock, @@ -1095,14 +1098,14 @@ async def test_addon_installed( ), [ ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, HassioAPIError(), None, False, False, ), ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, None, CannotConnect(Exception("Boom")), True, @@ -1170,14 +1173,14 @@ async def test_addon_installed_failures( ), [ ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, HassioAPIError(), None, False, False, ), ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, None, CannotConnect(Exception("Boom")), True, @@ -1224,7 +1227,7 @@ async def test_addon_installed_failures_zeroconf( assert result["reason"] == "addon_start_failed" -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_addon_installed_already_configured( hass: HomeAssistant, supervisor: MagicMock, @@ -1270,7 +1273,7 @@ async def test_addon_installed_already_configured( assert setup_entry.call_count == 1 -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_addon_not_installed( hass: HomeAssistant, supervisor: MagicMock, @@ -1379,7 +1382,7 @@ async def test_addon_not_installed_failures_zeroconf( assert result["reason"] == "addon_install_failed" -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_addon_not_installed_already_configured( hass: HomeAssistant, supervisor: MagicMock, diff --git a/tests/components/otbr/conftest.py b/tests/components/otbr/conftest.py index 56f29bdc79b4dd..794828ee1eefb4 100644 --- a/tests/components/otbr/conftest.py +++ b/tests/components/otbr/conftest.py @@ -5,6 +5,7 @@ import pytest from homeassistant.components import otbr +from homeassistant.config_entries import SOURCE_HASSIO from homeassistant.core import HomeAssistant from . import ( @@ -25,7 +26,9 @@ async def otbr_config_entry_multipan_fixture(hass: HomeAssistant) -> None: data=CONFIG_ENTRY_DATA_MULTIPAN, domain=otbr.DOMAIN, options={}, + source=SOURCE_HASSIO, title="Open Thread Border Router", + unique_id="1234", ) config_entry.add_to_hass(hass) with ( diff --git a/tests/components/otbr/test_silabs_multiprotocol.py b/tests/components/otbr/test_silabs_multiprotocol.py index 8d7bed13df6199..8b472f6dff74ae 100644 --- a/tests/components/otbr/test_silabs_multiprotocol.py +++ b/tests/components/otbr/test_silabs_multiprotocol.py @@ -1,6 +1,8 @@ """Test OTBR Silicon Labs Multiprotocol support.""" -from unittest.mock import patch +from collections.abc import Generator +from typing import Any +from unittest.mock import DEFAULT, AsyncMock, patch import pytest from python_otbr_api import ActiveDataSet, tlv_parser @@ -32,6 +34,43 @@ ) +ADDON_DISCOVERY_INFO = { + "config": { + "addon": "Silicon Labs Multiprotocol", + "host": "core-silabs-multiprotocol", + "port": 8081, + }, + "uuid": "1234", +} + + +ADDON_DISCOVERY_INFO_OTHER_UUID = { + "config": { + "addon": "Silicon Labs Multiprotocol", + "host": "core-silabs-multiprotocol", + "port": 8081, + }, + "uuid": "4321", +} + + +@pytest.fixture(name="discovery_info") +def discovery_info_fixture() -> Any: + """Return the discovery info from the supervisor.""" + return DEFAULT + + +@pytest.fixture(name="get_addon_discovery_info", autouse=True) +def get_addon_discovery_info_fixture(discovery_info: Any) -> Generator[AsyncMock]: + """Mock get add-on discovery info.""" + with patch( + "homeassistant.components.hassio.addon_manager.async_get_addon_discovery_info", + return_value=discovery_info, + ) as get_addon_discovery_info: + yield get_addon_discovery_info + + +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_change_channel( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: @@ -60,6 +99,7 @@ async def test_async_change_channel( ) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_change_channel_no_pending( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: @@ -92,6 +132,7 @@ async def test_async_change_channel_no_pending( ) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_change_channel_no_update( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: @@ -126,6 +167,17 @@ async def test_async_change_channel_no_otbr(hass: HomeAssistant) -> None: mock_set_channel.assert_not_awaited() +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO_OTHER_UUID]) +async def test_async_change_channel_non_matching_uuid( + hass: HomeAssistant, otbr_config_entry_multipan +) -> None: + """Test async_change_channel when otbr is not configured.""" + with patch("python_otbr_api.OTBR.set_channel") as mock_set_channel: + await otbr_silabs_multiprotocol.async_change_channel(hass, 16, delay=0) + mock_set_channel.assert_not_awaited() + + +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_get_channel( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: @@ -139,6 +191,7 @@ async def test_async_get_channel( mock_get_active_dataset.assert_awaited_once_with() +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_get_channel_no_dataset( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: @@ -152,6 +205,7 @@ async def test_async_get_channel_no_dataset( mock_get_active_dataset.assert_awaited_once_with() +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_get_channel_error( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: @@ -173,10 +227,21 @@ async def test_async_get_channel_no_otbr(hass: HomeAssistant) -> None: mock_get_active_dataset.assert_not_awaited() +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO_OTHER_UUID]) +async def test_async_get_channel_non_matching_uuid( + hass: HomeAssistant, otbr_config_entry_multipan +) -> None: + """Test async_change_channel when otbr is not configured.""" + with patch("python_otbr_api.OTBR.get_active_dataset") as mock_get_active_dataset: + assert await otbr_silabs_multiprotocol.async_get_channel(hass) is None + mock_get_active_dataset.assert_not_awaited() + + @pytest.mark.parametrize( ("url", "expected"), [(OTBR_MULTIPAN_URL, True), (OTBR_NON_MULTIPAN_URL, False)], ) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_using_multipan( hass: HomeAssistant, otbr_config_entry_multipan, url: str, expected: bool ) -> None: @@ -191,3 +256,11 @@ async def test_async_using_multipan_no_otbr(hass: HomeAssistant) -> None: """Test async_change_channel when otbr is not configured.""" assert await otbr_silabs_multiprotocol.async_using_multipan(hass) is False + + +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO_OTHER_UUID]) +async def test_async_using_multipan_non_matching_uuid( + hass: HomeAssistant, otbr_config_entry_multipan +) -> None: + """Test async_change_channel when otbr is not configured.""" + assert await otbr_silabs_multiprotocol.async_using_multipan(hass) is False diff --git a/tests/components/zwave_js/test_config_flow.py b/tests/components/zwave_js/test_config_flow.py index 46172f72b2ff5f..59556c3322d4b1 100644 --- a/tests/components/zwave_js/test_config_flow.py +++ b/tests/components/zwave_js/test_config_flow.py @@ -25,9 +25,12 @@ from tests.common import MockConfigEntry ADDON_DISCOVERY_INFO = { - "addon": "Z-Wave JS", - "host": "host1", - "port": 3001, + "config": { + "addon": "Z-Wave JS", + "host": "host1", + "port": 3001, + }, + "uuid": "1234", } @@ -335,7 +338,7 @@ async def test_manual_already_configured(hass: HomeAssistant) -> None: assert entry.data["integration_created_addon"] is False -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_supervisor_discovery( hass: HomeAssistant, supervisor, @@ -357,7 +360,7 @@ async def test_supervisor_discovery( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -396,7 +399,7 @@ async def test_supervisor_discovery( @pytest.mark.parametrize( ("discovery_info", "server_version_side_effect"), - [({"config": ADDON_DISCOVERY_INFO}, TimeoutError())], + [(ADDON_DISCOVERY_INFO, TimeoutError())], ) async def test_supervisor_discovery_cannot_connect( hass: HomeAssistant, supervisor, get_addon_discovery_info @@ -407,7 +410,7 @@ async def test_supervisor_discovery_cannot_connect( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -418,7 +421,7 @@ async def test_supervisor_discovery_cannot_connect( assert result["reason"] == "cannot_connect" -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_clean_discovery_on_user_create( hass: HomeAssistant, supervisor, @@ -440,7 +443,7 @@ async def test_clean_discovery_on_user_create( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -516,7 +519,7 @@ async def test_abort_discovery_with_existing_entry( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -545,7 +548,7 @@ async def test_abort_hassio_discovery_with_existing_flow( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -579,7 +582,7 @@ async def test_abort_hassio_discovery_for_other_addon( assert result2["reason"] == "not_zwave_js_addon" -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_usb_discovery( hass: HomeAssistant, supervisor, @@ -678,7 +681,7 @@ async def test_usb_discovery( assert len(mock_setup_entry.mock_calls) == 1 -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_usb_discovery_addon_not_running( hass: HomeAssistant, supervisor, @@ -794,7 +797,7 @@ async def test_discovery_addon_not_running( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -888,7 +891,7 @@ async def test_discovery_addon_not_installed( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -985,7 +988,7 @@ async def test_abort_usb_discovery_with_existing_flow( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO, + config=ADDON_DISCOVERY_INFO["config"], name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -1118,7 +1121,7 @@ async def test_not_addon(hass: HomeAssistant, supervisor) -> None: assert len(mock_setup_entry.mock_calls) == 1 -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_addon_running( hass: HomeAssistant, supervisor, @@ -1184,14 +1187,14 @@ async def test_addon_running( ), [ ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, HassioAPIError(), None, None, "addon_get_discovery_info_failed", ), ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, None, TimeoutError, None, @@ -1205,7 +1208,7 @@ async def test_addon_running( "addon_get_discovery_info_failed", ), ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, None, None, HassioAPIError(), @@ -1240,7 +1243,7 @@ async def test_addon_running_failures( assert result["reason"] == abort_reason -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_addon_running_already_configured( hass: HomeAssistant, supervisor, @@ -1299,7 +1302,7 @@ async def test_addon_running_already_configured( assert entry.data["lr_s2_authenticated_key"] == "new321" -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_addon_installed( hass: HomeAssistant, supervisor, @@ -1392,7 +1395,7 @@ async def test_addon_installed( @pytest.mark.parametrize( ("discovery_info", "start_addon_side_effect"), - [({"config": ADDON_DISCOVERY_INFO}, HassioAPIError())], + [(ADDON_DISCOVERY_INFO, HassioAPIError())], ) async def test_addon_installed_start_failure( hass: HomeAssistant, @@ -1464,7 +1467,7 @@ async def test_addon_installed_start_failure( ("discovery_info", "server_version_side_effect"), [ ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, TimeoutError, ), ( @@ -1541,7 +1544,7 @@ async def test_addon_installed_failures( @pytest.mark.parametrize( ("set_addon_options_side_effect", "discovery_info"), - [(HassioAPIError(), {"config": ADDON_DISCOVERY_INFO})], + [(HassioAPIError(), ADDON_DISCOVERY_INFO)], ) async def test_addon_installed_set_options_failure( hass: HomeAssistant, @@ -1603,7 +1606,7 @@ async def test_addon_installed_set_options_failure( assert start_addon.call_count == 0 -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_addon_installed_already_configured( hass: HomeAssistant, supervisor, @@ -1695,7 +1698,7 @@ async def test_addon_installed_already_configured( assert entry.data["lr_s2_authenticated_key"] == "new321" -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_addon_not_installed( hass: HomeAssistant, supervisor, @@ -1921,7 +1924,7 @@ async def test_options_not_addon( ), [ ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, {}, { "device": "/test", @@ -1947,7 +1950,7 @@ async def test_options_not_addon( 0, ), ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, {"use_addon": True}, { "device": "/test", @@ -2068,7 +2071,7 @@ async def test_options_addon_running( ("discovery_info", "entry_data", "old_addon_options", "new_addon_options"), [ ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, {}, { "device": "/test", @@ -2195,7 +2198,7 @@ async def different_device_server_version(*args): ), [ ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, {}, { "device": "/test", @@ -2224,7 +2227,7 @@ async def different_device_server_version(*args): different_device_server_version, ), ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, {}, { "device": "/test", @@ -2357,7 +2360,7 @@ async def test_options_different_device( ), [ ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, {}, { "device": "/test", @@ -2386,7 +2389,7 @@ async def test_options_different_device( [HassioAPIError(), None], ), ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, {}, { "device": "/test", @@ -2520,7 +2523,7 @@ async def test_options_addon_restart_failed( ), [ ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, {}, { "device": "/test", @@ -2613,7 +2616,7 @@ async def test_options_addon_running_server_info_failure( ), [ ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, {}, { "device": "/test", @@ -2639,7 +2642,7 @@ async def test_options_addon_running_server_info_failure( 0, ), ( - {"config": ADDON_DISCOVERY_INFO}, + ADDON_DISCOVERY_INFO, {"use_addon": True}, { "device": "/test", @@ -2751,7 +2754,7 @@ async def test_options_addon_not_installed( assert client.disconnect.call_count == 1 -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_import_addon_installed( hass: HomeAssistant, supervisor, From 80cedf50ae18119b072f1da23301c5b146d94092 Mon Sep 17 00:00:00 2001 From: Erik Date: Mon, 19 Aug 2024 15:57:04 +0200 Subject: [PATCH 2/2] Simplify --- .../components/hassio/addon_manager.py | 16 +--- .../components/matter/config_flow.py | 4 +- homeassistant/components/otbr/__init__.py | 4 +- .../components/otbr/silabs_multiprotocol.py | 12 +-- homeassistant/components/otbr/util.py | 2 - .../components/zwave_js/config_flow.py | 4 +- tests/components/hassio/test_addon_manager.py | 10 +-- tests/components/matter/test_config_flow.py | 69 ++++++++-------- tests/components/otbr/conftest.py | 3 - .../otbr/test_silabs_multiprotocol.py | 62 +++------------ tests/components/zwave_js/test_config_flow.py | 79 +++++++++---------- 11 files changed, 93 insertions(+), 172 deletions(-) diff --git a/homeassistant/components/hassio/addon_manager.py b/homeassistant/components/hassio/addon_manager.py index 4a43574e035846..b3c43f16be1b14 100644 --- a/homeassistant/components/hassio/addon_manager.py +++ b/homeassistant/components/hassio/addon_manager.py @@ -65,14 +65,6 @@ async def wrapper( return handle_hassio_api_error -@dataclass -class AddonDiscoveryInfo: - """Represent the add-on discovery info.""" - - config: dict - uuid: str - - @dataclass class AddonInfo: """Represent the current add-on info state.""" @@ -133,7 +125,7 @@ def task_in_progress(self) -> bool: ) @api_error("Failed to get the {addon_name} add-on discovery info") - async def async_get_addon_discovery_info(self) -> AddonDiscoveryInfo: + async def async_get_addon_discovery_info(self) -> dict: """Return add-on discovery info.""" discovery_info = await async_get_addon_discovery_info( self._hass, self.addon_slug @@ -142,10 +134,8 @@ async def async_get_addon_discovery_info(self) -> AddonDiscoveryInfo: if not discovery_info: raise AddonError(f"Failed to get {self.addon_name} add-on discovery info") - return AddonDiscoveryInfo( - config=discovery_info["config"], - uuid=discovery_info["uuid"], - ) + discovery_info_config: dict = discovery_info["config"] + return discovery_info_config @api_error("Failed to get the {addon_name} add-on info") async def async_get_addon_info(self) -> AddonInfo: diff --git a/homeassistant/components/matter/config_flow.py b/homeassistant/components/matter/config_flow.py index 5620c26d3e49e8..ae71b7a17116f4 100644 --- a/homeassistant/components/matter/config_flow.py +++ b/homeassistant/components/matter/config_flow.py @@ -119,12 +119,12 @@ async def _async_get_addon_discovery_info(self) -> dict: """Return add-on discovery info.""" addon_manager: AddonManager = get_addon_manager(self.hass) try: - discovery_info = await addon_manager.async_get_addon_discovery_info() + discovery_info_config = await addon_manager.async_get_addon_discovery_info() except AddonError as err: LOGGER.error(err) raise AbortFlow("addon_get_discovery_info_failed") from err - return discovery_info.config + return discovery_info_config async def async_step_start_addon( self, user_input: dict[str, Any] | None = None diff --git a/homeassistant/components/otbr/__init__.py b/homeassistant/components/otbr/__init__.py index b411612f77868d..97c2f40eb9997e 100644 --- a/homeassistant/components/otbr/__init__.py +++ b/homeassistant/components/otbr/__init__.py @@ -33,9 +33,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up an Open Thread Border Router config entry.""" api = python_otbr_api.OTBR(entry.data["url"], async_get_clientsession(hass), 10) - otbrdata = OTBRData( - entry.data["url"], api, entry.entry_id, entry.source, entry.unique_id or DOMAIN - ) + otbrdata = OTBRData(entry.data["url"], api, entry.entry_id) try: border_agent_id = await otbrdata.get_border_agent_id() dataset_tlvs = await otbrdata.get_active_dataset_tlvs() diff --git a/homeassistant/components/otbr/silabs_multiprotocol.py b/homeassistant/components/otbr/silabs_multiprotocol.py index e97ef91390ca19..411da0a9361657 100644 --- a/homeassistant/components/otbr/silabs_multiprotocol.py +++ b/homeassistant/components/otbr/silabs_multiprotocol.py @@ -12,11 +12,9 @@ from python_otbr_api.tlv_parser import MeshcopTLVType from homeassistant.components.homeassistant_hardware.silabs_multiprotocol_addon import ( - get_multiprotocol_addon_manager, is_multiprotocol_url, ) from homeassistant.components.thread import async_add_dataset -from homeassistant.config_entries import SOURCE_HASSIO from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError @@ -50,15 +48,9 @@ async def async_get_otbr_data_wrapper( if DOMAIN not in hass.data: return retval - multipan_manager = await get_multiprotocol_addon_manager(hass) - discovery_info = await multipan_manager.async_get_addon_discovery_info() - data: OTBRData = hass.data[DOMAIN] - if ( - data.entry_source != SOURCE_HASSIO - or data.entry_unique_id != discovery_info.uuid - ): + if not is_multiprotocol_url(data.url): return retval return await orig_func(hass, data, *args, **kwargs) @@ -125,4 +117,4 @@ async def async_using_multipan(hass: HomeAssistant, data: OTBRData) -> bool: Returns False if not configured. """ - return is_multiprotocol_url(data.url) + return True diff --git a/homeassistant/components/otbr/util.py b/homeassistant/components/otbr/util.py index 7fbd9117455c91..16cf3b60e37382 100644 --- a/homeassistant/components/otbr/util.py +++ b/homeassistant/components/otbr/util.py @@ -80,8 +80,6 @@ class OTBRData: url: str api: python_otbr_api.OTBR entry_id: str - entry_source: str - entry_unique_id: str @_handle_otbr_error async def factory_reset(self) -> None: diff --git a/homeassistant/components/zwave_js/config_flow.py b/homeassistant/components/zwave_js/config_flow.py index fed9a113e0fd28..e73fa9fc3a799c 100644 --- a/homeassistant/components/zwave_js/config_flow.py +++ b/homeassistant/components/zwave_js/config_flow.py @@ -333,12 +333,12 @@ async def _async_get_addon_discovery_info(self) -> dict: """Return add-on discovery info.""" addon_manager: AddonManager = get_addon_manager(self.hass) try: - discovery_info = await addon_manager.async_get_addon_discovery_info() + discovery_info_config = await addon_manager.async_get_addon_discovery_info() except AddonError as err: _LOGGER.error(err) raise AbortFlow("addon_get_discovery_info_failed") from err - return discovery_info.config + return discovery_info_config class ZWaveJSConfigFlow(BaseZwaveJSFlow, ConfigFlow, domain=DOMAIN): diff --git a/tests/components/hassio/test_addon_manager.py b/tests/components/hassio/test_addon_manager.py index 1165c2406e637e..6a20c6eec885e5 100644 --- a/tests/components/hassio/test_addon_manager.py +++ b/tests/components/hassio/test_addon_manager.py @@ -11,7 +11,6 @@ import pytest from homeassistant.components.hassio.addon_manager import ( - AddonDiscoveryInfo, AddonError, AddonInfo, AddonManager, @@ -211,14 +210,9 @@ async def test_get_addon_discovery_info( addon_manager: AddonManager, get_addon_discovery_info: AsyncMock ) -> None: """Test get addon discovery info.""" - get_addon_discovery_info.return_value = { - "config": {"test_key": "test"}, - "uuid": "1234", - } + get_addon_discovery_info.return_value = {"config": {"test_key": "test"}} - assert await addon_manager.async_get_addon_discovery_info() == AddonDiscoveryInfo( - config={"test_key": "test"}, uuid="1234" - ) + assert await addon_manager.async_get_addon_discovery_info() == {"test_key": "test"} assert get_addon_discovery_info.call_count == 1 diff --git a/tests/components/matter/test_config_flow.py b/tests/components/matter/test_config_flow.py index d88c20e2390f23..642bfe0f804288 100644 --- a/tests/components/matter/test_config_flow.py +++ b/tests/components/matter/test_config_flow.py @@ -20,12 +20,9 @@ from tests.common import MockConfigEntry ADDON_DISCOVERY_INFO = { - "config": { - "addon": "Matter Server", - "host": "host1", - "port": 5581, - }, - "uuid": "1234", + "addon": "Matter Server", + "host": "host1", + "port": 5581, } ZEROCONF_INFO_TCP = ZeroconfServiceInfo( ip_address=ip_address("fd11:be53:8d46:0:729e:5a4f:539d:1ee6"), @@ -304,7 +301,7 @@ async def test_zeroconf_discovery_not_onboarded_not_supervisor( @pytest.mark.parametrize("zeroconf_info", [ZEROCONF_INFO_TCP, ZEROCONF_INFO_UDP]) -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_zeroconf_not_onboarded_already_discovered( hass: HomeAssistant, supervisor: MagicMock, @@ -342,7 +339,7 @@ async def test_zeroconf_not_onboarded_already_discovered( @pytest.mark.parametrize("zeroconf_info", [ZEROCONF_INFO_TCP, ZEROCONF_INFO_UDP]) -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_zeroconf_not_onboarded_running( hass: HomeAssistant, supervisor: MagicMock, @@ -374,7 +371,7 @@ async def test_zeroconf_not_onboarded_running( @pytest.mark.parametrize("zeroconf_info", [ZEROCONF_INFO_TCP, ZEROCONF_INFO_UDP]) -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_zeroconf_not_onboarded_installed( hass: HomeAssistant, supervisor: MagicMock, @@ -408,7 +405,7 @@ async def test_zeroconf_not_onboarded_installed( @pytest.mark.parametrize("zeroconf_info", [ZEROCONF_INFO_TCP, ZEROCONF_INFO_UDP]) -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_zeroconf_not_onboarded_not_installed( hass: HomeAssistant, supervisor: MagicMock, @@ -445,7 +442,7 @@ async def test_zeroconf_not_onboarded_not_installed( assert setup_entry.call_count == 1 -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_supervisor_discovery( hass: HomeAssistant, supervisor: MagicMock, @@ -459,7 +456,7 @@ async def test_supervisor_discovery( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -483,7 +480,7 @@ async def test_supervisor_discovery( @pytest.mark.parametrize( ("discovery_info", "error"), - [(ADDON_DISCOVERY_INFO, HassioAPIError())], + [({"config": ADDON_DISCOVERY_INFO}, HassioAPIError())], ) async def test_supervisor_discovery_addon_info_failed( hass: HomeAssistant, @@ -499,7 +496,7 @@ async def test_supervisor_discovery_addon_info_failed( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -516,7 +513,7 @@ async def test_supervisor_discovery_addon_info_failed( assert result["reason"] == "addon_info_failed" -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_clean_supervisor_discovery_on_user_create( hass: HomeAssistant, supervisor: MagicMock, @@ -530,7 +527,7 @@ async def test_clean_supervisor_discovery_on_user_create( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -593,7 +590,7 @@ async def test_abort_supervisor_discovery_with_existing_entry( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -623,7 +620,7 @@ async def test_abort_supervisor_discovery_with_existing_flow( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -676,7 +673,7 @@ async def test_supervisor_discovery_addon_not_running( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -725,7 +722,7 @@ async def test_supervisor_discovery_addon_not_installed( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, uuid="1234", @@ -807,7 +804,7 @@ async def test_not_addon( assert setup_entry.call_count == 1 -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_addon_running( hass: HomeAssistant, supervisor: MagicMock, @@ -853,7 +850,7 @@ async def test_addon_running( ), [ ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, HassioAPIError(), None, None, @@ -862,7 +859,7 @@ async def test_addon_running( False, ), ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, None, CannotConnect(Exception("Boom")), None, @@ -880,7 +877,7 @@ async def test_addon_running( False, ), ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, None, None, HassioAPIError(), @@ -939,7 +936,7 @@ async def test_addon_running_failures( ), [ ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, HassioAPIError(), None, None, @@ -948,7 +945,7 @@ async def test_addon_running_failures( False, ), ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, None, CannotConnect(Exception("Boom")), None, @@ -966,7 +963,7 @@ async def test_addon_running_failures( False, ), ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, None, None, HassioAPIError(), @@ -1010,7 +1007,7 @@ async def test_addon_running_failures_zeroconf( assert result["reason"] == abort_reason -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_addon_running_already_configured( hass: HomeAssistant, supervisor: MagicMock, @@ -1048,7 +1045,7 @@ async def test_addon_running_already_configured( assert setup_entry.call_count == 1 -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_addon_installed( hass: HomeAssistant, supervisor: MagicMock, @@ -1098,14 +1095,14 @@ async def test_addon_installed( ), [ ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, HassioAPIError(), None, False, False, ), ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, None, CannotConnect(Exception("Boom")), True, @@ -1173,14 +1170,14 @@ async def test_addon_installed_failures( ), [ ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, HassioAPIError(), None, False, False, ), ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, None, CannotConnect(Exception("Boom")), True, @@ -1227,7 +1224,7 @@ async def test_addon_installed_failures_zeroconf( assert result["reason"] == "addon_start_failed" -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_addon_installed_already_configured( hass: HomeAssistant, supervisor: MagicMock, @@ -1273,7 +1270,7 @@ async def test_addon_installed_already_configured( assert setup_entry.call_count == 1 -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_addon_not_installed( hass: HomeAssistant, supervisor: MagicMock, @@ -1382,7 +1379,7 @@ async def test_addon_not_installed_failures_zeroconf( assert result["reason"] == "addon_install_failed" -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_addon_not_installed_already_configured( hass: HomeAssistant, supervisor: MagicMock, diff --git a/tests/components/otbr/conftest.py b/tests/components/otbr/conftest.py index 794828ee1eefb4..56f29bdc79b4dd 100644 --- a/tests/components/otbr/conftest.py +++ b/tests/components/otbr/conftest.py @@ -5,7 +5,6 @@ import pytest from homeassistant.components import otbr -from homeassistant.config_entries import SOURCE_HASSIO from homeassistant.core import HomeAssistant from . import ( @@ -26,9 +25,7 @@ async def otbr_config_entry_multipan_fixture(hass: HomeAssistant) -> None: data=CONFIG_ENTRY_DATA_MULTIPAN, domain=otbr.DOMAIN, options={}, - source=SOURCE_HASSIO, title="Open Thread Border Router", - unique_id="1234", ) config_entry.add_to_hass(hass) with ( diff --git a/tests/components/otbr/test_silabs_multiprotocol.py b/tests/components/otbr/test_silabs_multiprotocol.py index 8b472f6dff74ae..d5a6e15e9530bb 100644 --- a/tests/components/otbr/test_silabs_multiprotocol.py +++ b/tests/components/otbr/test_silabs_multiprotocol.py @@ -1,8 +1,6 @@ """Test OTBR Silicon Labs Multiprotocol support.""" -from collections.abc import Generator -from typing import Any -from unittest.mock import DEFAULT, AsyncMock, patch +from unittest.mock import patch import pytest from python_otbr_api import ActiveDataSet, tlv_parser @@ -34,43 +32,6 @@ ) -ADDON_DISCOVERY_INFO = { - "config": { - "addon": "Silicon Labs Multiprotocol", - "host": "core-silabs-multiprotocol", - "port": 8081, - }, - "uuid": "1234", -} - - -ADDON_DISCOVERY_INFO_OTHER_UUID = { - "config": { - "addon": "Silicon Labs Multiprotocol", - "host": "core-silabs-multiprotocol", - "port": 8081, - }, - "uuid": "4321", -} - - -@pytest.fixture(name="discovery_info") -def discovery_info_fixture() -> Any: - """Return the discovery info from the supervisor.""" - return DEFAULT - - -@pytest.fixture(name="get_addon_discovery_info", autouse=True) -def get_addon_discovery_info_fixture(discovery_info: Any) -> Generator[AsyncMock]: - """Mock get add-on discovery info.""" - with patch( - "homeassistant.components.hassio.addon_manager.async_get_addon_discovery_info", - return_value=discovery_info, - ) as get_addon_discovery_info: - yield get_addon_discovery_info - - -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_change_channel( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: @@ -99,7 +60,6 @@ async def test_async_change_channel( ) -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_change_channel_no_pending( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: @@ -132,7 +92,6 @@ async def test_async_change_channel_no_pending( ) -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_change_channel_no_update( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: @@ -167,17 +126,17 @@ async def test_async_change_channel_no_otbr(hass: HomeAssistant) -> None: mock_set_channel.assert_not_awaited() -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO_OTHER_UUID]) -async def test_async_change_channel_non_matching_uuid( +async def test_async_change_channel_non_matching_url( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: """Test async_change_channel when otbr is not configured.""" + data: otbr.OTBRData = hass.data[otbr.DOMAIN] + data.url = OTBR_NON_MULTIPAN_URL with patch("python_otbr_api.OTBR.set_channel") as mock_set_channel: await otbr_silabs_multiprotocol.async_change_channel(hass, 16, delay=0) mock_set_channel.assert_not_awaited() -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_get_channel( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: @@ -191,7 +150,6 @@ async def test_async_get_channel( mock_get_active_dataset.assert_awaited_once_with() -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_get_channel_no_dataset( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: @@ -205,7 +163,6 @@ async def test_async_get_channel_no_dataset( mock_get_active_dataset.assert_awaited_once_with() -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_get_channel_error( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: @@ -227,11 +184,12 @@ async def test_async_get_channel_no_otbr(hass: HomeAssistant) -> None: mock_get_active_dataset.assert_not_awaited() -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO_OTHER_UUID]) -async def test_async_get_channel_non_matching_uuid( +async def test_async_get_channel_non_matching_url( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: """Test async_change_channel when otbr is not configured.""" + data: otbr.OTBRData = hass.data[otbr.DOMAIN] + data.url = OTBR_NON_MULTIPAN_URL with patch("python_otbr_api.OTBR.get_active_dataset") as mock_get_active_dataset: assert await otbr_silabs_multiprotocol.async_get_channel(hass) is None mock_get_active_dataset.assert_not_awaited() @@ -241,7 +199,6 @@ async def test_async_get_channel_non_matching_uuid( ("url", "expected"), [(OTBR_MULTIPAN_URL, True), (OTBR_NON_MULTIPAN_URL, False)], ) -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) async def test_async_using_multipan( hass: HomeAssistant, otbr_config_entry_multipan, url: str, expected: bool ) -> None: @@ -258,9 +215,10 @@ async def test_async_using_multipan_no_otbr(hass: HomeAssistant) -> None: assert await otbr_silabs_multiprotocol.async_using_multipan(hass) is False -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO_OTHER_UUID]) -async def test_async_using_multipan_non_matching_uuid( +async def test_async_using_multipan_non_matching_url( hass: HomeAssistant, otbr_config_entry_multipan ) -> None: """Test async_change_channel when otbr is not configured.""" + data: otbr.OTBRData = hass.data[otbr.DOMAIN] + data.url = OTBR_NON_MULTIPAN_URL assert await otbr_silabs_multiprotocol.async_using_multipan(hass) is False diff --git a/tests/components/zwave_js/test_config_flow.py b/tests/components/zwave_js/test_config_flow.py index 59556c3322d4b1..46172f72b2ff5f 100644 --- a/tests/components/zwave_js/test_config_flow.py +++ b/tests/components/zwave_js/test_config_flow.py @@ -25,12 +25,9 @@ from tests.common import MockConfigEntry ADDON_DISCOVERY_INFO = { - "config": { - "addon": "Z-Wave JS", - "host": "host1", - "port": 3001, - }, - "uuid": "1234", + "addon": "Z-Wave JS", + "host": "host1", + "port": 3001, } @@ -338,7 +335,7 @@ async def test_manual_already_configured(hass: HomeAssistant) -> None: assert entry.data["integration_created_addon"] is False -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_supervisor_discovery( hass: HomeAssistant, supervisor, @@ -360,7 +357,7 @@ async def test_supervisor_discovery( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -399,7 +396,7 @@ async def test_supervisor_discovery( @pytest.mark.parametrize( ("discovery_info", "server_version_side_effect"), - [(ADDON_DISCOVERY_INFO, TimeoutError())], + [({"config": ADDON_DISCOVERY_INFO}, TimeoutError())], ) async def test_supervisor_discovery_cannot_connect( hass: HomeAssistant, supervisor, get_addon_discovery_info @@ -410,7 +407,7 @@ async def test_supervisor_discovery_cannot_connect( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -421,7 +418,7 @@ async def test_supervisor_discovery_cannot_connect( assert result["reason"] == "cannot_connect" -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_clean_discovery_on_user_create( hass: HomeAssistant, supervisor, @@ -443,7 +440,7 @@ async def test_clean_discovery_on_user_create( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -519,7 +516,7 @@ async def test_abort_discovery_with_existing_entry( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -548,7 +545,7 @@ async def test_abort_hassio_discovery_with_existing_flow( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -582,7 +579,7 @@ async def test_abort_hassio_discovery_for_other_addon( assert result2["reason"] == "not_zwave_js_addon" -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_usb_discovery( hass: HomeAssistant, supervisor, @@ -681,7 +678,7 @@ async def test_usb_discovery( assert len(mock_setup_entry.mock_calls) == 1 -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_usb_discovery_addon_not_running( hass: HomeAssistant, supervisor, @@ -797,7 +794,7 @@ async def test_discovery_addon_not_running( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -891,7 +888,7 @@ async def test_discovery_addon_not_installed( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -988,7 +985,7 @@ async def test_abort_usb_discovery_with_existing_flow( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, data=HassioServiceInfo( - config=ADDON_DISCOVERY_INFO["config"], + config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, uuid="1234", @@ -1121,7 +1118,7 @@ async def test_not_addon(hass: HomeAssistant, supervisor) -> None: assert len(mock_setup_entry.mock_calls) == 1 -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_addon_running( hass: HomeAssistant, supervisor, @@ -1187,14 +1184,14 @@ async def test_addon_running( ), [ ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, HassioAPIError(), None, None, "addon_get_discovery_info_failed", ), ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, None, TimeoutError, None, @@ -1208,7 +1205,7 @@ async def test_addon_running( "addon_get_discovery_info_failed", ), ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, None, None, HassioAPIError(), @@ -1243,7 +1240,7 @@ async def test_addon_running_failures( assert result["reason"] == abort_reason -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_addon_running_already_configured( hass: HomeAssistant, supervisor, @@ -1302,7 +1299,7 @@ async def test_addon_running_already_configured( assert entry.data["lr_s2_authenticated_key"] == "new321" -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_addon_installed( hass: HomeAssistant, supervisor, @@ -1395,7 +1392,7 @@ async def test_addon_installed( @pytest.mark.parametrize( ("discovery_info", "start_addon_side_effect"), - [(ADDON_DISCOVERY_INFO, HassioAPIError())], + [({"config": ADDON_DISCOVERY_INFO}, HassioAPIError())], ) async def test_addon_installed_start_failure( hass: HomeAssistant, @@ -1467,7 +1464,7 @@ async def test_addon_installed_start_failure( ("discovery_info", "server_version_side_effect"), [ ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, TimeoutError, ), ( @@ -1544,7 +1541,7 @@ async def test_addon_installed_failures( @pytest.mark.parametrize( ("set_addon_options_side_effect", "discovery_info"), - [(HassioAPIError(), ADDON_DISCOVERY_INFO)], + [(HassioAPIError(), {"config": ADDON_DISCOVERY_INFO})], ) async def test_addon_installed_set_options_failure( hass: HomeAssistant, @@ -1606,7 +1603,7 @@ async def test_addon_installed_set_options_failure( assert start_addon.call_count == 0 -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_addon_installed_already_configured( hass: HomeAssistant, supervisor, @@ -1698,7 +1695,7 @@ async def test_addon_installed_already_configured( assert entry.data["lr_s2_authenticated_key"] == "new321" -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_addon_not_installed( hass: HomeAssistant, supervisor, @@ -1924,7 +1921,7 @@ async def test_options_not_addon( ), [ ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, {}, { "device": "/test", @@ -1950,7 +1947,7 @@ async def test_options_not_addon( 0, ), ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, {"use_addon": True}, { "device": "/test", @@ -2071,7 +2068,7 @@ async def test_options_addon_running( ("discovery_info", "entry_data", "old_addon_options", "new_addon_options"), [ ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, {}, { "device": "/test", @@ -2198,7 +2195,7 @@ async def different_device_server_version(*args): ), [ ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, {}, { "device": "/test", @@ -2227,7 +2224,7 @@ async def different_device_server_version(*args): different_device_server_version, ), ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, {}, { "device": "/test", @@ -2360,7 +2357,7 @@ async def test_options_different_device( ), [ ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, {}, { "device": "/test", @@ -2389,7 +2386,7 @@ async def test_options_different_device( [HassioAPIError(), None], ), ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, {}, { "device": "/test", @@ -2523,7 +2520,7 @@ async def test_options_addon_restart_failed( ), [ ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, {}, { "device": "/test", @@ -2616,7 +2613,7 @@ async def test_options_addon_running_server_info_failure( ), [ ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, {}, { "device": "/test", @@ -2642,7 +2639,7 @@ async def test_options_addon_running_server_info_failure( 0, ), ( - ADDON_DISCOVERY_INFO, + {"config": ADDON_DISCOVERY_INFO}, {"use_addon": True}, { "device": "/test", @@ -2754,7 +2751,7 @@ async def test_options_addon_not_installed( assert client.disconnect.call_count == 1 -@pytest.mark.parametrize("discovery_info", [ADDON_DISCOVERY_INFO]) +@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_import_addon_installed( hass: HomeAssistant, supervisor,