Skip to content

Commit

Permalink
Ignore duplicate tradfri discovery (#24759)
Browse files Browse the repository at this point in the history
* Ignore duplicate tradfri discovery

* Update name
  • Loading branch information
balloob committed Jun 25, 2019
1 parent da57f92 commit 26fc57d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
13 changes: 11 additions & 2 deletions homeassistant/components/tradfri/config_flow.py
Expand Up @@ -78,13 +78,22 @@ async def async_step_auth(self, user_input=None):

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
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/tradfri/strings.json
Expand Up @@ -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."
}
}
}
19 changes: 18 additions & 1 deletion tests/components/tradfri/test_config_flow.py
Expand Up @@ -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'}
Expand All @@ -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

0 comments on commit 26fc57d

Please sign in to comment.