mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Remove (2021) backwards supporting functionality from UniFi (#81981)
This commit is contained in:
parent
9b8f94363c
commit
af6338343e
@ -1,6 +1,4 @@
|
||||
"""Integration to UniFi Network and its various features."""
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||
@ -10,12 +8,7 @@ from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
CONF_CONTROLLER,
|
||||
DOMAIN as UNIFI_DOMAIN,
|
||||
PLATFORMS,
|
||||
UNIFI_WIRELESS_CLIENTS,
|
||||
)
|
||||
from .const import DOMAIN as UNIFI_DOMAIN, PLATFORMS, UNIFI_WIRELESS_CLIENTS
|
||||
from .controller import UniFiController, get_unifi_controller
|
||||
from .errors import AuthenticationRequired, CannotConnect
|
||||
from .services import async_setup_services, async_unload_services
|
||||
@ -40,9 +33,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
# Removal of legacy PoE control was introduced with 2022.12
|
||||
async_remove_poe_client_entities(hass, config_entry)
|
||||
|
||||
# Flat configuration was introduced with 2021.3
|
||||
await async_flatten_entry_data(hass, config_entry)
|
||||
|
||||
try:
|
||||
api = await get_unifi_controller(hass, config_entry.data)
|
||||
controller = UniFiController(hass, config_entry, api)
|
||||
@ -54,12 +44,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
except AuthenticationRequired as err:
|
||||
raise ConfigEntryAuthFailed from err
|
||||
|
||||
# Unique ID was introduced with 2021.3
|
||||
if config_entry.unique_id is None:
|
||||
hass.config_entries.async_update_entry(
|
||||
config_entry, unique_id=controller.site_id
|
||||
)
|
||||
|
||||
hass.data[UNIFI_DOMAIN][config_entry.entry_id] = controller
|
||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||
await controller.async_update_device_registry()
|
||||
@ -104,52 +88,36 @@ def async_remove_poe_client_entities(
|
||||
ent_reg.async_remove(entity_id)
|
||||
|
||||
|
||||
async def async_flatten_entry_data(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> None:
|
||||
"""Simpler configuration structure for entry data.
|
||||
|
||||
Keep controller key layer in case user rollbacks.
|
||||
"""
|
||||
|
||||
data: Mapping[str, Any] = {
|
||||
**config_entry.data,
|
||||
**config_entry.data[CONF_CONTROLLER],
|
||||
}
|
||||
if config_entry.data != data:
|
||||
hass.config_entries.async_update_entry(config_entry, data=data)
|
||||
|
||||
|
||||
class UnifiWirelessClients:
|
||||
"""Class to store clients known to be wireless.
|
||||
|
||||
This is needed since wireless devices going offline might get marked as wired by UniFi.
|
||||
"""
|
||||
|
||||
def __init__(self, hass):
|
||||
def __init__(self, hass: HomeAssistant) -> None:
|
||||
"""Set up client storage."""
|
||||
self.hass = hass
|
||||
self.data = {}
|
||||
self._store = Store(hass, STORAGE_VERSION, STORAGE_KEY)
|
||||
self.data: dict[str, dict[str, list[str]]] = {}
|
||||
self._store: Store = Store(hass, STORAGE_VERSION, STORAGE_KEY)
|
||||
|
||||
async def async_load(self):
|
||||
async def async_load(self) -> None:
|
||||
"""Load data from file."""
|
||||
if (data := await self._store.async_load()) is not None:
|
||||
self.data = data
|
||||
|
||||
@callback
|
||||
def get_data(self, config_entry):
|
||||
def get_data(self, config_entry: ConfigEntry) -> set[str]:
|
||||
"""Get data related to a specific controller."""
|
||||
data = self.data.get(config_entry.entry_id, {"wireless_devices": []})
|
||||
return set(data["wireless_devices"])
|
||||
|
||||
@callback
|
||||
def update_data(self, data, config_entry):
|
||||
def update_data(self, data: set[str], config_entry: ConfigEntry) -> None:
|
||||
"""Update data and schedule to save to file."""
|
||||
self.data[config_entry.entry_id] = {"wireless_devices": list(data)}
|
||||
self._store.async_delay_save(self._data_to_save, SAVE_DELAY)
|
||||
|
||||
@callback
|
||||
def _data_to_save(self):
|
||||
def _data_to_save(self) -> dict[str, dict[str, list[str]]]:
|
||||
"""Return data of UniFi wireless clients to store in a file."""
|
||||
return self.data
|
||||
|
@ -2,19 +2,13 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components import unifi
|
||||
from homeassistant.components.unifi import async_flatten_entry_data
|
||||
from homeassistant.components.unifi.const import CONF_CONTROLLER, DOMAIN as UNIFI_DOMAIN
|
||||
from homeassistant.components.unifi.const import DOMAIN as UNIFI_DOMAIN
|
||||
from homeassistant.components.unifi.errors import AuthenticationRequired, CannotConnect
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .test_controller import (
|
||||
CONTROLLER_DATA,
|
||||
DEFAULT_CONFIG_ENTRY_ID,
|
||||
ENTRY_CONFIG,
|
||||
setup_unifi_integration,
|
||||
)
|
||||
from .test_controller import DEFAULT_CONFIG_ENTRY_ID, setup_unifi_integration
|
||||
|
||||
from tests.common import MockConfigEntry, flush_store
|
||||
from tests.common import flush_store
|
||||
|
||||
|
||||
async def test_setup_with_no_config(hass):
|
||||
@ -52,17 +46,6 @@ async def test_setup_entry_fails_trigger_reauth_flow(hass):
|
||||
assert hass.data[UNIFI_DOMAIN] == {}
|
||||
|
||||
|
||||
async def test_flatten_entry_data(hass):
|
||||
"""Verify entry data can be flattened."""
|
||||
entry = MockConfigEntry(
|
||||
domain=UNIFI_DOMAIN,
|
||||
data={CONF_CONTROLLER: CONTROLLER_DATA},
|
||||
)
|
||||
await async_flatten_entry_data(hass, entry)
|
||||
|
||||
assert entry.data == ENTRY_CONFIG
|
||||
|
||||
|
||||
async def test_unload_entry(hass, aioclient_mock):
|
||||
"""Test being able to unload an entry."""
|
||||
config_entry = await setup_unifi_integration(hass, aioclient_mock)
|
||||
|
Loading…
x
Reference in New Issue
Block a user