From e0b315041bb8c56f78e1a679a8892037b601600b Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 30 Nov 2021 08:42:08 +0100 Subject: [PATCH] Use dataclass properties in octoprint discovery (#60579) Co-authored-by: epenet --- .../components/octoprint/config_flow.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/octoprint/config_flow.py b/homeassistant/components/octoprint/config_flow.py index b2815b2d10f..6e6301a0ce5 100644 --- a/homeassistant/components/octoprint/config_flow.py +++ b/homeassistant/components/octoprint/config_flow.py @@ -6,7 +6,7 @@ import voluptuous as vol from yarl import URL from homeassistant import config_entries, data_entry_flow, exceptions -from homeassistant.components import zeroconf +from homeassistant.components import ssdp, zeroconf from homeassistant.const import ( CONF_API_KEY, CONF_HOST, @@ -143,29 +143,31 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> data_entry_flow.FlowResult: """Handle discovery flow.""" - uuid = discovery_info[zeroconf.ATTR_PROPERTIES]["uuid"] + uuid = discovery_info.properties["uuid"] await self.async_set_unique_id(uuid) self._abort_if_unique_id_configured() self.context["title_placeholders"] = { - CONF_HOST: discovery_info[zeroconf.ATTR_HOST], + CONF_HOST: discovery_info.host, } self.discovery_schema = _schema_with_defaults( - host=discovery_info[zeroconf.ATTR_HOST], - port=discovery_info[zeroconf.ATTR_PORT], - path=discovery_info[zeroconf.ATTR_PROPERTIES][CONF_PATH], + host=discovery_info.host, + port=discovery_info.port, + path=discovery_info.properties[CONF_PATH], ) return await self.async_step_user() - async def async_step_ssdp(self, discovery_info): + async def async_step_ssdp( + self, discovery_info: ssdp.SsdpServiceInfo + ) -> data_entry_flow.FlowResult: """Handle ssdp discovery flow.""" - uuid = discovery_info["UDN"][5:] + uuid = discovery_info.upnp["UDN"][5:] await self.async_set_unique_id(uuid) self._abort_if_unique_id_configured() - url = URL(discovery_info["presentationURL"]) + url = URL(discovery_info.upnp["presentationURL"]) self.context["title_placeholders"] = { CONF_HOST: url.host, }