Use dataclass properties in samsungtv discovery (#60595)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-01 16:42:42 +01:00 committed by GitHub
parent e7f00c2c4f
commit fc3c9b1b4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,12 +12,6 @@ import voluptuous as vol
from homeassistant import config_entries, data_entry_flow
from homeassistant.components import dhcp, ssdp, zeroconf
from homeassistant.components.ssdp import (
ATTR_SSDP_LOCATION,
ATTR_UPNP_MANUFACTURER,
ATTR_UPNP_MODEL_NAME,
ATTR_UPNP_UDN,
)
from homeassistant.const import (
CONF_HOST,
CONF_MAC,
@ -269,12 +263,12 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
) -> data_entry_flow.FlowResult:
"""Handle a flow initialized by ssdp discovery."""
LOGGER.debug("Samsung device found via SSDP: %s", discovery_info)
model_name: str = discovery_info.get(ATTR_UPNP_MODEL_NAME) or ""
self._udn = _strip_uuid(discovery_info[ATTR_UPNP_UDN])
if hostname := urlparse(discovery_info[ATTR_SSDP_LOCATION]).hostname:
model_name: str = discovery_info.upnp.get(ssdp.ATTR_UPNP_MODEL_NAME) or ""
self._udn = _strip_uuid(discovery_info.upnp[ssdp.ATTR_UPNP_UDN])
if hostname := urlparse(discovery_info.ssdp_location or "").hostname:
self._host = hostname
await self._async_set_unique_id_from_udn()
self._manufacturer = discovery_info[ATTR_UPNP_MANUFACTURER]
self._manufacturer = discovery_info.upnp[ssdp.ATTR_UPNP_MANUFACTURER]
self._abort_if_manufacturer_is_not_samsung()
if not await self._async_get_and_check_device_info():
# If we cannot get device info for an SSDP discovery
@ -290,8 +284,8 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
) -> data_entry_flow.FlowResult:
"""Handle a flow initialized by dhcp discovery."""
LOGGER.debug("Samsung device found via DHCP: %s", discovery_info)
self._mac = discovery_info[dhcp.MAC_ADDRESS]
self._host = discovery_info[dhcp.IP_ADDRESS]
self._mac = discovery_info.macaddress
self._host = discovery_info.ip
await self._async_start_discovery_with_mac_address()
await self._async_set_device_unique_id()
self.context["title_placeholders"] = {"device": self._title}