Fix zeroconf migration messing up ESPHome discovery (#24578)

pull/24601/head
Otto Winter 2019-06-17 18:19:40 +02:00 committed by Paulus Schoutsen
parent ddeb6b6baa
commit 05bb645263
2 changed files with 33 additions and 3 deletions

View File

@ -56,6 +56,7 @@ class EsphomeFlowHandler(config_entries.ConfigFlow):
self.context['title_placeholders'] = {
'name': self._name
}
self.context['name'] = self._name
# Only show authentication step if device uses password
if device_info.uses_password:
@ -98,9 +99,11 @@ class EsphomeFlowHandler(config_entries.ConfigFlow):
already_configured = data.device_info.name == node_name
if already_configured:
return self.async_abort(
reason='already_configured'
)
return self.async_abort(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={
'host': address,

View File

@ -281,3 +281,30 @@ async def test_discovery_already_configured_name(hass, mock_client):
result = await flow.async_step_zeroconf(user_input=service_info)
assert result['type'] == 'abort'
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'