diff --git a/homeassistant/components/hassio/discovery.py b/homeassistant/components/hassio/discovery.py index 48fd005fc32..2a5ce2485d1 100644 --- a/homeassistant/components/hassio/discovery.py +++ b/homeassistant/components/hassio/discovery.py @@ -29,6 +29,7 @@ class HassioServiceInfo(BaseServiceInfo): config: dict[str, Any] name: str slug: str + uuid: str @callback @@ -93,6 +94,7 @@ class HassIODiscovery(HomeAssistantView): service: str = data[ATTR_SERVICE] config_data: dict[str, Any] = data[ATTR_CONFIG] slug: str = data[ATTR_ADDON] + uuid: str = data[ATTR_UUID] # Read additional Add-on info try: @@ -109,7 +111,7 @@ class HassIODiscovery(HomeAssistantView): self.hass, service, context={"source": config_entries.SOURCE_HASSIO}, - data=HassioServiceInfo(config=config_data, name=name, slug=slug), + data=HassioServiceInfo(config=config_data, name=name, slug=slug, uuid=uuid), ) async def async_process_del(self, data): @@ -128,6 +130,6 @@ class HassIODiscovery(HomeAssistantView): # Use config flow for entry in self.hass.config_entries.async_entries(service): - if entry.source != config_entries.SOURCE_HASSIO: + if entry.source != config_entries.SOURCE_HASSIO or entry.unique_id != uuid: continue await self.hass.config_entries.async_remove(entry.entry_id) diff --git a/homeassistant/components/otbr/config_flow.py b/homeassistant/components/otbr/config_flow.py index 434b9026ae2..32842ad6cc7 100644 --- a/homeassistant/components/otbr/config_flow.py +++ b/homeassistant/components/otbr/config_flow.py @@ -98,6 +98,10 @@ class OTBRConfigFlow(ConfigFlow, domain=DOMAIN): for current_entry in current_entries: if current_entry.source != SOURCE_HASSIO: continue + if current_entry.unique_id != discovery_info.uuid: + self.hass.config_entries.async_update_entry( + current_entry, unique_id=discovery_info.uuid + ) current_url = yarl.URL(current_entry.data["url"]) if ( current_url.host != config["host"] @@ -116,7 +120,7 @@ class OTBRConfigFlow(ConfigFlow, domain=DOMAIN): _LOGGER.warning("Failed to communicate with OTBR@%s: %s", url, exc) return self.async_abort(reason="unknown") - await self.async_set_unique_id(DOMAIN) + await self.async_set_unique_id(discovery_info.uuid) return self.async_create_entry( title="Open Thread Border Router", data=config_entry_data, diff --git a/tests/components/adguard/test_config_flow.py b/tests/components/adguard/test_config_flow.py index 54f1d2d86af..f62172ebfad 100644 --- a/tests/components/adguard/test_config_flow.py +++ b/tests/components/adguard/test_config_flow.py @@ -134,6 +134,7 @@ async def test_hassio_already_configured(hass: HomeAssistant) -> None: }, name="AdGuard Home Addon", slug="adguard", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) @@ -158,6 +159,7 @@ async def test_hassio_ignored(hass: HomeAssistant) -> None: }, name="AdGuard Home Addon", slug="adguard", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) @@ -186,6 +188,7 @@ async def test_hassio_confirm( }, name="AdGuard Home Addon", slug="adguard", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) @@ -228,6 +231,7 @@ async def test_hassio_connection_error( }, name="AdGuard Home Addon", slug="adguard", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) diff --git a/tests/components/deconz/test_config_flow.py b/tests/components/deconz/test_config_flow.py index 769a5c16d07..d0c51e39987 100644 --- a/tests/components/deconz/test_config_flow.py +++ b/tests/components/deconz/test_config_flow.py @@ -576,6 +576,7 @@ async def test_flow_hassio_discovery(hass: HomeAssistant) -> None: }, name="Mock Addon", slug="deconz", + uuid="1234", ), context={"source": SOURCE_HASSIO}, ) @@ -628,6 +629,7 @@ async def test_hassio_discovery_update_configuration( }, name="Mock Addon", slug="deconz", + uuid="1234", ), context={"source": SOURCE_HASSIO}, ) @@ -658,6 +660,7 @@ async def test_hassio_discovery_dont_update_configuration( }, name="Mock Addon", slug="deconz", + uuid="1234", ), context={"source": SOURCE_HASSIO}, ) diff --git a/tests/components/esphome/test_config_flow.py b/tests/components/esphome/test_config_flow.py index f96ecc8327f..7d901733d81 100644 --- a/tests/components/esphome/test_config_flow.py +++ b/tests/components/esphome/test_config_flow.py @@ -813,6 +813,7 @@ async def test_discovery_hassio(hass: HomeAssistant, mock_dashboard) -> None: }, name="ESPHome", slug="mock-slug", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) diff --git a/tests/components/hassio/test_discovery.py b/tests/components/hassio/test_discovery.py index 51659927dfa..5c4717fd561 100644 --- a/tests/components/hassio/test_discovery.py +++ b/tests/components/hassio/test_discovery.py @@ -89,6 +89,7 @@ async def test_hassio_discovery_startup( }, name="Mosquitto Test", slug="mosquitto", + uuid="test", ) ) @@ -153,6 +154,7 @@ async def test_hassio_discovery_startup_done( }, name="Mosquitto Test", slug="mosquitto", + uuid="test", ) ) @@ -207,5 +209,6 @@ async def test_hassio_discovery_webhook( }, name="Mosquitto Test", slug="mosquitto", + uuid="test", ) ) diff --git a/tests/components/matter/test_config_flow.py b/tests/components/matter/test_config_flow.py index 9adafa5814b..eddf6506bfd 100644 --- a/tests/components/matter/test_config_flow.py +++ b/tests/components/matter/test_config_flow.py @@ -193,6 +193,7 @@ async def test_supervisor_discovery( config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, + uuid="1234", ), ) @@ -232,6 +233,7 @@ async def test_supervisor_discovery_addon_info_failed( config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, + uuid="1234", ), ) @@ -262,6 +264,7 @@ async def test_clean_supervisor_discovery_on_user_create( config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, + uuid="1234", ), ) @@ -324,6 +327,7 @@ async def test_abort_supervisor_discovery_with_existing_entry( config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, + uuid="1234", ), ) @@ -353,6 +357,7 @@ async def test_abort_supervisor_discovery_with_existing_flow( config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, + uuid="1234", ), ) @@ -379,6 +384,7 @@ async def test_abort_supervisor_discovery_for_other_addon( }, name="Other Matter Server", slug="other_addon", + uuid="1234", ), ) @@ -404,6 +410,7 @@ async def test_supervisor_discovery_addon_not_running( config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, + uuid="1234", ), ) @@ -452,6 +459,7 @@ async def test_supervisor_discovery_addon_not_installed( config=ADDON_DISCOVERY_INFO, name="Matter Server", slug=ADDON_SLUG, + uuid="1234", ), ) diff --git a/tests/components/motioneye/test_config_flow.py b/tests/components/motioneye/test_config_flow.py index a7bf537add6..5cb6244010e 100644 --- a/tests/components/motioneye/test_config_flow.py +++ b/tests/components/motioneye/test_config_flow.py @@ -79,6 +79,7 @@ async def test_hassio_success(hass: HomeAssistant) -> None: config={"addon": "motionEye", "url": TEST_URL}, name="motionEye", slug="motioneye", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) @@ -357,6 +358,7 @@ async def test_hassio_already_configured(hass: HomeAssistant) -> None: config={"addon": "motionEye", "url": TEST_URL}, name="motionEye", slug="motioneye", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) @@ -376,6 +378,7 @@ async def test_hassio_ignored(hass: HomeAssistant) -> None: config={"addon": "motionEye", "url": TEST_URL}, name="motionEye", slug="motioneye", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) @@ -396,6 +399,7 @@ async def test_hassio_abort_if_already_in_progress(hass: HomeAssistant) -> None: config={"addon": "motionEye", "url": TEST_URL}, name="motionEye", slug="motioneye", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) @@ -412,6 +416,7 @@ async def test_hassio_clean_up_on_user_flow(hass: HomeAssistant) -> None: config={"addon": "motionEye", "url": TEST_URL}, name="motionEye", slug="motioneye", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) diff --git a/tests/components/mqtt/test_config_flow.py b/tests/components/mqtt/test_config_flow.py index 78bd598436d..8f3846a7376 100644 --- a/tests/components/mqtt/test_config_flow.py +++ b/tests/components/mqtt/test_config_flow.py @@ -343,6 +343,7 @@ async def test_hassio_ignored(hass: HomeAssistant) -> None: }, name="Mosquitto", slug="mosquitto", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) @@ -373,6 +374,7 @@ async def test_hassio_confirm( }, name="Mock Addon", slug="mosquitto", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) @@ -421,6 +423,7 @@ async def test_hassio_cannot_connect( }, name="Mock Addon", slug="mosquitto", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) diff --git a/tests/components/otbr/test_config_flow.py b/tests/components/otbr/test_config_flow.py index b788c93610d..9fe30d709a7 100644 --- a/tests/components/otbr/test_config_flow.py +++ b/tests/components/otbr/test_config_flow.py @@ -21,6 +21,7 @@ HASSIO_DATA = hassio.HassioServiceInfo( config={"host": "core-silabs-multiprotocol", "port": 8081}, name="Silicon Labs Multiprotocol", slug="otbr", + uuid="12345", ) @@ -203,7 +204,7 @@ async def test_hassio_discovery_flow( assert config_entry.data == expected_data assert config_entry.options == {} assert config_entry.title == "Open Thread Border Router" - assert config_entry.unique_id == otbr.DOMAIN + assert config_entry.unique_id == HASSIO_DATA.uuid async def test_hassio_discovery_flow_router_not_setup( @@ -255,7 +256,7 @@ async def test_hassio_discovery_flow_router_not_setup( assert config_entry.data == expected_data assert config_entry.options == {} assert config_entry.title == "Open Thread Border Router" - assert config_entry.unique_id == otbr.DOMAIN + assert config_entry.unique_id == HASSIO_DATA.uuid async def test_hassio_discovery_flow_router_not_setup_has_preferred( @@ -304,7 +305,7 @@ async def test_hassio_discovery_flow_router_not_setup_has_preferred( assert config_entry.data == expected_data assert config_entry.options == {} assert config_entry.title == "Open Thread Border Router" - assert config_entry.unique_id == otbr.DOMAIN + assert config_entry.unique_id == HASSIO_DATA.uuid async def test_hassio_discovery_flow_router_not_setup_has_preferred_2( @@ -366,7 +367,7 @@ async def test_hassio_discovery_flow_router_not_setup_has_preferred_2( assert config_entry.data == expected_data assert config_entry.options == {} assert config_entry.title == "Open Thread Border Router" - assert config_entry.unique_id == otbr.DOMAIN + assert config_entry.unique_id == HASSIO_DATA.uuid async def test_hassio_discovery_flow_404( diff --git a/tests/components/rtsp_to_webrtc/test_config_flow.py b/tests/components/rtsp_to_webrtc/test_config_flow.py index 0cfd9ba5d5c..13885f06d3e 100644 --- a/tests/components/rtsp_to_webrtc/test_config_flow.py +++ b/tests/components/rtsp_to_webrtc/test_config_flow.py @@ -123,6 +123,7 @@ async def test_hassio_discovery(hass: HomeAssistant) -> None: }, name="RTSPtoWebRTC", slug="rtsp-to-webrtc", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) @@ -162,6 +163,7 @@ async def test_hassio_single_config_entry(hass: HomeAssistant) -> None: }, name="RTSPtoWebRTC", slug="rtsp-to-webrtc", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) @@ -184,6 +186,7 @@ async def test_hassio_ignored(hass: HomeAssistant) -> None: }, name="RTSPtoWebRTC", slug="rtsp-to-webrtc", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) @@ -203,6 +206,7 @@ async def test_hassio_discovery_server_failure(hass: HomeAssistant) -> None: }, name="RTSPtoWebRTC", slug="rtsp-to-webrtc", + uuid="1234", ), context={"source": config_entries.SOURCE_HASSIO}, ) diff --git a/tests/components/vlc_telnet/test_config_flow.py b/tests/components/vlc_telnet/test_config_flow.py index a9491d4d3b6..91ea5b3e439 100644 --- a/tests/components/vlc_telnet/test_config_flow.py +++ b/tests/components/vlc_telnet/test_config_flow.py @@ -250,6 +250,7 @@ async def test_hassio_flow(hass: HomeAssistant) -> None: }, name="VLC", slug="vlc", + uuid="1234", ) result = await hass.config_entries.flow.async_init( @@ -286,7 +287,7 @@ async def test_hassio_already_configured(hass: HomeAssistant) -> None: result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_HASSIO}, - data=HassioServiceInfo(config=entry_data, name="VLC", slug="vlc"), + data=HassioServiceInfo(config=entry_data, name="VLC", slug="vlc", uuid="1234"), ) await hass.async_block_till_done() @@ -330,6 +331,7 @@ async def test_hassio_errors( }, name="VLC", slug="vlc", + uuid="1234", ), ) await hass.async_block_till_done() diff --git a/tests/components/wyoming/test_config_flow.py b/tests/components/wyoming/test_config_flow.py index 54a5a2a8679..552215c1141 100644 --- a/tests/components/wyoming/test_config_flow.py +++ b/tests/components/wyoming/test_config_flow.py @@ -21,6 +21,7 @@ ADDON_DISCOVERY = HassioServiceInfo( }, name="Piper", slug="mock_piper", + uuid="1234", ) pytestmark = pytest.mark.usefixtures("mock_setup_entry") diff --git a/tests/components/zwave_js/test_config_flow.py b/tests/components/zwave_js/test_config_flow.py index 2b2c9bb4137..73dd82d5f4b 100644 --- a/tests/components/zwave_js/test_config_flow.py +++ b/tests/components/zwave_js/test_config_flow.py @@ -342,6 +342,7 @@ async def test_supervisor_discovery( config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, + uuid="1234", ), ) @@ -386,6 +387,7 @@ async def test_supervisor_discovery_cannot_connect( config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, + uuid="1234", ), ) @@ -416,6 +418,7 @@ async def test_clean_discovery_on_user_create( config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, + uuid="1234", ), ) @@ -486,6 +489,7 @@ async def test_abort_discovery_with_existing_entry( config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, + uuid="1234", ), ) @@ -514,6 +518,7 @@ async def test_abort_hassio_discovery_with_existing_flow( config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, + uuid="1234", ), ) @@ -536,6 +541,7 @@ async def test_abort_hassio_discovery_for_other_addon( }, name="Other Z-Wave JS", slug="other_addon", + uuid="1234", ), ) @@ -741,6 +747,7 @@ async def test_discovery_addon_not_running( config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, + uuid="1234", ), ) @@ -825,6 +832,7 @@ async def test_discovery_addon_not_installed( config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, + uuid="1234", ), ) @@ -912,6 +920,7 @@ async def test_abort_usb_discovery_with_existing_flow( config=ADDON_DISCOVERY_INFO, name="Z-Wave JS", slug=ADDON_SLUG, + uuid="1234", ), ) diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index ccfc60d7d97..53602ec28ff 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -2657,7 +2657,7 @@ async def test_async_setup_update_entry(hass: HomeAssistant) -> None: (config_entries.SOURCE_ZEROCONF, BaseServiceInfo()), ( config_entries.SOURCE_HASSIO, - HassioServiceInfo(config={}, name="Test", slug="test"), + HassioServiceInfo(config={}, name="Test", slug="test", uuid="1234"), ), ), )