From 2b2502c91c8fbd1f35c0f1654e5fb7776c8cc5b7 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 25 Sep 2018 11:57:32 +0200 Subject: [PATCH] Support old tradfri config format (#16841) --- .../components/tradfri/config_flow.py | 4 ++- tests/components/tradfri/test_config_flow.py | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/tradfri/config_flow.py b/homeassistant/components/tradfri/config_flow.py index 4de43c79e0c..8d8f9af79e6 100644 --- a/homeassistant/components/tradfri/config_flow.py +++ b/homeassistant/components/tradfri/config_flow.py @@ -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] diff --git a/tests/components/tradfri/test_config_flow.py b/tests/components/tradfri/test_config_flow.py index 4650fb5d9bc..580e9580d76 100644 --- a/tests/components/tradfri/test_config_flow.py +++ b/tests/components/tradfri/test_config_flow.py @@ -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