mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Use dataclass properties in roku discovery (#60577)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
9374ce87ba
commit
d74145ed7b
@ -8,11 +8,7 @@ from rokuecp import Roku, RokuError
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import ssdp, zeroconf
|
from homeassistant.components import ssdp, zeroconf
|
||||||
from homeassistant.components.ssdp import (
|
from homeassistant.components.ssdp import ATTR_UPNP_FRIENDLY_NAME, ATTR_UPNP_SERIAL
|
||||||
ATTR_SSDP_LOCATION,
|
|
||||||
ATTR_UPNP_FRIENDLY_NAME,
|
|
||||||
ATTR_UPNP_SERIAL,
|
|
||||||
)
|
|
||||||
from homeassistant.config_entries import ConfigFlow
|
from homeassistant.config_entries import ConfigFlow
|
||||||
from homeassistant.const import CONF_HOST, CONF_NAME
|
from homeassistant.const import CONF_HOST, CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
@ -91,9 +87,9 @@ class RokuConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
# If we already have the host configured do
|
# If we already have the host configured do
|
||||||
# not open connections to it if we can avoid it.
|
# not open connections to it if we can avoid it.
|
||||||
self._async_abort_entries_match({CONF_HOST: discovery_info[zeroconf.ATTR_HOST]})
|
self._async_abort_entries_match({CONF_HOST: discovery_info.host})
|
||||||
|
|
||||||
self.discovery_info.update({CONF_HOST: discovery_info[zeroconf.ATTR_HOST]})
|
self.discovery_info.update({CONF_HOST: discovery_info.host})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
info = await validate_input(self.hass, self.discovery_info)
|
info = await validate_input(self.hass, self.discovery_info)
|
||||||
@ -106,7 +102,7 @@ class RokuConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
await self.async_set_unique_id(info["serial_number"])
|
await self.async_set_unique_id(info["serial_number"])
|
||||||
self._abort_if_unique_id_configured(
|
self._abort_if_unique_id_configured(
|
||||||
updates={CONF_HOST: discovery_info[zeroconf.ATTR_HOST]},
|
updates={CONF_HOST: discovery_info.host},
|
||||||
)
|
)
|
||||||
|
|
||||||
self.context.update({"title_placeholders": {"name": info["title"]}})
|
self.context.update({"title_placeholders": {"name": info["title"]}})
|
||||||
@ -116,9 +112,9 @@ class RokuConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
||||||
"""Handle a flow initialized by discovery."""
|
"""Handle a flow initialized by discovery."""
|
||||||
host = urlparse(discovery_info[ATTR_SSDP_LOCATION]).hostname
|
host = urlparse(discovery_info.ssdp_location).hostname
|
||||||
name = discovery_info[ATTR_UPNP_FRIENDLY_NAME]
|
name = discovery_info.upnp[ATTR_UPNP_FRIENDLY_NAME]
|
||||||
serial_number = discovery_info[ATTR_UPNP_SERIAL]
|
serial_number = discovery_info.upnp[ATTR_UPNP_SERIAL]
|
||||||
|
|
||||||
await self.async_set_unique_id(serial_number)
|
await self.async_set_unique_id(serial_number)
|
||||||
self._abort_if_unique_id_configured(updates={CONF_HOST: host})
|
self._abort_if_unique_id_configured(updates={CONF_HOST: host})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user