mirror of https://github.com/home-assistant/core
Ignore duplicate tradfri discovery (#24759)
* Ignore duplicate tradfri discovery * Update name
This commit is contained in:
parent
da57f92796
commit
26fc57d1b3
|
@ -78,13 +78,22 @@ class FlowHandler(config_entries.ConfigFlow):
|
|||
|
||||
async def async_step_zeroconf(self, user_input):
|
||||
"""Handle zeroconf discovery."""
|
||||
host = user_input['host']
|
||||
|
||||
# pylint: disable=unsupported-assignment-operation
|
||||
self.context['host'] = host
|
||||
|
||||
if any(host == flow['context']['host']
|
||||
for flow in self._async_in_progress()):
|
||||
return self.async_abort(reason='already_in_progress')
|
||||
|
||||
for entry in self._async_current_entries():
|
||||
if entry.data[CONF_HOST] == user_input['host']:
|
||||
if entry.data[CONF_HOST] == host:
|
||||
return self.async_abort(
|
||||
reason='already_configured'
|
||||
)
|
||||
|
||||
self._host = user_input['host']
|
||||
self._host = host
|
||||
return await self.async_step_auth()
|
||||
|
||||
async_step_homekit = async_step_zeroconf
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
"timeout": "Timeout validating the code."
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "Bridge is already configured"
|
||||
"already_configured": "Bridge is already configured.",
|
||||
"already_in_progress": "Bridge configuration is already in progress."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -258,7 +258,7 @@ async def test_discovery_duplicate_aborted(hass):
|
|||
|
||||
|
||||
async def test_import_duplicate_aborted(hass):
|
||||
"""Test a duplicate discovery host is ignored."""
|
||||
"""Test a duplicate import host is ignored."""
|
||||
MockConfigEntry(
|
||||
domain='tradfri',
|
||||
data={'host': 'some-host'}
|
||||
|
@ -271,3 +271,20 @@ async def test_import_duplicate_aborted(hass):
|
|||
|
||||
assert flow['type'] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert flow['reason'] == 'already_configured'
|
||||
|
||||
|
||||
async def test_duplicate_discovery(hass, mock_auth, mock_entry_setup):
|
||||
"""Test a duplicate discovery in progress is ignored."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
'tradfri', context={'source': 'zeroconf'}, data={
|
||||
'host': '123.123.123.123'
|
||||
})
|
||||
|
||||
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
|
||||
|
||||
result2 = await hass.config_entries.flow.async_init(
|
||||
'tradfri', context={'source': 'zeroconf'}, data={
|
||||
'host': '123.123.123.123'
|
||||
})
|
||||
|
||||
assert result2['type'] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
|
|
Loading…
Reference in New Issue