Use ZeroconfServiceInfo in roku (#60053)

This commit is contained in:
epenet 2021-11-21 18:27:35 +01:00 committed by GitHub
parent 2270e920c3
commit 7560f11680
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

View File

@ -7,6 +7,7 @@ from urllib.parse import urlparse
from rokuecp import Roku, RokuError
import voluptuous as vol
from homeassistant.components import zeroconf
from homeassistant.components.ssdp import (
ATTR_SSDP_LOCATION,
ATTR_UPNP_FRIENDLY_NAME,
@ -84,14 +85,16 @@ class RokuConfigFlow(ConfigFlow, domain=DOMAIN):
return self.async_create_entry(title=info["title"], data=user_input)
async def async_step_homekit(self, discovery_info):
async def async_step_homekit(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
"""Handle a flow initialized by homekit discovery."""
# If we already have the host configured do
# not open connections to it if we can avoid it.
self._async_abort_entries_match({CONF_HOST: discovery_info[CONF_HOST]})
self._async_abort_entries_match({CONF_HOST: discovery_info[zeroconf.ATTR_HOST]})
self.discovery_info.update({CONF_HOST: discovery_info[CONF_HOST]})
self.discovery_info.update({CONF_HOST: discovery_info[zeroconf.ATTR_HOST]})
try:
info = await validate_input(self.hass, self.discovery_info)
@ -104,7 +107,7 @@ class RokuConfigFlow(ConfigFlow, domain=DOMAIN):
await self.async_set_unique_id(info["serial_number"])
self._abort_if_unique_id_configured(
updates={CONF_HOST: discovery_info[CONF_HOST]},
updates={CONF_HOST: discovery_info[zeroconf.ATTR_HOST]},
)
self.context.update({"title_placeholders": {"name": info["title"]}})

View File

@ -3,13 +3,14 @@ from http import HTTPStatus
import re
from socket import gaierror as SocketGIAError
from homeassistant.components import zeroconf
from homeassistant.components.roku.const import DOMAIN
from homeassistant.components.ssdp import (
ATTR_SSDP_LOCATION,
ATTR_UPNP_FRIENDLY_NAME,
ATTR_UPNP_SERIAL,
)
from homeassistant.const import CONF_HOST, CONF_ID, CONF_NAME
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture
@ -31,13 +32,13 @@ MOCK_SSDP_DISCOVERY_INFO = {
HOMEKIT_HOST = "192.168.1.161"
MOCK_HOMEKIT_DISCOVERY_INFO = {
CONF_NAME: "onn._hap._tcp.local.",
CONF_HOST: HOMEKIT_HOST,
"properties": {
CONF_ID: "2d:97:da:ee:dc:99",
MOCK_HOMEKIT_DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
name="onn._hap._tcp.local.",
host=HOMEKIT_HOST,
properties={
zeroconf.ATTR_PROPERTIES_ID: "2d:97:da:ee:dc:99",
},
}
)
def mock_connection(