1
mirror of https://github.com/home-assistant/core synced 2024-08-31 05:57:13 +02:00

Gracefully handle no uuid in kodi discovery (#43494)

This commit is contained in:
On Freund 2020-11-21 21:47:57 +02:00 committed by GitHub
parent 76eb5aeeb6
commit b2c9bd2ca6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 2 deletions

View File

@ -104,7 +104,10 @@ class KodiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self._host = discovery_info["host"]
self._port = int(discovery_info["port"])
self._name = discovery_info["hostname"][: -len(".local.")]
uuid = discovery_info["properties"]["uuid"]
uuid = discovery_info["properties"].get("uuid")
if not uuid:
return self.async_abort(reason="no_uuid")
self._discovery_name = discovery_info["name"]
await self.async_set_unique_id(uuid)

View File

@ -37,7 +37,8 @@
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
"unknown": "[%key:common::config_flow::error::unknown%]",
"no_uuid": "Kodi instance does not have a unique id. This is most likely due to an old Kodi version (17.x or below). You can configure the integration manually or upgrade to a more recent Kodi version."
}
},
"device_automation": {

View File

@ -11,6 +11,7 @@ from homeassistant.components.kodi.const import DEFAULT_TIMEOUT, DOMAIN
from .util import (
TEST_CREDENTIALS,
TEST_DISCOVERY,
TEST_DISCOVERY_WO_UUID,
TEST_HOST,
TEST_IMPORT,
TEST_WS_PORT,
@ -573,6 +574,16 @@ async def test_discovery_updates_unique_id(hass):
assert entry.data["name"] == "hostname"
async def test_discovery_without_unique_id(hass):
"""Test a discovery flow with no unique id aborts."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY_WO_UUID
)
assert result["type"] == "abort"
assert result["reason"] == "no_uuid"
async def test_form_import(hass):
"""Test we get the form with import source."""
with patch(

View File

@ -24,6 +24,16 @@ TEST_DISCOVERY = {
}
TEST_DISCOVERY_WO_UUID = {
"host": "1.1.1.1",
"port": 8080,
"hostname": "hostname.local.",
"type": "_xbmc-jsonrpc-h._tcp.local.",
"name": "hostname._xbmc-jsonrpc-h._tcp.local.",
"properties": {},
}
TEST_IMPORT = {
"name": "name",
"host": "1.1.1.1",