mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Use dataclass properties in esphome discovery (#60606)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
f0df3e4646
commit
416976dd39
@ -143,22 +143,20 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle zeroconf discovery."""
|
"""Handle zeroconf discovery."""
|
||||||
# Hostname is format: livingroom.local.
|
# Hostname is format: livingroom.local.
|
||||||
local_name = discovery_info[zeroconf.ATTR_HOSTNAME][:-1]
|
local_name = discovery_info.hostname[:-1]
|
||||||
node_name = local_name[: -len(".local")]
|
node_name = local_name[: -len(".local")]
|
||||||
address = discovery_info[zeroconf.ATTR_PROPERTIES].get("address", local_name)
|
address = discovery_info.properties.get("address", local_name)
|
||||||
|
|
||||||
# Check if already configured
|
# Check if already configured
|
||||||
await self.async_set_unique_id(node_name)
|
await self.async_set_unique_id(node_name)
|
||||||
self._abort_if_unique_id_configured(
|
self._abort_if_unique_id_configured(updates={CONF_HOST: discovery_info.host})
|
||||||
updates={CONF_HOST: discovery_info[zeroconf.ATTR_HOST]}
|
|
||||||
)
|
|
||||||
|
|
||||||
for entry in self._async_current_entries():
|
for entry in self._async_current_entries():
|
||||||
already_configured = False
|
already_configured = False
|
||||||
|
|
||||||
if CONF_HOST in entry.data and entry.data[CONF_HOST] in (
|
if CONF_HOST in entry.data and entry.data[CONF_HOST] in (
|
||||||
address,
|
address,
|
||||||
discovery_info[zeroconf.ATTR_HOST],
|
discovery_info.host,
|
||||||
):
|
):
|
||||||
# Is this address or IP address already configured?
|
# Is this address or IP address already configured?
|
||||||
already_configured = True
|
already_configured = True
|
||||||
@ -177,15 +175,15 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
entry,
|
entry,
|
||||||
data={
|
data={
|
||||||
**entry.data,
|
**entry.data,
|
||||||
CONF_HOST: discovery_info[zeroconf.ATTR_HOST],
|
CONF_HOST: discovery_info.host,
|
||||||
},
|
},
|
||||||
unique_id=node_name,
|
unique_id=node_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.async_abort(reason="already_configured")
|
return self.async_abort(reason="already_configured")
|
||||||
|
|
||||||
self._host = discovery_info[zeroconf.ATTR_HOST]
|
self._host = discovery_info.host
|
||||||
self._port = discovery_info[zeroconf.ATTR_PORT]
|
self._port = discovery_info.port
|
||||||
self._name = node_name
|
self._name = node_name
|
||||||
|
|
||||||
return await self.async_step_discovery_confirm()
|
return await self.async_step_discovery_confirm()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user