Use ZeroconfServiceInfo in kodi (#59984)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/60001/head
epenet 2021-11-19 17:16:28 +01:00 committed by GitHub
parent 8a4d3b2a2e
commit e3ee19d0c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 23 deletions

View File

@ -7,6 +7,7 @@ from pykodi import CannotConnectError, InvalidAuthError, Kodi, get_kodi_connecti
import voluptuous as vol
from homeassistant import config_entries, core, exceptions
from homeassistant.components import zeroconf
from homeassistant.const import (
CONF_HOST,
CONF_NAME,
@ -17,8 +18,8 @@ from homeassistant.const import (
CONF_USERNAME,
)
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.typing import DiscoveryInfoType
from .const import (
CONF_WS_PORT,
@ -99,15 +100,17 @@ class KodiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self._ssl: bool | None = DEFAULT_SSL
self._discovery_name: str | None = None
async def async_step_zeroconf(self, discovery_info: DiscoveryInfoType):
async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
"""Handle zeroconf discovery."""
self._host = discovery_info["host"]
self._port = int(discovery_info["port"])
self._name = discovery_info["hostname"][: -len(".local.")]
if not (uuid := discovery_info["properties"].get("uuid")):
self._host = discovery_info[zeroconf.ATTR_HOST]
self._port = int(discovery_info[zeroconf.ATTR_PORT])
self._name = discovery_info[zeroconf.ATTR_HOSTNAME][: -len(".local.")]
if not (uuid := discovery_info[zeroconf.ATTR_PROPERTIES].get("uuid")):
return self.async_abort(reason="no_uuid")
self._discovery_name = discovery_info["name"]
self._discovery_name = discovery_info[zeroconf.ATTR_NAME]
await self.async_set_unique_id(uuid)
self._abort_if_unique_id_configured(

View File

@ -1,4 +1,5 @@
"""Test the Kodi config flow."""
from homeassistant.components import zeroconf
from homeassistant.components.kodi.const import DEFAULT_SSL
TEST_HOST = {
@ -14,24 +15,24 @@ TEST_CREDENTIALS = {"username": "username", "password": "password"}
TEST_WS_PORT = {"ws_port": 9090}
UUID = "11111111-1111-1111-1111-111111111111"
TEST_DISCOVERY = {
"host": "1.1.1.1",
"port": 8080,
"hostname": "hostname.local.",
"type": "_xbmc-jsonrpc-h._tcp.local.",
"name": "hostname._xbmc-jsonrpc-h._tcp.local.",
"properties": {"uuid": UUID},
}
TEST_DISCOVERY = zeroconf.ZeroconfServiceInfo(
host="1.1.1.1",
port=8080,
hostname="hostname.local.",
type="_xbmc-jsonrpc-h._tcp.local.",
name="hostname._xbmc-jsonrpc-h._tcp.local.",
properties={"uuid": UUID},
)
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_DISCOVERY_WO_UUID = zeroconf.ZeroconfServiceInfo(
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 = {