diff --git a/homeassistant/components/unifi/config_flow.py b/homeassistant/components/unifi/config_flow.py index 78389c6a2d1..e91001e51be 100644 --- a/homeassistant/components/unifi/config_flow.py +++ b/homeassistant/components/unifi/config_flow.py @@ -34,7 +34,6 @@ from .const import ( from .controller import get_controller from .errors import AlreadyConfigured, AuthenticationRequired, CannotConnect -CONF_NEW_CLIENT = "new_client" DEFAULT_PORT = 8443 DEFAULT_SITE_ID = "default" DEFAULT_VERIFY_SSL = False @@ -230,53 +229,27 @@ class UnifiOptionsFlowHandler(config_entries.OptionsFlow): errors = {} if user_input is not None: - new_client = user_input.pop(CONF_NEW_CLIENT, None) self.options.update(user_input) - - if new_client: - if ( - new_client in self.controller.api.clients - or new_client in self.controller.api.clients_all - ): - self.options[CONF_BLOCK_CLIENT].append(new_client) - - else: - errors["base"] = "unknown_client_mac" - - else: - return await self.async_step_statistics_sensors() + return await self.async_step_statistics_sensors() clients_to_block = {} - for mac in self.options[CONF_BLOCK_CLIENT]: - - name = None - - for clients in [ - self.controller.api.clients, - self.controller.api.clients_all, - ]: - if mac in clients: - name = f"{clients[mac].name or clients[mac].hostname} ({mac})" - break - - if not name: - name = mac - - clients_to_block[mac] = name + for client in self.controller.api.clients.values(): + clients_to_block[ + client.mac + ] = f"{client.name or client.hostname} ({client.mac})" return self.async_show_form( step_id="client_control", data_schema=vol.Schema( { + vol.Optional( + CONF_BLOCK_CLIENT, default=self.options[CONF_BLOCK_CLIENT] + ): cv.multi_select(clients_to_block), vol.Optional( CONF_POE_CLIENTS, default=self.options.get(CONF_POE_CLIENTS, DEFAULT_POE_CLIENTS), ): bool, - vol.Optional( - CONF_BLOCK_CLIENT, default=self.options[CONF_BLOCK_CLIENT] - ): cv.multi_select(clients_to_block), - vol.Optional(CONF_NEW_CLIENT): str, } ), errors=errors, diff --git a/homeassistant/components/unifi/strings.json b/homeassistant/components/unifi/strings.json index f436a86c6b3..6c142d371c9 100644 --- a/homeassistant/components/unifi/strings.json +++ b/homeassistant/components/unifi/strings.json @@ -41,7 +41,6 @@ "client_control": { "data": { "block_client": "Network access controlled clients", - "new_client": "Add new client for network access control", "poe_clients": "Allow POE control of clients" }, "description": "Configure client controls\n\nCreate switches for serial numbers you want to control network access for.", @@ -56,4 +55,4 @@ } } } -} \ No newline at end of file +} diff --git a/tests/components/unifi/test_config_flow.py b/tests/components/unifi/test_config_flow.py index 09b16440f94..c6b4f27e7f4 100644 --- a/tests/components/unifi/test_config_flow.py +++ b/tests/components/unifi/test_config_flow.py @@ -5,7 +5,6 @@ from asynctest import patch from homeassistant import data_entry_flow from homeassistant.components import unifi from homeassistant.components.unifi import config_flow -from homeassistant.components.unifi.config_flow import CONF_NEW_CLIENT from homeassistant.components.unifi.const import ( CONF_ALLOW_BANDWIDTH_SENSORS, CONF_BLOCK_CLIENT, @@ -293,38 +292,9 @@ async def test_option_flow(hass): assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "client_control" - clients_to_block = hass.config_entries.options._progress[result["flow_id"]].options[ - CONF_BLOCK_CLIENT - ] result = await hass.config_entries.options.async_configure( result["flow_id"], - user_input={ - CONF_BLOCK_CLIENT: clients_to_block, - CONF_NEW_CLIENT: "00:00:00:00:00:01", - CONF_POE_CLIENTS: False, - }, - ) - - assert result["type"] == data_entry_flow.RESULT_TYPE_FORM - assert result["step_id"] == "client_control" - - result = await hass.config_entries.options.async_configure( - result["flow_id"], - user_input={ - CONF_BLOCK_CLIENT: clients_to_block, - CONF_NEW_CLIENT: "00:00:00:00:00:02", - }, - ) - - assert result["type"] == data_entry_flow.RESULT_TYPE_FORM - assert result["step_id"] == "client_control" - assert result["errors"] == {"base": "unknown_client_mac"} - - clients_to_block = hass.config_entries.options._progress[result["flow_id"]].options[ - CONF_BLOCK_CLIENT - ] - result = await hass.config_entries.options.async_configure( - result["flow_id"], user_input={CONF_BLOCK_CLIENT: clients_to_block}, + user_input={CONF_BLOCK_CLIENT: [CLIENTS[0]["mac"]], CONF_POE_CLIENTS: False}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -343,6 +313,6 @@ async def test_option_flow(hass): CONF_DETECTION_TIME: 100, CONF_IGNORE_WIRED_BUG: False, CONF_POE_CLIENTS: False, - CONF_BLOCK_CLIENT: ["00:00:00:00:00:01"], + CONF_BLOCK_CLIENT: [CLIENTS[0]["mac"]], CONF_ALLOW_BANDWIDTH_SENSORS: True, }