deCONZ migrate setup fully to config entry (#13679)
* Initial working config entry with discovery * No need for else * Make sure that imported config doesnt exist as a config entry * Improve checks to make sure there is only instance of deconz * Fix tests and add new tests * Follow upstream changes Fix case when discovery started ongoing config entry and user completes setup from other path it was possible to complete discovered config entry as well * Add test to make sure link doesn't bypass any check for only allowing one config entry * Dont use len to determine an empty sequence * Cleanup * Allways get bridgeid to use as unique identifier for bridge
This commit is contained in:
parent
7d43ad6a37
commit
c5cb28d41f
10 changed files with 481 additions and 268 deletions
69
tests/components/deconz/test_init.py
Normal file
69
tests/components/deconz/test_init.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
"""Test deCONZ component setup process."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import deconz
|
||||
|
||||
|
||||
async def test_config_with_host_passed_to_config_entry(hass):
|
||||
"""Test that configured options for a host are loaded via config entry."""
|
||||
with patch.object(hass, 'config_entries') as mock_config_entries, \
|
||||
patch.object(deconz, 'configured_hosts', return_value=[]), \
|
||||
patch.object(deconz, 'load_json', return_value={}):
|
||||
assert await async_setup_component(hass, deconz.DOMAIN, {
|
||||
deconz.DOMAIN: {
|
||||
deconz.CONF_HOST: '1.2.3.4',
|
||||
deconz.CONF_PORT: 80
|
||||
}
|
||||
}) is True
|
||||
# Import flow started
|
||||
assert len(mock_config_entries.flow.mock_calls) == 2
|
||||
|
||||
|
||||
async def test_config_file_passed_to_config_entry(hass):
|
||||
"""Test that configuration file for a host are loaded via config entry."""
|
||||
with patch.object(hass, 'config_entries') as mock_config_entries, \
|
||||
patch.object(deconz, 'configured_hosts', return_value=[]), \
|
||||
patch.object(deconz, 'load_json',
|
||||
return_value={'host': '1.2.3.4'}):
|
||||
assert await async_setup_component(hass, deconz.DOMAIN, {
|
||||
deconz.DOMAIN: {}
|
||||
}) is True
|
||||
# Import flow started
|
||||
assert len(mock_config_entries.flow.mock_calls) == 2
|
||||
|
||||
|
||||
async def test_config_without_host_not_passed_to_config_entry(hass):
|
||||
"""Test that a configuration without a host does not initiate an import."""
|
||||
with patch.object(hass, 'config_entries') as mock_config_entries, \
|
||||
patch.object(deconz, 'configured_hosts', return_value=[]), \
|
||||
patch.object(deconz, 'load_json', return_value={}):
|
||||
assert await async_setup_component(hass, deconz.DOMAIN, {
|
||||
deconz.DOMAIN: {}
|
||||
}) is True
|
||||
# No flow started
|
||||
assert len(mock_config_entries.flow.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_config_already_registered_not_passed_to_config_entry(hass):
|
||||
"""Test that an already registered host does not initiate an import."""
|
||||
with patch.object(hass, 'config_entries') as mock_config_entries, \
|
||||
patch.object(deconz, 'configured_hosts',
|
||||
return_value=['1.2.3.4']), \
|
||||
patch.object(deconz, 'load_json', return_value={}):
|
||||
assert await async_setup_component(hass, deconz.DOMAIN, {
|
||||
deconz.DOMAIN: {
|
||||
deconz.CONF_HOST: '1.2.3.4',
|
||||
deconz.CONF_PORT: 80
|
||||
}
|
||||
}) is True
|
||||
# No flow started
|
||||
assert len(mock_config_entries.flow.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_config_discovery(hass):
|
||||
"""Test that a discovered bridge does not initiate an import."""
|
||||
with patch.object(hass, 'config_entries') as mock_config_entries:
|
||||
assert await async_setup_component(hass, deconz.DOMAIN, {}) is True
|
||||
# No flow started
|
||||
assert len(mock_config_entries.flow.mock_calls) == 0
|
Loading…
Add table
Add a link
Reference in a new issue