Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle no uuid in kodi discovery #43494

Merged
merged 2 commits into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Gracefully handle no uuid in kodi discovery
  • Loading branch information
OnFreund committed Nov 21, 2020
commit fdf38f02d6490a85dbe265a7329e63139ddd6cb1
5 changes: 4 additions & 1 deletion homeassistant/components/kodi/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ async def async_step_zeroconf(self, discovery_info: DiscoveryInfoType):
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)
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/kodi/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
frenck marked this conversation as resolved.
Show resolved Hide resolved
}
},
"device_automation": {
Expand Down
11 changes: 11 additions & 0 deletions tests/components/kodi/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .util import (
TEST_CREDENTIALS,
TEST_DISCOVERY,
TEST_DISCOVERY_WO_UUID,
TEST_HOST,
TEST_IMPORT,
TEST_WS_PORT,
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions tests/components/kodi/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
}


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",
Expand Down