mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Remove legacy UniFi PoE client clean up (#100318)
This commit is contained in:
parent
23a891ebb1
commit
7b00265cfe
@ -6,7 +6,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import config_validation as cv, entity_registry as er
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.storage import Store
|
from homeassistant.helpers.storage import Store
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
@ -34,9 +34,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
"""Set up the UniFi Network integration."""
|
"""Set up the UniFi Network integration."""
|
||||||
hass.data.setdefault(UNIFI_DOMAIN, {})
|
hass.data.setdefault(UNIFI_DOMAIN, {})
|
||||||
|
|
||||||
# Removal of legacy PoE control was introduced with 2022.12
|
|
||||||
async_remove_poe_client_entities(hass, config_entry)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
api = await get_unifi_controller(hass, config_entry.data)
|
api = await get_unifi_controller(hass, config_entry.data)
|
||||||
controller = UniFiController(hass, config_entry, api)
|
controller = UniFiController(hass, config_entry, api)
|
||||||
@ -74,24 +71,6 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||||||
return await controller.async_reset()
|
return await controller.async_reset()
|
||||||
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def async_remove_poe_client_entities(
|
|
||||||
hass: HomeAssistant, config_entry: ConfigEntry
|
|
||||||
) -> None:
|
|
||||||
"""Remove PoE client entities."""
|
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
|
|
||||||
entity_ids_to_be_removed = [
|
|
||||||
entry.entity_id
|
|
||||||
for entry in ent_reg.entities.values()
|
|
||||||
if entry.config_entry_id == config_entry.entry_id
|
|
||||||
and entry.unique_id.startswith("poe-")
|
|
||||||
]
|
|
||||||
|
|
||||||
for entity_id in entity_ids_to_be_removed:
|
|
||||||
ent_reg.async_remove(entity_id)
|
|
||||||
|
|
||||||
|
|
||||||
class UnifiWirelessClients:
|
class UnifiWirelessClients:
|
||||||
"""Class to store clients known to be wireless.
|
"""Class to store clients known to be wireless.
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ from aiounifi.models.message import MessageKey
|
|||||||
from aiounifi.websocket import WebsocketState
|
from aiounifi.websocket import WebsocketState
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
|
||||||
from homeassistant.components.switch import (
|
from homeassistant.components.switch import (
|
||||||
DOMAIN as SWITCH_DOMAIN,
|
DOMAIN as SWITCH_DOMAIN,
|
||||||
SERVICE_TURN_OFF,
|
SERVICE_TURN_OFF,
|
||||||
@ -34,12 +33,7 @@ from homeassistant.helpers import entity_registry as er
|
|||||||
from homeassistant.helpers.entity_registry import RegistryEntryDisabler
|
from homeassistant.helpers.entity_registry import RegistryEntryDisabler
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from .test_controller import (
|
from .test_controller import CONTROLLER_HOST, SITE, setup_unifi_integration
|
||||||
CONTROLLER_HOST,
|
|
||||||
ENTRY_CONFIG,
|
|
||||||
SITE,
|
|
||||||
setup_unifi_integration,
|
|
||||||
)
|
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
@ -1436,38 +1430,6 @@ async def test_poe_port_switches(
|
|||||||
assert hass.states.get("switch.mock_name_port_1_poe").state == STATE_OFF
|
assert hass.states.get("switch.mock_name_port_1_poe").state == STATE_OFF
|
||||||
|
|
||||||
|
|
||||||
async def test_remove_poe_client_switches(
|
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
|
||||||
) -> None:
|
|
||||||
"""Test old PoE client switches are removed."""
|
|
||||||
|
|
||||||
config_entry = config_entries.ConfigEntry(
|
|
||||||
version=1,
|
|
||||||
domain=UNIFI_DOMAIN,
|
|
||||||
title="Mock Title",
|
|
||||||
data=ENTRY_CONFIG,
|
|
||||||
source="test",
|
|
||||||
options={},
|
|
||||||
entry_id="1",
|
|
||||||
)
|
|
||||||
|
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
ent_reg.async_get_or_create(
|
|
||||||
SWITCH_DOMAIN,
|
|
||||||
UNIFI_DOMAIN,
|
|
||||||
"poe-123",
|
|
||||||
config_entry=config_entry,
|
|
||||||
)
|
|
||||||
|
|
||||||
await setup_unifi_integration(hass, aioclient_mock)
|
|
||||||
|
|
||||||
assert not [
|
|
||||||
entry
|
|
||||||
for entry in ent_reg.entities.values()
|
|
||||||
if entry.config_entry_id == config_entry.entry_id
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
async def test_wlan_switches(
|
async def test_wlan_switches(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_unifi_websocket
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_unifi_websocket
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user