Fix zeroconf migration messing up ESPHome discovery (#24578)
This commit is contained in:
parent
ddeb6b6baa
commit
05bb645263
2 changed files with 33 additions and 3 deletions
|
@ -56,6 +56,7 @@ class EsphomeFlowHandler(config_entries.ConfigFlow):
|
||||||
self.context['title_placeholders'] = {
|
self.context['title_placeholders'] = {
|
||||||
'name': self._name
|
'name': self._name
|
||||||
}
|
}
|
||||||
|
self.context['name'] = self._name
|
||||||
|
|
||||||
# Only show authentication step if device uses password
|
# Only show authentication step if device uses password
|
||||||
if device_info.uses_password:
|
if device_info.uses_password:
|
||||||
|
@ -98,9 +99,11 @@ class EsphomeFlowHandler(config_entries.ConfigFlow):
|
||||||
already_configured = data.device_info.name == node_name
|
already_configured = data.device_info.name == node_name
|
||||||
|
|
||||||
if already_configured:
|
if already_configured:
|
||||||
return self.async_abort(
|
return self.async_abort(reason='already_configured')
|
||||||
reason='already_configured'
|
|
||||||
)
|
for flow in self._async_in_progress():
|
||||||
|
if flow['context']['name'] == node_name:
|
||||||
|
return self.async_abort(reason='already_configured')
|
||||||
|
|
||||||
return await self._async_authenticate_or_add(user_input={
|
return await self._async_authenticate_or_add(user_input={
|
||||||
'host': address,
|
'host': address,
|
||||||
|
|
|
@ -281,3 +281,30 @@ async def test_discovery_already_configured_name(hass, mock_client):
|
||||||
result = await flow.async_step_zeroconf(user_input=service_info)
|
result = await flow.async_step_zeroconf(user_input=service_info)
|
||||||
assert result['type'] == 'abort'
|
assert result['type'] == 'abort'
|
||||||
assert result['reason'] == 'already_configured'
|
assert result['reason'] == 'already_configured'
|
||||||
|
|
||||||
|
|
||||||
|
async def test_discovery_duplicate_data(hass, mock_client):
|
||||||
|
"""Test discovery aborts if same mDNS packet arrives."""
|
||||||
|
service_info = {
|
||||||
|
'host': '192.168.43.183',
|
||||||
|
'port': 6053,
|
||||||
|
'hostname': 'test8266.local.',
|
||||||
|
'properties': {
|
||||||
|
"address": "test8266.local"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mock_client.device_info.return_value = mock_coro(
|
||||||
|
MockDeviceInfo(False, "test8266"))
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
'esphome', data=service_info, context={'source': 'zeroconf'}
|
||||||
|
)
|
||||||
|
assert result['type'] == 'form'
|
||||||
|
assert result['step_id'] == 'discovery_confirm'
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
'esphome', data=service_info, context={'source': 'zeroconf'}
|
||||||
|
)
|
||||||
|
assert result['type'] == 'abort'
|
||||||
|
assert result['reason'] == 'already_configured'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue