Support old tradfri config format (#16841)

pull/16427/head
Paulus Schoutsen 2018-09-25 11:57:32 +02:00 committed by Pascal Vizeli
parent 4a4c07ac1b
commit 2b2502c91c
2 changed files with 34 additions and 1 deletions

View File

@ -95,7 +95,9 @@ class FlowHandler(config_entries.ConfigFlow):
try:
data = await get_gateway_info(
self.hass, user_input['host'], user_input['identity'],
self.hass, user_input['host'],
# Old config format had a fixed identity
user_input.get('identity', 'homeassistant'),
user_input['key'])
data[CONF_IMPORT_GROUPS] = user_input[CONF_IMPORT_GROUPS]

View File

@ -154,3 +154,34 @@ async def test_import_connection(hass, mock_gateway_info, mock_entry_setup):
assert len(mock_gateway_info.mock_calls) == 1
assert len(mock_entry_setup.mock_calls) == 1
async def test_import_connection_legacy(hass, mock_gateway_info,
mock_entry_setup):
"""Test a connection via import."""
mock_gateway_info.side_effect = \
lambda hass, host, identity, key: mock_coro({
'host': host,
'identity': identity,
'key': key,
'gateway_id': 'mock-gateway'
})
result = await hass.config_entries.flow.async_init(
'tradfri', context={'source': 'import'}, data={
'host': '123.123.123.123',
'key': 'mock-key',
'import_groups': True
})
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result['result'].data == {
'host': '123.123.123.123',
'gateway_id': 'mock-gateway',
'identity': 'homeassistant',
'key': 'mock-key',
'import_groups': True
}
assert len(mock_gateway_info.mock_calls) == 1
assert len(mock_entry_setup.mock_calls) == 1