Use dataclass properties in forked_daapd discovery (#60587)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-11-30 10:55:32 +01:00 committed by GitHub
parent 7182827818
commit 40a814221c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -160,7 +160,7 @@ class ForkedDaapdFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
) -> FlowResult: ) -> FlowResult:
"""Prepare configuration for a discovered forked-daapd device.""" """Prepare configuration for a discovered forked-daapd device."""
version_num = 0 version_num = 0
zeroconf_properties = discovery_info[zeroconf.ATTR_PROPERTIES] zeroconf_properties = discovery_info.properties
if zeroconf_properties.get("Machine Name"): if zeroconf_properties.get("Machine Name"):
with suppress(ValueError): with suppress(ValueError):
version_num = int( version_num = int(
@ -173,7 +173,7 @@ class ForkedDaapdFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
# Update title and abort if we already have an entry for this host # Update title and abort if we already have an entry for this host
for entry in self._async_current_entries(): for entry in self._async_current_entries():
if entry.data.get(CONF_HOST) != discovery_info[zeroconf.ATTR_HOST]: if entry.data.get(CONF_HOST) != discovery_info.host:
continue continue
self.hass.config_entries.async_update_entry( self.hass.config_entries.async_update_entry(
entry, entry,
@ -182,8 +182,8 @@ class ForkedDaapdFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
return self.async_abort(reason="already_configured") return self.async_abort(reason="already_configured")
zeroconf_data = { zeroconf_data = {
CONF_HOST: discovery_info[zeroconf.ATTR_HOST], CONF_HOST: discovery_info.host,
CONF_PORT: discovery_info[zeroconf.ATTR_PORT], CONF_PORT: discovery_info.port,
CONF_NAME: zeroconf_properties["Machine Name"], CONF_NAME: zeroconf_properties["Machine Name"],
} }
self.discovery_schema = vol.Schema(fill_in_schema_dict(zeroconf_data)) self.discovery_schema = vol.Schema(fill_in_schema_dict(zeroconf_data))