Rework some UniFi unique IDs (#104390)
This commit is contained in:
parent
d4450c6c55
commit
6271fe333d
4 changed files with 144 additions and 14 deletions
|
@ -5,6 +5,7 @@ from datetime import timedelta
|
|||
from aiounifi.models.message import MessageKey
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.switch import (
|
||||
DOMAIN as SWITCH_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
|
@ -32,7 +33,12 @@ from homeassistant.helpers import entity_registry as er
|
|||
from homeassistant.helpers.entity_registry import RegistryEntryDisabler
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .test_controller import CONTROLLER_HOST, SITE, setup_unifi_integration
|
||||
from .test_controller import (
|
||||
CONTROLLER_HOST,
|
||||
ENTRY_CONFIG,
|
||||
SITE,
|
||||
setup_unifi_integration,
|
||||
)
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
@ -1585,3 +1591,70 @@ async def test_port_forwarding_switches(
|
|||
mock_unifi_websocket(message=MessageKey.PORT_FORWARD_DELETED, data=_data)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 0
|
||||
|
||||
|
||||
async def test_updating_unique_id(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Verify outlet control and poe control unique ID update works."""
|
||||
poe_device = {
|
||||
"board_rev": 3,
|
||||
"device_id": "mock-id",
|
||||
"ip": "10.0.0.1",
|
||||
"last_seen": 1562600145,
|
||||
"mac": "00:00:00:00:01:01",
|
||||
"model": "US16P150",
|
||||
"name": "switch",
|
||||
"state": 1,
|
||||
"type": "usw",
|
||||
"version": "4.0.42.10433",
|
||||
"port_table": [
|
||||
{
|
||||
"media": "GE",
|
||||
"name": "Port 1",
|
||||
"port_idx": 1,
|
||||
"poe_caps": 7,
|
||||
"poe_class": "Class 4",
|
||||
"poe_enable": True,
|
||||
"poe_mode": "auto",
|
||||
"poe_power": "2.56",
|
||||
"poe_voltage": "53.40",
|
||||
"portconf_id": "1a1",
|
||||
"port_poe": True,
|
||||
"up": True,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
config_entry = config_entries.ConfigEntry(
|
||||
version=1,
|
||||
domain=UNIFI_DOMAIN,
|
||||
title="Mock Title",
|
||||
data=ENTRY_CONFIG,
|
||||
source="test",
|
||||
options={},
|
||||
entry_id="1",
|
||||
)
|
||||
|
||||
registry = er.async_get(hass)
|
||||
registry.async_get_or_create(
|
||||
SWITCH_DOMAIN,
|
||||
UNIFI_DOMAIN,
|
||||
f'{poe_device["mac"]}-poe-1',
|
||||
suggested_object_id="switch_port_1_poe",
|
||||
config_entry=config_entry,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SWITCH_DOMAIN,
|
||||
UNIFI_DOMAIN,
|
||||
f'{OUTLET_UP1["mac"]}-outlet-1',
|
||||
suggested_object_id="plug_outlet_1",
|
||||
config_entry=config_entry,
|
||||
)
|
||||
|
||||
await setup_unifi_integration(
|
||||
hass, aioclient_mock, devices_response=[poe_device, OUTLET_UP1]
|
||||
)
|
||||
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 2
|
||||
assert hass.states.get("switch.switch_port_1_poe")
|
||||
assert hass.states.get("switch.plug_outlet_1")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue