Don't initialize components which have already been discovered (#6381)
* Don't initialize components which have already been discovered (fixes #5588) * Don't log that we've found a service unless we know it's not a duplicate * Encode discovery data hash with JSON This also solves the issue of trying to hash non-hashable objects like dicts * Add test for duplicate device discovery
This commit is contained in:
1 parent
a9db6b16eb
commit
ab42acf4d7
2 files changed
+37
-2
No files matched your search
@@ -126,3 +126,30 @@ def test_ignore_service(hass):
|
||||
|
||||
assert not mock_discover.called
|
||||
assert not mock_platform.called
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_discover_duplicates(hass):
|
||||
"""Test load a component."""
|
||||
result = yield from async_setup_component(hass, 'discovery', BASE_CONFIG)
|
||||
assert result
|
||||
|
||||
def discover(netdisco):
|
||||
"""Fake discovery."""
|
||||
return [(SERVICE_NO_PLATFORM, SERVICE_INFO),
|
||||
(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
||||
|
||||
with patch.object(discovery, '_discover', discover), \
|
||||
patch('homeassistant.components.discovery.async_discover',
|
||||
return_value=mock_coro()) as mock_discover, \
|
||||
patch('homeassistant.components.discovery.async_load_platform',
|
||||
return_value=mock_coro()) as mock_platform:
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
assert mock_discover.called
|
||||
assert mock_discover.call_count == 1
|
||||
assert not mock_platform.called
|
||||
mock_discover.assert_called_with(
|
||||
hass, SERVICE_NO_PLATFORM, SERVICE_INFO,
|
||||
SERVICE_NO_PLATFORM_COMPONENT, BASE_CONFIG)
|
||||
Reference in new issue
Block a user