Gracefully handle no uuid in kodi discovery (#43494)
This commit is contained in:
parent
99399cfd29
commit
e94111f725
4 changed files with 27 additions and 2 deletions
homeassistant/components/kodi
tests/components/kodi
|
@ -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)
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Reference in a new issue