UniFi - Store controller in config_entry.entry_id (#34553)

* Store controller in config_entry.entry_id

* Clean up imports
This commit is contained in:
Robert Svensson authored and GitHub committed 2020-04-23 16:48:24 +02:00
1 parent a0fbf9ba47
commit c3689d7416
13 files changed
+190 -182

No files matched your search

+23 -21
View File
@@ -4,8 +4,14 @@ from copy import deepcopy
from aiounifi.controller import MESSAGE_CLIENT_REMOVED
from aiounifi.websocket import SIGNAL_DATA
from homeassistant.components import unifi
import homeassistant.components.sensor as sensor
from homeassistant.components.device_tracker import DOMAIN as TRACKER_DOMAIN
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.components.unifi.const import (
CONF_ALLOW_BANDWIDTH_SENSORS,
CONF_TRACK_CLIENTS,
CONF_TRACK_DEVICES,
DOMAIN as UNIFI_DOMAIN,
)
from homeassistant.setup import async_setup_component
from .test_controller import setup_unifi_integration
@@ -44,21 +50,21 @@ async def test_platform_manually_configured(hass):
"""Test that we do not discover anything or try to set up a controller."""
assert (
await async_setup_component(
hass, sensor.DOMAIN, {sensor.DOMAIN: {"platform": "unifi"}}
hass, SENSOR_DOMAIN, {SENSOR_DOMAIN: {"platform": UNIFI_DOMAIN}}
)
is True
)
assert unifi.DOMAIN not in hass.data
assert UNIFI_DOMAIN not in hass.data
async def test_no_clients(hass):
"""Test the update_clients function when no clients are found."""
controller = await setup_unifi_integration(
hass, options={unifi.const.CONF_ALLOW_BANDWIDTH_SENSORS: True},
hass, options={CONF_ALLOW_BANDWIDTH_SENSORS: True},
)
assert len(controller.mock_requests) == 4
assert len(hass.states.async_entity_ids("sensor")) == 0
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 0
async def test_sensors(hass):
@@ -66,15 +72,15 @@ async def test_sensors(hass):
controller = await setup_unifi_integration(
hass,
options={
unifi.const.CONF_ALLOW_BANDWIDTH_SENSORS: True,
unifi.const.CONF_TRACK_CLIENTS: False,
unifi.const.CONF_TRACK_DEVICES: False,
CONF_ALLOW_BANDWIDTH_SENSORS: True,
CONF_TRACK_CLIENTS: False,
CONF_TRACK_DEVICES: False,
},
clients_response=CLIENTS,
)
assert len(controller.mock_requests) == 4
assert len(hass.states.async_entity_ids("sensor")) == 4
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 4
wired_client_rx = hass.states.get("sensor.wired_client_name_rx")
assert wired_client_rx.state == "1234.0"
@@ -104,8 +110,7 @@ async def test_sensors(hass):
assert wireless_client_tx.state == "6789.0"
hass.config_entries.async_update_entry(
controller.config_entry,
options={unifi.const.CONF_ALLOW_BANDWIDTH_SENSORS: False},
controller.config_entry, options={CONF_ALLOW_BANDWIDTH_SENSORS: False},
)
await hass.async_block_till_done()
@@ -116,8 +121,7 @@ async def test_sensors(hass):
assert wireless_client_tx is None
hass.config_entries.async_update_entry(
controller.config_entry,
options={unifi.const.CONF_ALLOW_BANDWIDTH_SENSORS: True},
controller.config_entry, options={CONF_ALLOW_BANDWIDTH_SENSORS: True},
)
await hass.async_block_till_done()
@@ -131,12 +135,10 @@ async def test_sensors(hass):
async def test_remove_sensors(hass):
"""Test the remove_items function with some clients."""
controller = await setup_unifi_integration(
hass,
options={unifi.const.CONF_ALLOW_BANDWIDTH_SENSORS: True},
clients_response=CLIENTS,
hass, options={CONF_ALLOW_BANDWIDTH_SENSORS: True}, clients_response=CLIENTS,
)
assert len(hass.states.async_entity_ids("sensor")) == 4
assert len(hass.states.async_entity_ids("device_tracker")) == 2
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 2
wired_client_rx = hass.states.get("sensor.wired_client_name_rx")
assert wired_client_rx is not None
@@ -155,8 +157,8 @@ async def test_remove_sensors(hass):
controller.api.session_handler(SIGNAL_DATA)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids("sensor")) == 2
assert len(hass.states.async_entity_ids("device_tracker")) == 1
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 2
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 1
wired_client_rx = hass.states.get("sensor.wired_client_name_rx")
assert wired_client_rx is None