Use dataclass properties in octoprint discovery (#60579)

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

View File

@ -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,
}