From 42f4a4d4e3e07b73772d3b284c016f6745bcebcc Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Fri, 2 Nov 2018 08:50:34 +0100 Subject: [PATCH 1/6] Add config flow step for manual input Remove support for loading discovery config from json file --- homeassistant/components/deconz/__init__.py | 11 +-- .../components/deconz/config_flow.py | 32 ++++----- homeassistant/components/deconz/const.py | 3 +- tests/components/deconz/test_config_flow.py | 69 ++++++------------- tests/components/deconz/test_init.py | 22 +----- 5 files changed, 45 insertions(+), 92 deletions(-) diff --git a/homeassistant/components/deconz/__init__.py b/homeassistant/components/deconz/__init__.py index c314a1191dba1..4d3e2cbc6a926 100644 --- a/homeassistant/components/deconz/__init__.py +++ b/homeassistant/components/deconz/__init__.py @@ -11,11 +11,10 @@ CONF_API_KEY, CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_STOP) from homeassistant.helpers import config_validation as cv from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC -from homeassistant.util.json import load_json # Loading the config flow file will register the flow from .config_flow import configured_hosts -from .const import CONFIG_FILE, DOMAIN, _LOGGER +from .const import DEFAULT_PORT, DOMAIN, _LOGGER from .gateway import DeconzGateway REQUIREMENTS = ['pydeconz==47'] @@ -27,7 +26,7 @@ DOMAIN: vol.Schema({ vol.Optional(CONF_API_KEY): cv.string, vol.Optional(CONF_HOST): cv.string, - vol.Optional(CONF_PORT, default=80): cv.port, + vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, }) }, extra=vol.ALLOW_EXTRA) @@ -53,11 +52,7 @@ async def async_setup(hass, config): """ if DOMAIN in config: deconz_config = None - config_file = await hass.async_add_job( - load_json, hass.config.path(CONFIG_FILE)) - if config_file: - deconz_config = config_file - elif CONF_HOST in config[DOMAIN]: + if CONF_HOST in config[DOMAIN]: deconz_config = config[DOMAIN] if deconz_config and not configured_hosts(hass): hass.async_add_job(hass.config_entries.flow.async_init( diff --git a/homeassistant/components/deconz/config_flow.py b/homeassistant/components/deconz/config_flow.py index 293b6c1b540ac..db49eda97060f 100644 --- a/homeassistant/components/deconz/config_flow.py +++ b/homeassistant/components/deconz/config_flow.py @@ -6,11 +6,9 @@ from homeassistant.core import callback from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT from homeassistant.helpers import aiohttp_client -from homeassistant.util.json import load_json from .const import ( - CONF_ALLOW_DECONZ_GROUPS, CONF_ALLOW_CLIP_SENSOR, CONFIG_FILE, DOMAIN) - + CONF_ALLOW_DECONZ_GROUPS, CONF_ALLOW_CLIP_SENSOR, DEFAULT_PORT, DOMAIN) CONF_BRIDGEID = 'bridgeid' @@ -47,10 +45,14 @@ async def async_step_user(self, user_input=None): return self.async_abort(reason='one_instance_only') if user_input is not None: - for bridge in self.bridges: - if bridge[CONF_HOST] == user_input[CONF_HOST]: - self.deconz_config = bridge - return await self.async_step_link() + if self.bridges: + for bridge in self.bridges: + if bridge[CONF_HOST] == user_input[CONF_HOST]: + self.deconz_config = bridge + return await self.async_step_link() + else: + self.deconz_config = user_input + return await self.async_step_link() session = aiohttp_client.async_get_clientsession(self.hass) self.bridges = await async_discovery(session) @@ -58,6 +60,7 @@ async def async_step_user(self, user_input=None): if len(self.bridges) == 1: self.deconz_config = self.bridges[0] return await self.async_step_link() + if len(self.bridges) > 1: hosts = [] for bridge in self.bridges: @@ -69,8 +72,12 @@ async def async_step_user(self, user_input=None): }) ) - return self.async_abort( - reason='no_bridges' + return self.async_show_form( + step_id='user', + data_schema=vol.Schema({ + vol.Required(CONF_HOST): str, + vol.Required(CONF_PORT, default=DEFAULT_PORT): int, + }), ) async def async_step_link(self, user_input=None): @@ -135,13 +142,6 @@ async def async_step_discovery(self, discovery_info): deconz_config[CONF_PORT] = discovery_info.get(CONF_PORT) deconz_config[CONF_BRIDGEID] = discovery_info.get('serial') - config_file = await self.hass.async_add_job( - load_json, self.hass.config.path(CONFIG_FILE)) - if config_file and \ - config_file[CONF_HOST] == deconz_config[CONF_HOST] and \ - CONF_API_KEY in config_file: - deconz_config[CONF_API_KEY] = config_file[CONF_API_KEY] - return await self.async_step_import(deconz_config) async def async_step_import(self, import_config): diff --git a/homeassistant/components/deconz/const.py b/homeassistant/components/deconz/const.py index d856d8c14659e..e97c393dd5a75 100644 --- a/homeassistant/components/deconz/const.py +++ b/homeassistant/components/deconz/const.py @@ -4,9 +4,10 @@ _LOGGER = logging.getLogger('homeassistant.components.deconz') DOMAIN = 'deconz' -CONFIG_FILE = 'deconz.conf' DECONZ_DOMAIN = 'deconz' +DEFAULT_PORT = 80 + CONF_ALLOW_CLIP_SENSOR = 'allow_clip_sensor' CONF_ALLOW_DECONZ_GROUPS = 'allow_deconz_groups' diff --git a/tests/components/deconz/test_config_flow.py b/tests/components/deconz/test_config_flow.py index 20b7a88bc055c..60d1f9782f5ea 100644 --- a/tests/components/deconz/test_config_flow.py +++ b/tests/components/deconz/test_config_flow.py @@ -56,7 +56,9 @@ async def test_flow_no_discovered_bridges(hass, aioclient_mock): flow.hass = hass result = await flow.async_step_user() - assert result['type'] == 'abort' + assert result['type'] == 'form' + assert result['step_id'] == 'user' + # assert result['type'] == 'abort' async def test_flow_one_bridge_discovered(hass, aioclient_mock): @@ -107,6 +109,20 @@ async def test_flow_two_bridges_selection(hass, aioclient_mock): assert flow.deconz_config['host'] == '1.2.3.4' +async def test_flow_manual_configuration(hass, aioclient_mock): + """Test config flow with manual input.""" + aioclient_mock.get(pydeconz.utils.URL_DISCOVER, json=[]) + flow = config_flow.DeconzFlowHandler() + flow.hass = hass + + user_input = {'host': '1.2.3.4', 'port': 80} + + result = await flow.async_step_user(user_input) + assert result['type'] == 'form' + assert result['step_id'] == 'link' + assert flow.deconz_config == user_input + + async def test_link_no_api_key(hass, aioclient_mock): """Test config flow should abort if no API key was possible to retrieve.""" aioclient_mock.post('http://1.2.3.4:80/api', json=[]) @@ -138,57 +154,14 @@ async def test_link_already_registered_bridge(hass): async def test_bridge_discovery(hass): - """Test a bridge being discovered with no additional config file.""" + """Test a bridge being discovered.""" flow = config_flow.DeconzFlowHandler() flow.hass = hass - with patch.object(config_flow, 'load_json', return_value={}): - result = await flow.async_step_discovery({ - 'host': '1.2.3.4', - 'port': 80, - 'serial': 'id' - }) - - assert result['type'] == 'form' - assert result['step_id'] == 'link' - - -async def test_bridge_discovery_config_file(hass): - """Test a bridge being discovered with a corresponding config file.""" - flow = config_flow.DeconzFlowHandler() - flow.hass = hass - with patch.object(config_flow, 'load_json', - return_value={'host': '1.2.3.4', - 'port': 8080, - 'api_key': '1234567890ABCDEF'}): - result = await flow.async_step_discovery({ - 'host': '1.2.3.4', - 'port': 80, - 'serial': 'id' - }) - - assert result['type'] == 'create_entry' - assert result['title'] == 'deCONZ-id' - assert result['data'] == { - 'bridgeid': 'id', + result = await flow.async_step_discovery({ 'host': '1.2.3.4', 'port': 80, - 'api_key': '1234567890ABCDEF', - 'allow_clip_sensor': True, - 'allow_deconz_groups': True - } - - -async def test_bridge_discovery_other_config_file(hass): - """Test a bridge being discovered with another bridges config file.""" - flow = config_flow.DeconzFlowHandler() - flow.hass = hass - with patch.object(config_flow, 'load_json', - return_value={'host': '5.6.7.8', 'api_key': '5678'}): - result = await flow.async_step_discovery({ - 'host': '1.2.3.4', - 'port': 80, - 'serial': 'id' - }) + 'serial': 'id' + }) assert result['type'] == 'form' assert result['step_id'] == 'link' diff --git a/tests/components/deconz/test_init.py b/tests/components/deconz/test_init.py index 3453dd86c1221..b83756f6ebbae 100644 --- a/tests/components/deconz/test_init.py +++ b/tests/components/deconz/test_init.py @@ -21,8 +21,7 @@ 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={}): + patch.object(deconz, 'configured_hosts', return_value=[]): assert await async_setup_component(hass, deconz.DOMAIN, { deconz.DOMAIN: { deconz.CONF_HOST: '1.2.3.4', @@ -33,24 +32,10 @@ async def test_config_with_host_passed_to_config_entry(hass): 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={}): + patch.object(deconz, 'configured_hosts', return_value=[]): assert await async_setup_component(hass, deconz.DOMAIN, { deconz.DOMAIN: {} }) is True @@ -62,8 +47,7 @@ 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={}): + return_value=['1.2.3.4']): assert await async_setup_component(hass, deconz.DOMAIN, { deconz.DOMAIN: { deconz.CONF_HOST: '1.2.3.4', From cac75063d4ca0b9cbcfd17869800d31626b2ec60 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Fri, 2 Nov 2018 09:27:43 +0100 Subject: [PATCH 2/6] Small cleanup Fix all translations to step user instead of step init --- .../components/deconz/.translations/bg.json | 2 +- .../components/deconz/.translations/ca.json | 2 +- .../components/deconz/.translations/cs.json | 2 +- .../components/deconz/.translations/cy.json | 2 +- .../components/deconz/.translations/da.json | 2 +- .../components/deconz/.translations/de.json | 2 +- .../components/deconz/.translations/en.json | 4 ++-- .../components/deconz/.translations/es-419.json | 2 +- .../components/deconz/.translations/fr.json | 2 +- .../components/deconz/.translations/he.json | 2 +- .../components/deconz/.translations/hu.json | 2 +- .../components/deconz/.translations/id.json | 2 +- .../components/deconz/.translations/it.json | 2 +- .../components/deconz/.translations/ja.json | 2 +- .../components/deconz/.translations/ko.json | 2 +- .../components/deconz/.translations/lb.json | 2 +- .../components/deconz/.translations/nl.json | 2 +- .../components/deconz/.translations/nn.json | 2 +- .../components/deconz/.translations/no.json | 2 +- .../components/deconz/.translations/pl.json | 2 +- .../components/deconz/.translations/pt-BR.json | 2 +- .../components/deconz/.translations/pt.json | 2 +- .../components/deconz/.translations/ru.json | 2 +- .../components/deconz/.translations/sl.json | 2 +- .../components/deconz/.translations/sv.json | 4 ++-- .../components/deconz/.translations/vi.json | 2 +- .../components/deconz/.translations/zh-Hans.json | 2 +- .../components/deconz/.translations/zh-Hant.json | 2 +- homeassistant/components/deconz/config_flow.py | 14 ++++++-------- homeassistant/components/deconz/strings.json | 4 ++-- tests/components/deconz/test_config_flow.py | 2 -- 31 files changed, 38 insertions(+), 42 deletions(-) diff --git a/homeassistant/components/deconz/.translations/bg.json b/homeassistant/components/deconz/.translations/bg.json index 2ea6576206375..35b83f323d564 100644 --- a/homeassistant/components/deconz/.translations/bg.json +++ b/homeassistant/components/deconz/.translations/bg.json @@ -9,7 +9,7 @@ "no_key": "\u041d\u0435 \u043c\u043e\u0436\u0430 \u0434\u0430 \u0441\u0435 \u043f\u043e\u043b\u0443\u0447\u0438 API \u043a\u043b\u044e\u0447" }, "step": { - "init": { + "user": { "data": { "host": "\u0425\u043e\u0441\u0442", "port": "\u041f\u043e\u0440\u0442 (\u0441\u0442\u043e\u0439\u043d\u043e\u0441\u0442 \u043f\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0431\u0438\u0440\u0430\u043d\u0435: '80')" diff --git a/homeassistant/components/deconz/.translations/ca.json b/homeassistant/components/deconz/.translations/ca.json index 10eb9f5bc7316..1d51136bdb02b 100644 --- a/homeassistant/components/deconz/.translations/ca.json +++ b/homeassistant/components/deconz/.translations/ca.json @@ -9,7 +9,7 @@ "no_key": "No s'ha pogut obtenir una clau API" }, "step": { - "init": { + "user": { "data": { "host": "Amfitri\u00f3", "port": "Port (predeterminat: '80')" diff --git a/homeassistant/components/deconz/.translations/cs.json b/homeassistant/components/deconz/.translations/cs.json index 1588766e406c7..b6dcf31c192df 100644 --- a/homeassistant/components/deconz/.translations/cs.json +++ b/homeassistant/components/deconz/.translations/cs.json @@ -9,7 +9,7 @@ "no_key": "Nelze z\u00edskat kl\u00ed\u010d API" }, "step": { - "init": { + "user": { "data": { "host": "Hostitel", "port": "Port (v\u00fdchoz\u00ed hodnota: '80')" diff --git a/homeassistant/components/deconz/.translations/cy.json b/homeassistant/components/deconz/.translations/cy.json index fff54bb3f6cfd..e8068a5ebe6f4 100644 --- a/homeassistant/components/deconz/.translations/cy.json +++ b/homeassistant/components/deconz/.translations/cy.json @@ -9,7 +9,7 @@ "no_key": "Methu cael allwedd API" }, "step": { - "init": { + "user": { "data": { "host": "Gwesteiwr", "port": "Port (gwerth diofyn: '80')" diff --git a/homeassistant/components/deconz/.translations/da.json b/homeassistant/components/deconz/.translations/da.json index 7f9aad83160d9..4eef8f5fe0902 100644 --- a/homeassistant/components/deconz/.translations/da.json +++ b/homeassistant/components/deconz/.translations/da.json @@ -8,7 +8,7 @@ "no_key": "Kunne ikke f\u00e5 en API-n\u00f8gle" }, "step": { - "init": { + "user": { "data": { "host": "V\u00e6rt", "port": "Port (standardv\u00e6rdi: '80')" diff --git a/homeassistant/components/deconz/.translations/de.json b/homeassistant/components/deconz/.translations/de.json index 645daa56f6bf6..d55dfcd69868b 100644 --- a/homeassistant/components/deconz/.translations/de.json +++ b/homeassistant/components/deconz/.translations/de.json @@ -9,7 +9,7 @@ "no_key": "Es konnte kein API-Schl\u00fcssel abgerufen werden" }, "step": { - "init": { + "user": { "data": { "host": "Host", "port": "Port (Standartwert : '80')" diff --git a/homeassistant/components/deconz/.translations/en.json b/homeassistant/components/deconz/.translations/en.json index f55f64ca43094..47cc8361ed3dc 100644 --- a/homeassistant/components/deconz/.translations/en.json +++ b/homeassistant/components/deconz/.translations/en.json @@ -9,10 +9,10 @@ "no_key": "Couldn't get an API key" }, "step": { - "init": { + "user": { "data": { "host": "Host", - "port": "Port (default value: '80')" + "port": "Port" }, "title": "Define deCONZ gateway" }, diff --git a/homeassistant/components/deconz/.translations/es-419.json b/homeassistant/components/deconz/.translations/es-419.json index ab47a5b43c824..df7bd619b4022 100644 --- a/homeassistant/components/deconz/.translations/es-419.json +++ b/homeassistant/components/deconz/.translations/es-419.json @@ -9,7 +9,7 @@ "no_key": "No se pudo obtener una clave de API" }, "step": { - "init": { + "user": { "data": { "host": "Host", "port": "Puerto (valor predeterminado: '80')" diff --git a/homeassistant/components/deconz/.translations/fr.json b/homeassistant/components/deconz/.translations/fr.json index 56399a3c6fd95..e8e0029b522a2 100644 --- a/homeassistant/components/deconz/.translations/fr.json +++ b/homeassistant/components/deconz/.translations/fr.json @@ -9,7 +9,7 @@ "no_key": "Impossible d'obtenir une cl\u00e9 d'API" }, "step": { - "init": { + "user": { "data": { "host": "H\u00f4te", "port": "Port (valeur par d\u00e9faut : 80)" diff --git a/homeassistant/components/deconz/.translations/he.json b/homeassistant/components/deconz/.translations/he.json index 89a2d69950e41..c980699dea704 100644 --- a/homeassistant/components/deconz/.translations/he.json +++ b/homeassistant/components/deconz/.translations/he.json @@ -9,7 +9,7 @@ "no_key": "\u05dc\u05d0 \u05e0\u05d9\u05ea\u05df \u05d4\u05d9\u05d4 \u05dc\u05e7\u05d1\u05dc \u05de\u05e4\u05ea\u05d7 API" }, "step": { - "init": { + "user": { "data": { "host": "\u05de\u05d0\u05e8\u05d7", "port": "\u05e4\u05d5\u05e8\u05d8 (\u05d1\u05e8\u05d9\u05e8\u05ea \u05de\u05d7\u05d3\u05dc: '80')" diff --git a/homeassistant/components/deconz/.translations/hu.json b/homeassistant/components/deconz/.translations/hu.json index ca2466e992121..68f25fe655c4b 100644 --- a/homeassistant/components/deconz/.translations/hu.json +++ b/homeassistant/components/deconz/.translations/hu.json @@ -9,7 +9,7 @@ "no_key": "API kulcs lek\u00e9r\u00e9se nem siker\u00fclt" }, "step": { - "init": { + "user": { "data": { "host": "H\u00e1zigazda (Host)", "port": "Port (alap\u00e9rtelmezett \u00e9rt\u00e9k: '80')" diff --git a/homeassistant/components/deconz/.translations/id.json b/homeassistant/components/deconz/.translations/id.json index 7d0b3163a40b8..c4d87ed1f8f47 100644 --- a/homeassistant/components/deconz/.translations/id.json +++ b/homeassistant/components/deconz/.translations/id.json @@ -9,7 +9,7 @@ "no_key": "Tidak bisa mendapatkan kunci API" }, "step": { - "init": { + "user": { "data": { "host": "Host", "port": "Port (nilai default: '80')" diff --git a/homeassistant/components/deconz/.translations/it.json b/homeassistant/components/deconz/.translations/it.json index 87dcd0610f2cc..2f0ff80250017 100644 --- a/homeassistant/components/deconz/.translations/it.json +++ b/homeassistant/components/deconz/.translations/it.json @@ -9,7 +9,7 @@ "no_key": "Impossibile ottenere una API key" }, "step": { - "init": { + "user": { "data": { "host": "Host", "port": "Porta (valore di default: '80')" diff --git a/homeassistant/components/deconz/.translations/ja.json b/homeassistant/components/deconz/.translations/ja.json index 5148ebeaa86b2..65aff94c988cd 100644 --- a/homeassistant/components/deconz/.translations/ja.json +++ b/homeassistant/components/deconz/.translations/ja.json @@ -4,7 +4,7 @@ "no_key": "API\u30ad\u30fc\u3092\u53d6\u5f97\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f" }, "step": { - "init": { + "user": { "data": { "host": "\u30db\u30b9\u30c8", "port": "\u30dd\u30fc\u30c8\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\uff1a'80'\uff09" diff --git a/homeassistant/components/deconz/.translations/ko.json b/homeassistant/components/deconz/.translations/ko.json index a501951540b3e..6ac260b570bb9 100644 --- a/homeassistant/components/deconz/.translations/ko.json +++ b/homeassistant/components/deconz/.translations/ko.json @@ -9,7 +9,7 @@ "no_key": "API \ud0a4\ub97c \uac00\uc838\uc62c \uc218 \uc5c6\uc2b5\ub2c8\ub2e4" }, "step": { - "init": { + "user": { "data": { "host": "\ud638\uc2a4\ud2b8", "port": "\ud3ec\ud2b8 (\uae30\ubcf8\uac12: '80')" diff --git a/homeassistant/components/deconz/.translations/lb.json b/homeassistant/components/deconz/.translations/lb.json index 3de7de9ddb3e6..7fea1abfacb29 100644 --- a/homeassistant/components/deconz/.translations/lb.json +++ b/homeassistant/components/deconz/.translations/lb.json @@ -9,7 +9,7 @@ "no_key": "Konnt keen API Schl\u00ebssel kr\u00e9ien" }, "step": { - "init": { + "user": { "data": { "host": "Host", "port": "Port (Standard Wert: '80')" diff --git a/homeassistant/components/deconz/.translations/nl.json b/homeassistant/components/deconz/.translations/nl.json index 9084d22f4a303..88e843476091a 100644 --- a/homeassistant/components/deconz/.translations/nl.json +++ b/homeassistant/components/deconz/.translations/nl.json @@ -9,7 +9,7 @@ "no_key": "Kon geen API-sleutel ophalen" }, "step": { - "init": { + "user": { "data": { "host": "Host", "port": "Poort (standaard: '80')" diff --git a/homeassistant/components/deconz/.translations/nn.json b/homeassistant/components/deconz/.translations/nn.json index 4bdc4b4c1bee3..cf9133aeb88bb 100644 --- a/homeassistant/components/deconz/.translations/nn.json +++ b/homeassistant/components/deconz/.translations/nn.json @@ -9,7 +9,7 @@ "no_key": "Kunne ikkje f\u00e5 ein API-n\u00f8kkel" }, "step": { - "init": { + "user": { "data": { "host": "Vert", "port": "Port (standardverdi: '80')" diff --git a/homeassistant/components/deconz/.translations/no.json b/homeassistant/components/deconz/.translations/no.json index 27868814eab24..1d25519d830ad 100644 --- a/homeassistant/components/deconz/.translations/no.json +++ b/homeassistant/components/deconz/.translations/no.json @@ -9,7 +9,7 @@ "no_key": "Kunne ikke f\u00e5 en API-n\u00f8kkel" }, "step": { - "init": { + "user": { "data": { "host": "Vert", "port": "Port (standardverdi: '80')" diff --git a/homeassistant/components/deconz/.translations/pl.json b/homeassistant/components/deconz/.translations/pl.json index 5dd87d9e46214..f5697a3894b8c 100644 --- a/homeassistant/components/deconz/.translations/pl.json +++ b/homeassistant/components/deconz/.translations/pl.json @@ -9,7 +9,7 @@ "no_key": "Nie mo\u017cna uzyska\u0107 klucza API" }, "step": { - "init": { + "user": { "data": { "host": "Host", "port": "Port (warto\u015b\u0107 domy\u015blna: \"80\")" diff --git a/homeassistant/components/deconz/.translations/pt-BR.json b/homeassistant/components/deconz/.translations/pt-BR.json index be79e7e461ae0..2b76cdbdd4e5f 100644 --- a/homeassistant/components/deconz/.translations/pt-BR.json +++ b/homeassistant/components/deconz/.translations/pt-BR.json @@ -9,7 +9,7 @@ "no_key": "N\u00e3o foi poss\u00edvel obter uma chave de API" }, "step": { - "init": { + "user": { "data": { "host": "Hospedeiro", "port": "Porta (valor padr\u00e3o: '80')" diff --git a/homeassistant/components/deconz/.translations/pt.json b/homeassistant/components/deconz/.translations/pt.json index a0419b8baa42d..e4a2f4ca7cb38 100644 --- a/homeassistant/components/deconz/.translations/pt.json +++ b/homeassistant/components/deconz/.translations/pt.json @@ -9,7 +9,7 @@ "no_key": "N\u00e3o foi poss\u00edvel obter uma chave de API" }, "step": { - "init": { + "user": { "data": { "host": "Servidor", "port": "Porta (por omiss\u00e3o: '80')" diff --git a/homeassistant/components/deconz/.translations/ru.json b/homeassistant/components/deconz/.translations/ru.json index a9b66314f3152..ed4a06b299325 100644 --- a/homeassistant/components/deconz/.translations/ru.json +++ b/homeassistant/components/deconz/.translations/ru.json @@ -9,7 +9,7 @@ "no_key": "\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043b\u044e\u0447 API" }, "step": { - "init": { + "user": { "data": { "host": "\u0425\u043e\u0441\u0442", "port": "\u041f\u043e\u0440\u0442 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e: '80')" diff --git a/homeassistant/components/deconz/.translations/sl.json b/homeassistant/components/deconz/.translations/sl.json index bc7a2cbd86158..07f9537c0f567 100644 --- a/homeassistant/components/deconz/.translations/sl.json +++ b/homeassistant/components/deconz/.translations/sl.json @@ -9,7 +9,7 @@ "no_key": "Klju\u010da API ni mogo\u010de dobiti" }, "step": { - "init": { + "user": { "data": { "host": "Gostitelj", "port": "Vrata (privzeta vrednost: '80')" diff --git a/homeassistant/components/deconz/.translations/sv.json b/homeassistant/components/deconz/.translations/sv.json index 88cf8742acde8..3b449217f6381 100644 --- a/homeassistant/components/deconz/.translations/sv.json +++ b/homeassistant/components/deconz/.translations/sv.json @@ -10,9 +10,9 @@ }, "step": { "init": { - "data": { + "user": { "host": "V\u00e4rd", - "port": "Port (standardv\u00e4rde: '80')" + "port": "Port" }, "title": "Definiera deCONZ-gatewaye" }, diff --git a/homeassistant/components/deconz/.translations/vi.json b/homeassistant/components/deconz/.translations/vi.json index 00f1d9be57f07..20a9652f27ac8 100644 --- a/homeassistant/components/deconz/.translations/vi.json +++ b/homeassistant/components/deconz/.translations/vi.json @@ -9,7 +9,7 @@ "no_key": "Kh\u00f4ng th\u1ec3 l\u1ea5y kh\u00f3a API" }, "step": { - "init": { + "user": { "data": { "port": "C\u1ed5ng (gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh: '80')" } diff --git a/homeassistant/components/deconz/.translations/zh-Hans.json b/homeassistant/components/deconz/.translations/zh-Hans.json index 2e5a216c77dde..10a758c1ecffd 100644 --- a/homeassistant/components/deconz/.translations/zh-Hans.json +++ b/homeassistant/components/deconz/.translations/zh-Hans.json @@ -9,7 +9,7 @@ "no_key": "\u65e0\u6cd5\u83b7\u53d6 API \u5bc6\u94a5" }, "step": { - "init": { + "user": { "data": { "host": "\u4e3b\u673a", "port": "\u7aef\u53e3\uff08\u9ed8\u8ba4\u503c\uff1a'80'\uff09" diff --git a/homeassistant/components/deconz/.translations/zh-Hant.json b/homeassistant/components/deconz/.translations/zh-Hant.json index 524f68d41bc05..daf26a15bca15 100644 --- a/homeassistant/components/deconz/.translations/zh-Hant.json +++ b/homeassistant/components/deconz/.translations/zh-Hant.json @@ -9,7 +9,7 @@ "no_key": "\u7121\u6cd5\u53d6\u5f97 API key" }, "step": { - "init": { + "user": { "data": { "host": "\u4e3b\u6a5f\u7aef", "port": "\u901a\u8a0a\u57e0\uff08\u9810\u8a2d\u503c\uff1a'80'\uff09" diff --git a/homeassistant/components/deconz/config_flow.py b/homeassistant/components/deconz/config_flow.py index db49eda97060f..93bef6fee1c18 100644 --- a/homeassistant/components/deconz/config_flow.py +++ b/homeassistant/components/deconz/config_flow.py @@ -45,14 +45,12 @@ async def async_step_user(self, user_input=None): return self.async_abort(reason='one_instance_only') if user_input is not None: - if self.bridges: - for bridge in self.bridges: - if bridge[CONF_HOST] == user_input[CONF_HOST]: - self.deconz_config = bridge - return await self.async_step_link() - else: - self.deconz_config = user_input - return await self.async_step_link() + for bridge in self.bridges: + if bridge[CONF_HOST] == user_input[CONF_HOST]: + self.deconz_config = bridge + return await self.async_step_link() + self.deconz_config = user_input + return await self.async_step_link() session = aiohttp_client.async_get_clientsession(self.hass) self.bridges = await async_discovery(session) diff --git a/homeassistant/components/deconz/strings.json b/homeassistant/components/deconz/strings.json index 09549a300a0d3..b2ec0ae55d385 100644 --- a/homeassistant/components/deconz/strings.json +++ b/homeassistant/components/deconz/strings.json @@ -2,11 +2,11 @@ "config": { "title": "deCONZ Zigbee gateway", "step": { - "init": { + "user": { "title": "Define deCONZ gateway", "data": { "host": "Host", - "port": "Port (default value: '80')" + "port": "Port" } }, "link": { diff --git a/tests/components/deconz/test_config_flow.py b/tests/components/deconz/test_config_flow.py index 60d1f9782f5ea..49b086efff6e4 100644 --- a/tests/components/deconz/test_config_flow.py +++ b/tests/components/deconz/test_config_flow.py @@ -1,5 +1,4 @@ """Tests for deCONZ config flow.""" -from unittest.mock import patch import pytest import voluptuous as vol @@ -58,7 +57,6 @@ async def test_flow_no_discovered_bridges(hass, aioclient_mock): result = await flow.async_step_user() assert result['type'] == 'form' assert result['step_id'] == 'user' - # assert result['type'] == 'abort' async def test_flow_one_bridge_discovered(hass, aioclient_mock): From 69e30f8ac01b9016bad9c59f189d9dda399f6878 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Mon, 5 Nov 2018 21:28:49 +0100 Subject: [PATCH 3/6] Revert to using step_init --- .../components/deconz/.translations/bg.json | 2 +- .../components/deconz/.translations/ca.json | 2 +- .../components/deconz/.translations/cs.json | 2 +- .../components/deconz/.translations/cy.json | 2 +- .../components/deconz/.translations/da.json | 2 +- .../components/deconz/.translations/de.json | 2 +- .../components/deconz/.translations/en.json | 2 +- .../components/deconz/.translations/es-419.json | 2 +- .../components/deconz/.translations/fr.json | 2 +- .../components/deconz/.translations/he.json | 2 +- .../components/deconz/.translations/hu.json | 2 +- .../components/deconz/.translations/id.json | 2 +- .../components/deconz/.translations/it.json | 2 +- .../components/deconz/.translations/ja.json | 2 +- .../components/deconz/.translations/ko.json | 2 +- .../components/deconz/.translations/lb.json | 2 +- .../components/deconz/.translations/nl.json | 2 +- .../components/deconz/.translations/nn.json | 2 +- .../components/deconz/.translations/no.json | 2 +- .../components/deconz/.translations/pl.json | 2 +- .../components/deconz/.translations/pt-BR.json | 2 +- .../components/deconz/.translations/pt.json | 2 +- .../components/deconz/.translations/ru.json | 2 +- .../components/deconz/.translations/sl.json | 2 +- .../components/deconz/.translations/sv.json | 2 +- .../components/deconz/.translations/vi.json | 2 +- .../components/deconz/.translations/zh-Hans.json | 2 +- .../components/deconz/.translations/zh-Hant.json | 2 +- homeassistant/components/deconz/config_flow.py | 6 +++++- homeassistant/components/deconz/strings.json | 2 +- tests/components/deconz/test_config_flow.py | 14 +++++++------- 31 files changed, 41 insertions(+), 37 deletions(-) diff --git a/homeassistant/components/deconz/.translations/bg.json b/homeassistant/components/deconz/.translations/bg.json index 35b83f323d564..2ea6576206375 100644 --- a/homeassistant/components/deconz/.translations/bg.json +++ b/homeassistant/components/deconz/.translations/bg.json @@ -9,7 +9,7 @@ "no_key": "\u041d\u0435 \u043c\u043e\u0436\u0430 \u0434\u0430 \u0441\u0435 \u043f\u043e\u043b\u0443\u0447\u0438 API \u043a\u043b\u044e\u0447" }, "step": { - "user": { + "init": { "data": { "host": "\u0425\u043e\u0441\u0442", "port": "\u041f\u043e\u0440\u0442 (\u0441\u0442\u043e\u0439\u043d\u043e\u0441\u0442 \u043f\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0431\u0438\u0440\u0430\u043d\u0435: '80')" diff --git a/homeassistant/components/deconz/.translations/ca.json b/homeassistant/components/deconz/.translations/ca.json index 1d51136bdb02b..10eb9f5bc7316 100644 --- a/homeassistant/components/deconz/.translations/ca.json +++ b/homeassistant/components/deconz/.translations/ca.json @@ -9,7 +9,7 @@ "no_key": "No s'ha pogut obtenir una clau API" }, "step": { - "user": { + "init": { "data": { "host": "Amfitri\u00f3", "port": "Port (predeterminat: '80')" diff --git a/homeassistant/components/deconz/.translations/cs.json b/homeassistant/components/deconz/.translations/cs.json index b6dcf31c192df..1588766e406c7 100644 --- a/homeassistant/components/deconz/.translations/cs.json +++ b/homeassistant/components/deconz/.translations/cs.json @@ -9,7 +9,7 @@ "no_key": "Nelze z\u00edskat kl\u00ed\u010d API" }, "step": { - "user": { + "init": { "data": { "host": "Hostitel", "port": "Port (v\u00fdchoz\u00ed hodnota: '80')" diff --git a/homeassistant/components/deconz/.translations/cy.json b/homeassistant/components/deconz/.translations/cy.json index e8068a5ebe6f4..fff54bb3f6cfd 100644 --- a/homeassistant/components/deconz/.translations/cy.json +++ b/homeassistant/components/deconz/.translations/cy.json @@ -9,7 +9,7 @@ "no_key": "Methu cael allwedd API" }, "step": { - "user": { + "init": { "data": { "host": "Gwesteiwr", "port": "Port (gwerth diofyn: '80')" diff --git a/homeassistant/components/deconz/.translations/da.json b/homeassistant/components/deconz/.translations/da.json index 4eef8f5fe0902..7f9aad83160d9 100644 --- a/homeassistant/components/deconz/.translations/da.json +++ b/homeassistant/components/deconz/.translations/da.json @@ -8,7 +8,7 @@ "no_key": "Kunne ikke f\u00e5 en API-n\u00f8gle" }, "step": { - "user": { + "init": { "data": { "host": "V\u00e6rt", "port": "Port (standardv\u00e6rdi: '80')" diff --git a/homeassistant/components/deconz/.translations/de.json b/homeassistant/components/deconz/.translations/de.json index d55dfcd69868b..645daa56f6bf6 100644 --- a/homeassistant/components/deconz/.translations/de.json +++ b/homeassistant/components/deconz/.translations/de.json @@ -9,7 +9,7 @@ "no_key": "Es konnte kein API-Schl\u00fcssel abgerufen werden" }, "step": { - "user": { + "init": { "data": { "host": "Host", "port": "Port (Standartwert : '80')" diff --git a/homeassistant/components/deconz/.translations/en.json b/homeassistant/components/deconz/.translations/en.json index 47cc8361ed3dc..0c60953db5648 100644 --- a/homeassistant/components/deconz/.translations/en.json +++ b/homeassistant/components/deconz/.translations/en.json @@ -9,7 +9,7 @@ "no_key": "Couldn't get an API key" }, "step": { - "user": { + "init": { "data": { "host": "Host", "port": "Port" diff --git a/homeassistant/components/deconz/.translations/es-419.json b/homeassistant/components/deconz/.translations/es-419.json index df7bd619b4022..ab47a5b43c824 100644 --- a/homeassistant/components/deconz/.translations/es-419.json +++ b/homeassistant/components/deconz/.translations/es-419.json @@ -9,7 +9,7 @@ "no_key": "No se pudo obtener una clave de API" }, "step": { - "user": { + "init": { "data": { "host": "Host", "port": "Puerto (valor predeterminado: '80')" diff --git a/homeassistant/components/deconz/.translations/fr.json b/homeassistant/components/deconz/.translations/fr.json index e8e0029b522a2..56399a3c6fd95 100644 --- a/homeassistant/components/deconz/.translations/fr.json +++ b/homeassistant/components/deconz/.translations/fr.json @@ -9,7 +9,7 @@ "no_key": "Impossible d'obtenir une cl\u00e9 d'API" }, "step": { - "user": { + "init": { "data": { "host": "H\u00f4te", "port": "Port (valeur par d\u00e9faut : 80)" diff --git a/homeassistant/components/deconz/.translations/he.json b/homeassistant/components/deconz/.translations/he.json index c980699dea704..89a2d69950e41 100644 --- a/homeassistant/components/deconz/.translations/he.json +++ b/homeassistant/components/deconz/.translations/he.json @@ -9,7 +9,7 @@ "no_key": "\u05dc\u05d0 \u05e0\u05d9\u05ea\u05df \u05d4\u05d9\u05d4 \u05dc\u05e7\u05d1\u05dc \u05de\u05e4\u05ea\u05d7 API" }, "step": { - "user": { + "init": { "data": { "host": "\u05de\u05d0\u05e8\u05d7", "port": "\u05e4\u05d5\u05e8\u05d8 (\u05d1\u05e8\u05d9\u05e8\u05ea \u05de\u05d7\u05d3\u05dc: '80')" diff --git a/homeassistant/components/deconz/.translations/hu.json b/homeassistant/components/deconz/.translations/hu.json index 68f25fe655c4b..ca2466e992121 100644 --- a/homeassistant/components/deconz/.translations/hu.json +++ b/homeassistant/components/deconz/.translations/hu.json @@ -9,7 +9,7 @@ "no_key": "API kulcs lek\u00e9r\u00e9se nem siker\u00fclt" }, "step": { - "user": { + "init": { "data": { "host": "H\u00e1zigazda (Host)", "port": "Port (alap\u00e9rtelmezett \u00e9rt\u00e9k: '80')" diff --git a/homeassistant/components/deconz/.translations/id.json b/homeassistant/components/deconz/.translations/id.json index c4d87ed1f8f47..7d0b3163a40b8 100644 --- a/homeassistant/components/deconz/.translations/id.json +++ b/homeassistant/components/deconz/.translations/id.json @@ -9,7 +9,7 @@ "no_key": "Tidak bisa mendapatkan kunci API" }, "step": { - "user": { + "init": { "data": { "host": "Host", "port": "Port (nilai default: '80')" diff --git a/homeassistant/components/deconz/.translations/it.json b/homeassistant/components/deconz/.translations/it.json index 2f0ff80250017..87dcd0610f2cc 100644 --- a/homeassistant/components/deconz/.translations/it.json +++ b/homeassistant/components/deconz/.translations/it.json @@ -9,7 +9,7 @@ "no_key": "Impossibile ottenere una API key" }, "step": { - "user": { + "init": { "data": { "host": "Host", "port": "Porta (valore di default: '80')" diff --git a/homeassistant/components/deconz/.translations/ja.json b/homeassistant/components/deconz/.translations/ja.json index 65aff94c988cd..5148ebeaa86b2 100644 --- a/homeassistant/components/deconz/.translations/ja.json +++ b/homeassistant/components/deconz/.translations/ja.json @@ -4,7 +4,7 @@ "no_key": "API\u30ad\u30fc\u3092\u53d6\u5f97\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f" }, "step": { - "user": { + "init": { "data": { "host": "\u30db\u30b9\u30c8", "port": "\u30dd\u30fc\u30c8\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\uff1a'80'\uff09" diff --git a/homeassistant/components/deconz/.translations/ko.json b/homeassistant/components/deconz/.translations/ko.json index 6ac260b570bb9..a501951540b3e 100644 --- a/homeassistant/components/deconz/.translations/ko.json +++ b/homeassistant/components/deconz/.translations/ko.json @@ -9,7 +9,7 @@ "no_key": "API \ud0a4\ub97c \uac00\uc838\uc62c \uc218 \uc5c6\uc2b5\ub2c8\ub2e4" }, "step": { - "user": { + "init": { "data": { "host": "\ud638\uc2a4\ud2b8", "port": "\ud3ec\ud2b8 (\uae30\ubcf8\uac12: '80')" diff --git a/homeassistant/components/deconz/.translations/lb.json b/homeassistant/components/deconz/.translations/lb.json index 7fea1abfacb29..3de7de9ddb3e6 100644 --- a/homeassistant/components/deconz/.translations/lb.json +++ b/homeassistant/components/deconz/.translations/lb.json @@ -9,7 +9,7 @@ "no_key": "Konnt keen API Schl\u00ebssel kr\u00e9ien" }, "step": { - "user": { + "init": { "data": { "host": "Host", "port": "Port (Standard Wert: '80')" diff --git a/homeassistant/components/deconz/.translations/nl.json b/homeassistant/components/deconz/.translations/nl.json index 88e843476091a..9084d22f4a303 100644 --- a/homeassistant/components/deconz/.translations/nl.json +++ b/homeassistant/components/deconz/.translations/nl.json @@ -9,7 +9,7 @@ "no_key": "Kon geen API-sleutel ophalen" }, "step": { - "user": { + "init": { "data": { "host": "Host", "port": "Poort (standaard: '80')" diff --git a/homeassistant/components/deconz/.translations/nn.json b/homeassistant/components/deconz/.translations/nn.json index cf9133aeb88bb..4bdc4b4c1bee3 100644 --- a/homeassistant/components/deconz/.translations/nn.json +++ b/homeassistant/components/deconz/.translations/nn.json @@ -9,7 +9,7 @@ "no_key": "Kunne ikkje f\u00e5 ein API-n\u00f8kkel" }, "step": { - "user": { + "init": { "data": { "host": "Vert", "port": "Port (standardverdi: '80')" diff --git a/homeassistant/components/deconz/.translations/no.json b/homeassistant/components/deconz/.translations/no.json index 1d25519d830ad..27868814eab24 100644 --- a/homeassistant/components/deconz/.translations/no.json +++ b/homeassistant/components/deconz/.translations/no.json @@ -9,7 +9,7 @@ "no_key": "Kunne ikke f\u00e5 en API-n\u00f8kkel" }, "step": { - "user": { + "init": { "data": { "host": "Vert", "port": "Port (standardverdi: '80')" diff --git a/homeassistant/components/deconz/.translations/pl.json b/homeassistant/components/deconz/.translations/pl.json index f5697a3894b8c..5dd87d9e46214 100644 --- a/homeassistant/components/deconz/.translations/pl.json +++ b/homeassistant/components/deconz/.translations/pl.json @@ -9,7 +9,7 @@ "no_key": "Nie mo\u017cna uzyska\u0107 klucza API" }, "step": { - "user": { + "init": { "data": { "host": "Host", "port": "Port (warto\u015b\u0107 domy\u015blna: \"80\")" diff --git a/homeassistant/components/deconz/.translations/pt-BR.json b/homeassistant/components/deconz/.translations/pt-BR.json index 2b76cdbdd4e5f..be79e7e461ae0 100644 --- a/homeassistant/components/deconz/.translations/pt-BR.json +++ b/homeassistant/components/deconz/.translations/pt-BR.json @@ -9,7 +9,7 @@ "no_key": "N\u00e3o foi poss\u00edvel obter uma chave de API" }, "step": { - "user": { + "init": { "data": { "host": "Hospedeiro", "port": "Porta (valor padr\u00e3o: '80')" diff --git a/homeassistant/components/deconz/.translations/pt.json b/homeassistant/components/deconz/.translations/pt.json index e4a2f4ca7cb38..a0419b8baa42d 100644 --- a/homeassistant/components/deconz/.translations/pt.json +++ b/homeassistant/components/deconz/.translations/pt.json @@ -9,7 +9,7 @@ "no_key": "N\u00e3o foi poss\u00edvel obter uma chave de API" }, "step": { - "user": { + "init": { "data": { "host": "Servidor", "port": "Porta (por omiss\u00e3o: '80')" diff --git a/homeassistant/components/deconz/.translations/ru.json b/homeassistant/components/deconz/.translations/ru.json index ed4a06b299325..a9b66314f3152 100644 --- a/homeassistant/components/deconz/.translations/ru.json +++ b/homeassistant/components/deconz/.translations/ru.json @@ -9,7 +9,7 @@ "no_key": "\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043b\u044e\u0447 API" }, "step": { - "user": { + "init": { "data": { "host": "\u0425\u043e\u0441\u0442", "port": "\u041f\u043e\u0440\u0442 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e: '80')" diff --git a/homeassistant/components/deconz/.translations/sl.json b/homeassistant/components/deconz/.translations/sl.json index 07f9537c0f567..bc7a2cbd86158 100644 --- a/homeassistant/components/deconz/.translations/sl.json +++ b/homeassistant/components/deconz/.translations/sl.json @@ -9,7 +9,7 @@ "no_key": "Klju\u010da API ni mogo\u010de dobiti" }, "step": { - "user": { + "init": { "data": { "host": "Gostitelj", "port": "Vrata (privzeta vrednost: '80')" diff --git a/homeassistant/components/deconz/.translations/sv.json b/homeassistant/components/deconz/.translations/sv.json index 3b449217f6381..a5d64a7a3296f 100644 --- a/homeassistant/components/deconz/.translations/sv.json +++ b/homeassistant/components/deconz/.translations/sv.json @@ -10,7 +10,7 @@ }, "step": { "init": { - "user": { + "init": { "host": "V\u00e4rd", "port": "Port" }, diff --git a/homeassistant/components/deconz/.translations/vi.json b/homeassistant/components/deconz/.translations/vi.json index 20a9652f27ac8..00f1d9be57f07 100644 --- a/homeassistant/components/deconz/.translations/vi.json +++ b/homeassistant/components/deconz/.translations/vi.json @@ -9,7 +9,7 @@ "no_key": "Kh\u00f4ng th\u1ec3 l\u1ea5y kh\u00f3a API" }, "step": { - "user": { + "init": { "data": { "port": "C\u1ed5ng (gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh: '80')" } diff --git a/homeassistant/components/deconz/.translations/zh-Hans.json b/homeassistant/components/deconz/.translations/zh-Hans.json index 10a758c1ecffd..2e5a216c77dde 100644 --- a/homeassistant/components/deconz/.translations/zh-Hans.json +++ b/homeassistant/components/deconz/.translations/zh-Hans.json @@ -9,7 +9,7 @@ "no_key": "\u65e0\u6cd5\u83b7\u53d6 API \u5bc6\u94a5" }, "step": { - "user": { + "init": { "data": { "host": "\u4e3b\u673a", "port": "\u7aef\u53e3\uff08\u9ed8\u8ba4\u503c\uff1a'80'\uff09" diff --git a/homeassistant/components/deconz/.translations/zh-Hant.json b/homeassistant/components/deconz/.translations/zh-Hant.json index daf26a15bca15..524f68d41bc05 100644 --- a/homeassistant/components/deconz/.translations/zh-Hant.json +++ b/homeassistant/components/deconz/.translations/zh-Hant.json @@ -9,7 +9,7 @@ "no_key": "\u7121\u6cd5\u53d6\u5f97 API key" }, "step": { - "user": { + "init": { "data": { "host": "\u4e3b\u6a5f\u7aef", "port": "\u901a\u8a0a\u57e0\uff08\u9810\u8a2d\u503c\uff1a'80'\uff09" diff --git a/homeassistant/components/deconz/config_flow.py b/homeassistant/components/deconz/config_flow.py index 93bef6fee1c18..f7bc71a23987e 100644 --- a/homeassistant/components/deconz/config_flow.py +++ b/homeassistant/components/deconz/config_flow.py @@ -33,6 +33,10 @@ def __init__(self): self.deconz_config = {} async def async_step_user(self, user_input=None): + """Handle a flow initialized by the user.""" + return await self.async_step_init(user_input) + + async def async_step_init(self, user_input=None): """Handle a deCONZ config flow start. Only allows one instance to be set up. @@ -64,7 +68,7 @@ async def async_step_user(self, user_input=None): for bridge in self.bridges: hosts.append(bridge[CONF_HOST]) return self.async_show_form( - step_id='user', + step_id='init', data_schema=vol.Schema({ vol.Required(CONF_HOST): vol.In(hosts) }) diff --git a/homeassistant/components/deconz/strings.json b/homeassistant/components/deconz/strings.json index b2ec0ae55d385..9ab7b56c0ca6e 100644 --- a/homeassistant/components/deconz/strings.json +++ b/homeassistant/components/deconz/strings.json @@ -2,7 +2,7 @@ "config": { "title": "deCONZ Zigbee gateway", "step": { - "user": { + "init": { "title": "Define deCONZ gateway", "data": { "host": "Host", diff --git a/tests/components/deconz/test_config_flow.py b/tests/components/deconz/test_config_flow.py index 49b086efff6e4..9e1d6a2fca1e6 100644 --- a/tests/components/deconz/test_config_flow.py +++ b/tests/components/deconz/test_config_flow.py @@ -44,7 +44,7 @@ async def test_flow_already_registered_bridge(hass): flow = config_flow.DeconzFlowHandler() flow.hass = hass - result = await flow.async_step_user() + result = await flow.async_step_init() assert result['type'] == 'abort' @@ -54,7 +54,7 @@ async def test_flow_no_discovered_bridges(hass, aioclient_mock): flow = config_flow.DeconzFlowHandler() flow.hass = hass - result = await flow.async_step_user() + result = await flow.async_step_init() assert result['type'] == 'form' assert result['step_id'] == 'user' @@ -67,7 +67,7 @@ async def test_flow_one_bridge_discovered(hass, aioclient_mock): flow = config_flow.DeconzFlowHandler() flow.hass = hass - result = await flow.async_step_user() + result = await flow.async_step_init() assert result['type'] == 'form' assert result['step_id'] == 'link' @@ -81,9 +81,9 @@ async def test_flow_two_bridges_discovered(hass, aioclient_mock): flow = config_flow.DeconzFlowHandler() flow.hass = hass - result = await flow.async_step_user() + result = await flow.async_step_init() assert result['type'] == 'form' - assert result['step_id'] == 'user' + assert result['step_id'] == 'init' with pytest.raises(vol.Invalid): assert result['data_schema']({'host': '0.0.0.0'}) @@ -101,7 +101,7 @@ async def test_flow_two_bridges_selection(hass, aioclient_mock): {'bridgeid': 'id2', 'host': '5.6.7.8', 'port': 80} ] - result = await flow.async_step_user(user_input={'host': '1.2.3.4'}) + result = await flow.async_step_init(user_input={'host': '1.2.3.4'}) assert result['type'] == 'form' assert result['step_id'] == 'link' assert flow.deconz_config['host'] == '1.2.3.4' @@ -115,7 +115,7 @@ async def test_flow_manual_configuration(hass, aioclient_mock): user_input = {'host': '1.2.3.4', 'port': 80} - result = await flow.async_step_user(user_input) + result = await flow.async_step_init(user_input) assert result['type'] == 'form' assert result['step_id'] == 'link' assert flow.deconz_config == user_input From c0aa62957551c01c584f7d37ecf986fcf68ac85b Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Mon, 5 Nov 2018 21:33:24 +0100 Subject: [PATCH 4/6] Small cleanup Add test_gateway that was forgotten in a previous PR --- .../components/deconz/.translations/sv.json | 2 +- homeassistant/components/deconz/const.py | 1 - tests/components/deconz/test_gateway.py | 221 ++++++++++++++++++ 3 files changed, 222 insertions(+), 2 deletions(-) create mode 100644 tests/components/deconz/test_gateway.py diff --git a/homeassistant/components/deconz/.translations/sv.json b/homeassistant/components/deconz/.translations/sv.json index a5d64a7a3296f..3ab3dae6dcd5b 100644 --- a/homeassistant/components/deconz/.translations/sv.json +++ b/homeassistant/components/deconz/.translations/sv.json @@ -10,7 +10,7 @@ }, "step": { "init": { - "init": { + "data": { "host": "V\u00e4rd", "port": "Port" }, diff --git a/homeassistant/components/deconz/const.py b/homeassistant/components/deconz/const.py index e97c393dd5a75..b08f3d7182428 100644 --- a/homeassistant/components/deconz/const.py +++ b/homeassistant/components/deconz/const.py @@ -4,7 +4,6 @@ _LOGGER = logging.getLogger('homeassistant.components.deconz') DOMAIN = 'deconz' -DECONZ_DOMAIN = 'deconz' DEFAULT_PORT = 80 diff --git a/tests/components/deconz/test_gateway.py b/tests/components/deconz/test_gateway.py new file mode 100644 index 0000000000000..5f7c1dfcfceea --- /dev/null +++ b/tests/components/deconz/test_gateway.py @@ -0,0 +1,221 @@ +"""Test deCONZ gateway.""" +from unittest.mock import Mock, patch + +from homeassistant.components.deconz import gateway + +from tests.common import mock_coro + +ENTRY_CONFIG = { + "host": "1.2.3.4", + "port": 80, + "api_key": "1234567890ABCDEF", + "bridgeid": "0123456789ABCDEF", + "allow_clip_sensor": True, + "allow_deconz_groups": True, +} + + +async def test_gateway_setup(): + """Successful setup.""" + hass = Mock() + entry = Mock() + entry.data = ENTRY_CONFIG + api = Mock() + api.async_add_remote.return_value = Mock() + api.sensors = {} + + deconz_gateway = gateway.DeconzGateway(hass, entry) + + with patch.object(gateway, 'get_gateway', return_value=mock_coro(api)), \ + patch.object( + gateway, 'async_dispatcher_connect', return_value=Mock()): + assert await deconz_gateway.async_setup() is True + + assert deconz_gateway.api is api + assert len(hass.config_entries.async_forward_entry_setup.mock_calls) == 6 + assert hass.config_entries.async_forward_entry_setup.mock_calls[0][1] == \ + (entry, 'binary_sensor') + assert hass.config_entries.async_forward_entry_setup.mock_calls[1][1] == \ + (entry, 'cover') + assert hass.config_entries.async_forward_entry_setup.mock_calls[2][1] == \ + (entry, 'light') + assert hass.config_entries.async_forward_entry_setup.mock_calls[3][1] == \ + (entry, 'scene') + assert hass.config_entries.async_forward_entry_setup.mock_calls[4][1] == \ + (entry, 'sensor') + assert hass.config_entries.async_forward_entry_setup.mock_calls[5][1] == \ + (entry, 'switch') + assert len(api.start.mock_calls) == 1 + + +async def test_gateway_retry(): + """Retry setup.""" + hass = Mock() + entry = Mock() + entry.data = ENTRY_CONFIG + + deconz_gateway = gateway.DeconzGateway(hass, entry) + + with patch.object(gateway, 'get_gateway', return_value=mock_coro(False)): + assert await deconz_gateway.async_setup() is False + + +async def test_connection_status(hass): + """Make sure that connection status triggers a dispatcher send.""" + entry = Mock() + entry.data = ENTRY_CONFIG + + deconz_gateway = gateway.DeconzGateway(hass, entry) + with patch.object(gateway, 'async_dispatcher_send') as mock_dispatch_send: + deconz_gateway.async_connection_status_callback(True) + + await hass.async_block_till_done() + assert len(mock_dispatch_send.mock_calls) == 1 + assert len(mock_dispatch_send.mock_calls[0]) == 3 + + +async def test_add_device(hass): + """Successful retry setup.""" + entry = Mock() + entry.data = ENTRY_CONFIG + + deconz_gateway = gateway.DeconzGateway(hass, entry) + with patch.object(gateway, 'async_dispatcher_send') as mock_dispatch_send: + deconz_gateway.async_add_device_callback('sensor', Mock()) + + await hass.async_block_till_done() + assert len(mock_dispatch_send.mock_calls) == 1 + assert len(mock_dispatch_send.mock_calls[0]) == 3 + + +async def test_add_remote(): + """Successful add remote.""" + hass = Mock() + entry = Mock() + entry.data = ENTRY_CONFIG + + remote = Mock() + remote.name = 'name' + remote.type = 'ZHASwitch' + remote.register_async_callback = Mock() + + deconz_gateway = gateway.DeconzGateway(hass, entry) + deconz_gateway.async_add_remote([remote]) + + assert len(deconz_gateway.events) == 1 + + +async def test_shutdown(): + """Successful shutdown.""" + hass = Mock() + entry = Mock() + entry.data = ENTRY_CONFIG + + deconz_gateway = gateway.DeconzGateway(hass, entry) + deconz_gateway.api = Mock() + deconz_gateway.shutdown(None) + + assert len(deconz_gateway.api.close.mock_calls) == 1 + + +async def test_reset_cancel_retry(): + """Verify async reset can handle a scheduled retry.""" + hass = Mock() + entry = Mock() + entry.data = ENTRY_CONFIG + + deconz_gateway = gateway.DeconzGateway(hass, entry) + + with patch.object(gateway, 'get_gateway', return_value=mock_coro(False)): + assert await deconz_gateway.async_setup() is False + + assert deconz_gateway._cancel_retry_setup is not None + + assert await deconz_gateway.async_reset() is True + + +async def test_reset_after_successful_setup(): + """""" + hass = Mock() + entry = Mock() + entry.data = ENTRY_CONFIG + api = Mock() + api.async_add_remote.return_value = Mock() + api.sensors = {} + + deconz_gateway = gateway.DeconzGateway(hass, entry) + + with patch.object(gateway, 'get_gateway', return_value=mock_coro(api)), \ + patch.object( + gateway, 'async_dispatcher_connect', return_value=Mock()): + assert await deconz_gateway.async_setup() is True + + listener = Mock() + deconz_gateway.listeners = [listener] + event = Mock() + event.async_will_remove_from_hass = Mock() + deconz_gateway.events = [event] + deconz_gateway.deconz_ids = {'key': 'value'} + + hass.config_entries.async_forward_entry_unload.return_value = \ + mock_coro(True) + assert await deconz_gateway.async_reset() is True + + assert len(hass.config_entries.async_forward_entry_unload.mock_calls) == 6 + + assert len(listener.mock_calls) == 1 + assert len(deconz_gateway.listeners) == 0 + + assert len(event.async_will_remove_from_hass.mock_calls) == 1 + assert len(deconz_gateway.events) == 0 + + assert len(deconz_gateway.deconz_ids) == 0 + + +async def test_get_gateway(hass): + """Successful call.""" + with patch('pydeconz.DeconzSession.async_load_parameters', + return_value=mock_coro(True)): + assert await gateway.get_gateway(hass, ENTRY_CONFIG, Mock(), Mock()) + + +async def test_get_gateway_fails(hass): + """Failed call.""" + with patch('pydeconz.DeconzSession.async_load_parameters', + return_value=mock_coro(False)): + assert await gateway.get_gateway(hass, ENTRY_CONFIG, Mock(), Mock()) is False + + +async def test_create_event(): + """Successfully created a deCONZ event.""" + hass = Mock() + remote = Mock() + remote.name = 'Name' + + event = gateway.DeconzEvent(hass, remote) + + assert event._id == 'name' + + +async def test_update_event(): + """Successfully update a deCONZ event.""" + hass = Mock() + remote = Mock() + remote.name = 'Name' + + event = gateway.DeconzEvent(hass, remote) + event.async_update_callback({'state': True}) + + assert len(hass.bus.async_fire.mock_calls) == 1 + + +async def test_remove_event(): + """Successfully update a deCONZ event.""" + hass = Mock() + remote = Mock() + remote.name = 'Name' + + event = gateway.DeconzEvent(hass, remote) + event.async_will_remove_from_hass() + + assert event._device is None From 23305cffa0a17f4ab7013865fbfbc96137f0eeec Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Mon, 5 Nov 2018 21:35:03 +0100 Subject: [PATCH 5/6] Fix hound comment --- tests/components/deconz/test_gateway.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/components/deconz/test_gateway.py b/tests/components/deconz/test_gateway.py index 5f7c1dfcfceea..b42db02bf060e 100644 --- a/tests/components/deconz/test_gateway.py +++ b/tests/components/deconz/test_gateway.py @@ -183,7 +183,8 @@ async def test_get_gateway_fails(hass): """Failed call.""" with patch('pydeconz.DeconzSession.async_load_parameters', return_value=mock_coro(False)): - assert await gateway.get_gateway(hass, ENTRY_CONFIG, Mock(), Mock()) is False + assert await gateway.get_gateway( + hass, ENTRY_CONFIG, Mock(), Mock()) is False async def test_create_event(): From d6e9d87dcb23dc4b1bd62dfed463c99095b27941 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Tue, 6 Nov 2018 07:01:24 +0100 Subject: [PATCH 6/6] Fix empty pydocstring --- tests/components/deconz/test_gateway.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/components/deconz/test_gateway.py b/tests/components/deconz/test_gateway.py index b42db02bf060e..3411f96b981e1 100644 --- a/tests/components/deconz/test_gateway.py +++ b/tests/components/deconz/test_gateway.py @@ -135,7 +135,7 @@ async def test_reset_cancel_retry(): async def test_reset_after_successful_setup(): - """""" + """Verify that reset works on a setup component.""" hass = Mock() entry = Mock() entry.data = ENTRY_CONFIG