Include UUID in hassio discovery data (#91970)

This commit is contained in:
Erik Montnemery 2023-04-25 09:48:47 +02:00 committed by GitHub
parent 0b0573c387
commit 63f3767a29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 59 additions and 9 deletions

View File

@ -29,6 +29,7 @@ class HassioServiceInfo(BaseServiceInfo):
config: dict[str, Any] config: dict[str, Any]
name: str name: str
slug: str slug: str
uuid: str
@callback @callback
@ -93,6 +94,7 @@ class HassIODiscovery(HomeAssistantView):
service: str = data[ATTR_SERVICE] service: str = data[ATTR_SERVICE]
config_data: dict[str, Any] = data[ATTR_CONFIG] config_data: dict[str, Any] = data[ATTR_CONFIG]
slug: str = data[ATTR_ADDON] slug: str = data[ATTR_ADDON]
uuid: str = data[ATTR_UUID]
# Read additional Add-on info # Read additional Add-on info
try: try:
@ -109,7 +111,7 @@ class HassIODiscovery(HomeAssistantView):
self.hass, self.hass,
service, service,
context={"source": config_entries.SOURCE_HASSIO}, 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): async def async_process_del(self, data):
@ -128,6 +130,6 @@ class HassIODiscovery(HomeAssistantView):
# Use config flow # Use config flow
for entry in self.hass.config_entries.async_entries(service): 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 continue
await self.hass.config_entries.async_remove(entry.entry_id) await self.hass.config_entries.async_remove(entry.entry_id)

View File

@ -98,6 +98,10 @@ class OTBRConfigFlow(ConfigFlow, domain=DOMAIN):
for current_entry in current_entries: for current_entry in current_entries:
if current_entry.source != SOURCE_HASSIO: if current_entry.source != SOURCE_HASSIO:
continue 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"]) current_url = yarl.URL(current_entry.data["url"])
if ( if (
current_url.host != config["host"] 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) _LOGGER.warning("Failed to communicate with OTBR@%s: %s", url, exc)
return self.async_abort(reason="unknown") 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( return self.async_create_entry(
title="Open Thread Border Router", title="Open Thread Border Router",
data=config_entry_data, data=config_entry_data,

View File

@ -134,6 +134,7 @@ async def test_hassio_already_configured(hass: HomeAssistant) -> None:
}, },
name="AdGuard Home Addon", name="AdGuard Home Addon",
slug="adguard", slug="adguard",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )
@ -158,6 +159,7 @@ async def test_hassio_ignored(hass: HomeAssistant) -> None:
}, },
name="AdGuard Home Addon", name="AdGuard Home Addon",
slug="adguard", slug="adguard",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )
@ -186,6 +188,7 @@ async def test_hassio_confirm(
}, },
name="AdGuard Home Addon", name="AdGuard Home Addon",
slug="adguard", slug="adguard",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )
@ -228,6 +231,7 @@ async def test_hassio_connection_error(
}, },
name="AdGuard Home Addon", name="AdGuard Home Addon",
slug="adguard", slug="adguard",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )

View File

@ -576,6 +576,7 @@ async def test_flow_hassio_discovery(hass: HomeAssistant) -> None:
}, },
name="Mock Addon", name="Mock Addon",
slug="deconz", slug="deconz",
uuid="1234",
), ),
context={"source": SOURCE_HASSIO}, context={"source": SOURCE_HASSIO},
) )
@ -628,6 +629,7 @@ async def test_hassio_discovery_update_configuration(
}, },
name="Mock Addon", name="Mock Addon",
slug="deconz", slug="deconz",
uuid="1234",
), ),
context={"source": SOURCE_HASSIO}, context={"source": SOURCE_HASSIO},
) )
@ -658,6 +660,7 @@ async def test_hassio_discovery_dont_update_configuration(
}, },
name="Mock Addon", name="Mock Addon",
slug="deconz", slug="deconz",
uuid="1234",
), ),
context={"source": SOURCE_HASSIO}, context={"source": SOURCE_HASSIO},
) )

View File

@ -813,6 +813,7 @@ async def test_discovery_hassio(hass: HomeAssistant, mock_dashboard) -> None:
}, },
name="ESPHome", name="ESPHome",
slug="mock-slug", slug="mock-slug",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )

View File

@ -89,6 +89,7 @@ async def test_hassio_discovery_startup(
}, },
name="Mosquitto Test", name="Mosquitto Test",
slug="mosquitto", slug="mosquitto",
uuid="test",
) )
) )
@ -153,6 +154,7 @@ async def test_hassio_discovery_startup_done(
}, },
name="Mosquitto Test", name="Mosquitto Test",
slug="mosquitto", slug="mosquitto",
uuid="test",
) )
) )
@ -207,5 +209,6 @@ async def test_hassio_discovery_webhook(
}, },
name="Mosquitto Test", name="Mosquitto Test",
slug="mosquitto", slug="mosquitto",
uuid="test",
) )
) )

View File

@ -193,6 +193,7 @@ async def test_supervisor_discovery(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Matter Server", name="Matter Server",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )
@ -232,6 +233,7 @@ async def test_supervisor_discovery_addon_info_failed(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Matter Server", name="Matter Server",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )
@ -262,6 +264,7 @@ async def test_clean_supervisor_discovery_on_user_create(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Matter Server", name="Matter Server",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )
@ -324,6 +327,7 @@ async def test_abort_supervisor_discovery_with_existing_entry(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Matter Server", name="Matter Server",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )
@ -353,6 +357,7 @@ async def test_abort_supervisor_discovery_with_existing_flow(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Matter Server", name="Matter Server",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )
@ -379,6 +384,7 @@ async def test_abort_supervisor_discovery_for_other_addon(
}, },
name="Other Matter Server", name="Other Matter Server",
slug="other_addon", slug="other_addon",
uuid="1234",
), ),
) )
@ -404,6 +410,7 @@ async def test_supervisor_discovery_addon_not_running(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Matter Server", name="Matter Server",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )
@ -452,6 +459,7 @@ async def test_supervisor_discovery_addon_not_installed(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Matter Server", name="Matter Server",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )

View File

@ -79,6 +79,7 @@ async def test_hassio_success(hass: HomeAssistant) -> None:
config={"addon": "motionEye", "url": TEST_URL}, config={"addon": "motionEye", "url": TEST_URL},
name="motionEye", name="motionEye",
slug="motioneye", slug="motioneye",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, 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}, config={"addon": "motionEye", "url": TEST_URL},
name="motionEye", name="motionEye",
slug="motioneye", slug="motioneye",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )
@ -376,6 +378,7 @@ async def test_hassio_ignored(hass: HomeAssistant) -> None:
config={"addon": "motionEye", "url": TEST_URL}, config={"addon": "motionEye", "url": TEST_URL},
name="motionEye", name="motionEye",
slug="motioneye", slug="motioneye",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, 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}, config={"addon": "motionEye", "url": TEST_URL},
name="motionEye", name="motionEye",
slug="motioneye", slug="motioneye",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, 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}, config={"addon": "motionEye", "url": TEST_URL},
name="motionEye", name="motionEye",
slug="motioneye", slug="motioneye",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )

View File

@ -343,6 +343,7 @@ async def test_hassio_ignored(hass: HomeAssistant) -> None:
}, },
name="Mosquitto", name="Mosquitto",
slug="mosquitto", slug="mosquitto",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )
@ -373,6 +374,7 @@ async def test_hassio_confirm(
}, },
name="Mock Addon", name="Mock Addon",
slug="mosquitto", slug="mosquitto",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )
@ -421,6 +423,7 @@ async def test_hassio_cannot_connect(
}, },
name="Mock Addon", name="Mock Addon",
slug="mosquitto", slug="mosquitto",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )

View File

@ -21,6 +21,7 @@ HASSIO_DATA = hassio.HassioServiceInfo(
config={"host": "core-silabs-multiprotocol", "port": 8081}, config={"host": "core-silabs-multiprotocol", "port": 8081},
name="Silicon Labs Multiprotocol", name="Silicon Labs Multiprotocol",
slug="otbr", slug="otbr",
uuid="12345",
) )
@ -203,7 +204,7 @@ async def test_hassio_discovery_flow(
assert config_entry.data == expected_data assert config_entry.data == expected_data
assert config_entry.options == {} assert config_entry.options == {}
assert config_entry.title == "Open Thread Border Router" 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( 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.data == expected_data
assert config_entry.options == {} assert config_entry.options == {}
assert config_entry.title == "Open Thread Border Router" 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( 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.data == expected_data
assert config_entry.options == {} assert config_entry.options == {}
assert config_entry.title == "Open Thread Border Router" 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( 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.data == expected_data
assert config_entry.options == {} assert config_entry.options == {}
assert config_entry.title == "Open Thread Border Router" 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( async def test_hassio_discovery_flow_404(

View File

@ -123,6 +123,7 @@ async def test_hassio_discovery(hass: HomeAssistant) -> None:
}, },
name="RTSPtoWebRTC", name="RTSPtoWebRTC",
slug="rtsp-to-webrtc", slug="rtsp-to-webrtc",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )
@ -162,6 +163,7 @@ async def test_hassio_single_config_entry(hass: HomeAssistant) -> None:
}, },
name="RTSPtoWebRTC", name="RTSPtoWebRTC",
slug="rtsp-to-webrtc", slug="rtsp-to-webrtc",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )
@ -184,6 +186,7 @@ async def test_hassio_ignored(hass: HomeAssistant) -> None:
}, },
name="RTSPtoWebRTC", name="RTSPtoWebRTC",
slug="rtsp-to-webrtc", slug="rtsp-to-webrtc",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )
@ -203,6 +206,7 @@ async def test_hassio_discovery_server_failure(hass: HomeAssistant) -> None:
}, },
name="RTSPtoWebRTC", name="RTSPtoWebRTC",
slug="rtsp-to-webrtc", slug="rtsp-to-webrtc",
uuid="1234",
), ),
context={"source": config_entries.SOURCE_HASSIO}, context={"source": config_entries.SOURCE_HASSIO},
) )

View File

@ -250,6 +250,7 @@ async def test_hassio_flow(hass: HomeAssistant) -> None:
}, },
name="VLC", name="VLC",
slug="vlc", slug="vlc",
uuid="1234",
) )
result = await hass.config_entries.flow.async_init( 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( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_HASSIO}, 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() await hass.async_block_till_done()
@ -330,6 +331,7 @@ async def test_hassio_errors(
}, },
name="VLC", name="VLC",
slug="vlc", slug="vlc",
uuid="1234",
), ),
) )
await hass.async_block_till_done() await hass.async_block_till_done()

View File

@ -21,6 +21,7 @@ ADDON_DISCOVERY = HassioServiceInfo(
}, },
name="Piper", name="Piper",
slug="mock_piper", slug="mock_piper",
uuid="1234",
) )
pytestmark = pytest.mark.usefixtures("mock_setup_entry") pytestmark = pytest.mark.usefixtures("mock_setup_entry")

View File

@ -342,6 +342,7 @@ async def test_supervisor_discovery(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Z-Wave JS", name="Z-Wave JS",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )
@ -386,6 +387,7 @@ async def test_supervisor_discovery_cannot_connect(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Z-Wave JS", name="Z-Wave JS",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )
@ -416,6 +418,7 @@ async def test_clean_discovery_on_user_create(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Z-Wave JS", name="Z-Wave JS",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )
@ -486,6 +489,7 @@ async def test_abort_discovery_with_existing_entry(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Z-Wave JS", name="Z-Wave JS",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )
@ -514,6 +518,7 @@ async def test_abort_hassio_discovery_with_existing_flow(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Z-Wave JS", name="Z-Wave JS",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )
@ -536,6 +541,7 @@ async def test_abort_hassio_discovery_for_other_addon(
}, },
name="Other Z-Wave JS", name="Other Z-Wave JS",
slug="other_addon", slug="other_addon",
uuid="1234",
), ),
) )
@ -741,6 +747,7 @@ async def test_discovery_addon_not_running(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Z-Wave JS", name="Z-Wave JS",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )
@ -825,6 +832,7 @@ async def test_discovery_addon_not_installed(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Z-Wave JS", name="Z-Wave JS",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )
@ -912,6 +920,7 @@ async def test_abort_usb_discovery_with_existing_flow(
config=ADDON_DISCOVERY_INFO, config=ADDON_DISCOVERY_INFO,
name="Z-Wave JS", name="Z-Wave JS",
slug=ADDON_SLUG, slug=ADDON_SLUG,
uuid="1234",
), ),
) )

View File

@ -2657,7 +2657,7 @@ async def test_async_setup_update_entry(hass: HomeAssistant) -> None:
(config_entries.SOURCE_ZEROCONF, BaseServiceInfo()), (config_entries.SOURCE_ZEROCONF, BaseServiceInfo()),
( (
config_entries.SOURCE_HASSIO, config_entries.SOURCE_HASSIO,
HassioServiceInfo(config={}, name="Test", slug="test"), HassioServiceInfo(config={}, name="Test", slug="test", uuid="1234"),
), ),
), ),
) )