Use ZeroconfServiceInfo in kodi (#59984)
Co-authored-by: epenet <epenet@users.noreply.github.com>pull/60001/head
parent
8a4d3b2a2e
commit
e3ee19d0c4
|
@ -7,6 +7,7 @@ from pykodi import CannotConnectError, InvalidAuthError, Kodi, get_kodi_connecti
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries, core, exceptions
|
from homeassistant import config_entries, core, exceptions
|
||||||
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
|
@ -17,8 +18,8 @@ from homeassistant.const import (
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_WS_PORT,
|
CONF_WS_PORT,
|
||||||
|
@ -99,15 +100,17 @@ class KodiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
self._ssl: bool | None = DEFAULT_SSL
|
self._ssl: bool | None = DEFAULT_SSL
|
||||||
self._discovery_name: str | None = None
|
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."""
|
"""Handle zeroconf discovery."""
|
||||||
self._host = discovery_info["host"]
|
self._host = discovery_info[zeroconf.ATTR_HOST]
|
||||||
self._port = int(discovery_info["port"])
|
self._port = int(discovery_info[zeroconf.ATTR_PORT])
|
||||||
self._name = discovery_info["hostname"][: -len(".local.")]
|
self._name = discovery_info[zeroconf.ATTR_HOSTNAME][: -len(".local.")]
|
||||||
if not (uuid := discovery_info["properties"].get("uuid")):
|
if not (uuid := discovery_info[zeroconf.ATTR_PROPERTIES].get("uuid")):
|
||||||
return self.async_abort(reason="no_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)
|
await self.async_set_unique_id(uuid)
|
||||||
self._abort_if_unique_id_configured(
|
self._abort_if_unique_id_configured(
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Test the Kodi config flow."""
|
"""Test the Kodi config flow."""
|
||||||
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.components.kodi.const import DEFAULT_SSL
|
from homeassistant.components.kodi.const import DEFAULT_SSL
|
||||||
|
|
||||||
TEST_HOST = {
|
TEST_HOST = {
|
||||||
|
@ -14,24 +15,24 @@ TEST_CREDENTIALS = {"username": "username", "password": "password"}
|
||||||
TEST_WS_PORT = {"ws_port": 9090}
|
TEST_WS_PORT = {"ws_port": 9090}
|
||||||
|
|
||||||
UUID = "11111111-1111-1111-1111-111111111111"
|
UUID = "11111111-1111-1111-1111-111111111111"
|
||||||
TEST_DISCOVERY = {
|
TEST_DISCOVERY = zeroconf.ZeroconfServiceInfo(
|
||||||
"host": "1.1.1.1",
|
host="1.1.1.1",
|
||||||
"port": 8080,
|
port=8080,
|
||||||
"hostname": "hostname.local.",
|
hostname="hostname.local.",
|
||||||
"type": "_xbmc-jsonrpc-h._tcp.local.",
|
type="_xbmc-jsonrpc-h._tcp.local.",
|
||||||
"name": "hostname._xbmc-jsonrpc-h._tcp.local.",
|
name="hostname._xbmc-jsonrpc-h._tcp.local.",
|
||||||
"properties": {"uuid": UUID},
|
properties={"uuid": UUID},
|
||||||
}
|
)
|
||||||
|
|
||||||
|
|
||||||
TEST_DISCOVERY_WO_UUID = {
|
TEST_DISCOVERY_WO_UUID = zeroconf.ZeroconfServiceInfo(
|
||||||
"host": "1.1.1.1",
|
host="1.1.1.1",
|
||||||
"port": 8080,
|
port=8080,
|
||||||
"hostname": "hostname.local.",
|
hostname="hostname.local.",
|
||||||
"type": "_xbmc-jsonrpc-h._tcp.local.",
|
type="_xbmc-jsonrpc-h._tcp.local.",
|
||||||
"name": "hostname._xbmc-jsonrpc-h._tcp.local.",
|
name="hostname._xbmc-jsonrpc-h._tcp.local.",
|
||||||
"properties": {},
|
properties={},
|
||||||
}
|
)
|
||||||
|
|
||||||
|
|
||||||
TEST_IMPORT = {
|
TEST_IMPORT = {
|
||||||
|
|
Loading…
Reference in New Issue