From f56f391f810a8cf79197b94bdf8fda630bd69a66 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Sun, 1 Jan 2023 20:03:14 +0100 Subject: [PATCH] Remove legacy constant from UniFi (#84947) --- homeassistant/components/unifi/config_flow.py | 3 --- homeassistant/components/unifi/const.py | 1 - homeassistant/components/unifi/diagnostics.py | 6 +++--- tests/components/unifi/test_config_flow.py | 9 --------- tests/components/unifi/test_controller.py | 15 ++++++--------- tests/components/unifi/test_diagnostics.py | 3 ++- 6 files changed, 11 insertions(+), 26 deletions(-) diff --git a/homeassistant/components/unifi/config_flow.py b/homeassistant/components/unifi/config_flow.py index caf256ded20..64ea7b39778 100644 --- a/homeassistant/components/unifi/config_flow.py +++ b/homeassistant/components/unifi/config_flow.py @@ -33,7 +33,6 @@ from .const import ( CONF_ALLOW_BANDWIDTH_SENSORS, CONF_ALLOW_UPTIME_SENSORS, CONF_BLOCK_CLIENT, - CONF_CONTROLLER, CONF_DETECTION_TIME, CONF_DPI_RESTRICTIONS, CONF_IGNORE_WIRED_BUG, @@ -152,8 +151,6 @@ class UnifiFlowHandler(config_entries.ConfigFlow, domain=UNIFI_DOMAIN): unique_id = user_input[CONF_SITE_ID] self.config[CONF_SITE_ID] = self.site_ids[unique_id] - # Backwards compatible config - self.config[CONF_CONTROLLER] = self.config.copy() config_entry = await self.async_set_unique_id(unique_id) abort_reason = "configuration_updated" diff --git a/homeassistant/components/unifi/const.py b/homeassistant/components/unifi/const.py index 85f744e481f..b5cea06c719 100644 --- a/homeassistant/components/unifi/const.py +++ b/homeassistant/components/unifi/const.py @@ -14,7 +14,6 @@ PLATFORMS = [ Platform.UPDATE, ] -CONF_CONTROLLER = "controller" CONF_SITE_ID = "site" UNIFI_WIRELESS_CLIENTS = "unifi_wireless_clients" diff --git a/homeassistant/components/unifi/diagnostics.py b/homeassistant/components/unifi/diagnostics.py index 495613f3b81..3c72c06d6f2 100644 --- a/homeassistant/components/unifi/diagnostics.py +++ b/homeassistant/components/unifi/diagnostics.py @@ -11,11 +11,11 @@ from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.device_registry import format_mac -from .const import CONF_CONTROLLER, DOMAIN as UNIFI_DOMAIN +from .const import DOMAIN as UNIFI_DOMAIN from .controller import UniFiController -TO_REDACT = {CONF_CONTROLLER, CONF_PASSWORD} -REDACT_CONFIG = {CONF_CONTROLLER, CONF_HOST, CONF_PASSWORD, CONF_USERNAME} +TO_REDACT = {CONF_PASSWORD} +REDACT_CONFIG = {CONF_HOST, CONF_PASSWORD, CONF_USERNAME} REDACT_CLIENTS = {"bssid", "essid"} REDACT_DEVICES = { "anon_id", diff --git a/tests/components/unifi/test_config_flow.py b/tests/components/unifi/test_config_flow.py index 078c068c8ed..c9ce0e74c21 100644 --- a/tests/components/unifi/test_config_flow.py +++ b/tests/components/unifi/test_config_flow.py @@ -12,7 +12,6 @@ from homeassistant.components.unifi.const import ( CONF_ALLOW_BANDWIDTH_SENSORS, CONF_ALLOW_UPTIME_SENSORS, CONF_BLOCK_CLIENT, - CONF_CONTROLLER, CONF_DETECTION_TIME, CONF_DPI_RESTRICTIONS, CONF_IGNORE_WIRED_BUG, @@ -143,14 +142,6 @@ async def test_flow_works(hass, aioclient_mock, mock_discovery): CONF_PORT: 1234, CONF_SITE_ID: "site_id", CONF_VERIFY_SSL: True, - CONF_CONTROLLER: { - CONF_HOST: "1.2.3.4", - CONF_USERNAME: "username", - CONF_PASSWORD: "password", - CONF_PORT: 1234, - CONF_SITE_ID: "site_id", - CONF_VERIFY_SSL: True, - }, } diff --git a/tests/components/unifi/test_controller.py b/tests/components/unifi/test_controller.py index 3861c5b38bd..c08fee21fdf 100644 --- a/tests/components/unifi/test_controller.py +++ b/tests/components/unifi/test_controller.py @@ -16,7 +16,6 @@ from homeassistant.components.device_tracker import DOMAIN as TRACKER_DOMAIN from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN from homeassistant.components.unifi.const import ( - CONF_CONTROLLER, CONF_SITE_ID, CONF_TRACK_CLIENTS, CONF_TRACK_DEVICES, @@ -67,7 +66,7 @@ CONTROLLER_HOST = { "uptime": 1562600160, } -CONTROLLER_DATA = { +ENTRY_CONFIG = { CONF_HOST: DEFAULT_HOST, CONF_USERNAME: "username", CONF_PASSWORD: "password", @@ -75,8 +74,6 @@ CONTROLLER_DATA = { CONF_SITE_ID: DEFAULT_SITE, CONF_VERIFY_SSL: False, } - -ENTRY_CONFIG = {**CONTROLLER_DATA, CONF_CONTROLLER: CONTROLLER_DATA} ENTRY_OPTIONS = {} CONFIGURATION = [] @@ -227,8 +224,8 @@ async def test_controller_setup(hass, aioclient_mock): assert forward_entry_setup.mock_calls[1][1] == (entry, SENSOR_DOMAIN) assert forward_entry_setup.mock_calls[2][1] == (entry, SWITCH_DOMAIN) - assert controller.host == CONTROLLER_DATA[CONF_HOST] - assert controller.site == CONTROLLER_DATA[CONF_SITE_ID] + assert controller.host == ENTRY_CONFIG[CONF_HOST] + assert controller.site == ENTRY_CONFIG[CONF_SITE_ID] assert controller.site_name == SITE[0]["desc"] assert controller.site_role == SITE[0]["role"] @@ -467,12 +464,12 @@ async def test_get_unifi_controller(hass): with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch( "aiounifi.Controller.login", return_value=True ): - assert await get_unifi_controller(hass, CONTROLLER_DATA) + assert await get_unifi_controller(hass, ENTRY_CONFIG) async def test_get_unifi_controller_verify_ssl_false(hass): """Successful call with verify ssl set to false.""" - controller_data = dict(CONTROLLER_DATA) + controller_data = dict(ENTRY_CONFIG) controller_data[CONF_VERIFY_SSL] = False with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch( "aiounifi.Controller.login", return_value=True @@ -500,4 +497,4 @@ async def test_get_unifi_controller_fails_to_connect( with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch( "aiounifi.Controller.login", side_effect=side_effect ), pytest.raises(raised_exception): - await get_unifi_controller(hass, CONTROLLER_DATA) + await get_unifi_controller(hass, ENTRY_CONFIG) diff --git a/tests/components/unifi/test_diagnostics.py b/tests/components/unifi/test_diagnostics.py index 9de0e4b6154..0899153033e 100644 --- a/tests/components/unifi/test_diagnostics.py +++ b/tests/components/unifi/test_diagnostics.py @@ -29,6 +29,7 @@ async def test_entry_diagnostics(hass, hass_client, aioclient_mock): "wired-tx_bytes": 5678000000, } device = { + "board_rev": "1.2.3", "ethernet_table": [ { "mac": "22:22:22:22:22:22", @@ -112,7 +113,6 @@ async def test_entry_diagnostics(hass, hass_client, aioclient_mock): assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { "config": { "data": { - "controller": REDACTED, "host": REDACTED, "password": REDACTED, "port": 1234, @@ -154,6 +154,7 @@ async def test_entry_diagnostics(hass, hass_client, aioclient_mock): }, "devices": { "00:00:00:00:00:01": { + "board_rev": "1.2.3", "ethernet_table": [ { "mac": "00:00:00:00:00:02",