Fix ESPHome discovered when already exists (#24187)
* Fix ESPHome discovered when already exists * Update .coveragerc
This commit is contained in:
parent
04c5cda7e5
commit
1ce2d97d3d
5 changed files with 183 additions and 144 deletions
|
@ -7,6 +7,8 @@ import voluptuous as vol
|
|||
from homeassistant import config_entries
|
||||
from homeassistant.helpers import ConfigType
|
||||
|
||||
from .entry_data import DATA_KEY, RuntimeEntryData
|
||||
|
||||
|
||||
@config_entries.HANDLERS.register('esphome')
|
||||
class EsphomeFlowHandler(config_entries.ConfigFlow):
|
||||
|
@ -76,10 +78,25 @@ class EsphomeFlowHandler(config_entries.ConfigFlow):
|
|||
|
||||
async def async_step_zeroconf(self, user_input: ConfigType):
|
||||
"""Handle zeroconf discovery."""
|
||||
address = user_input['properties'].get(
|
||||
'address', user_input['hostname'][:-1])
|
||||
# Hostname is format: livingroom.local.
|
||||
local_name = user_input['hostname'][:-1]
|
||||
node_name = local_name[:-len('.local')]
|
||||
address = user_input['properties'].get('address', local_name)
|
||||
|
||||
# Check if already configured
|
||||
for entry in self._async_current_entries():
|
||||
already_configured = False
|
||||
if entry.data['host'] == address:
|
||||
# Is this address already configured?
|
||||
already_configured = True
|
||||
elif entry.entry_id in self.hass.data.get(DATA_KEY, {}):
|
||||
# Does a config entry with this name already exist?
|
||||
data = self.hass.data[DATA_KEY][
|
||||
entry.entry_id] # type: RuntimeEntryData
|
||||
# Node names are unique in the network
|
||||
already_configured = data.device_info.name == node_name
|
||||
|
||||
if already_configured:
|
||||
return self.async_abort(
|
||||
reason='already_configured'
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue