deCONZ - Improve tests based on Martins feedback in Axis integration (#30438)

This commit is contained in:
Robert Svensson 2020-01-03 18:11:04 +01:00 committed by GitHub
parent 8a1fc8b8f0
commit ec61342ec3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 84 additions and 197 deletions

View file

@ -5,7 +5,7 @@ from homeassistant.components import deconz
import homeassistant.components.binary_sensor as binary_sensor import homeassistant.components.binary_sensor as binary_sensor
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from .test_gateway import DECONZ_WEB_REQUEST, ENTRY_CONFIG, setup_deconz_integration from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
SENSORS = { SENSORS = {
"1": { "1": {
@ -61,10 +61,7 @@ async def test_platform_manually_configured(hass):
async def test_no_binary_sensors(hass): async def test_no_binary_sensors(hass):
"""Test that no sensors in deconz results in no sensor entities.""" """Test that no sensors in deconz results in no sensor entities."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert len(gateway.deconz_ids) == 0 assert len(gateway.deconz_ids) == 0
assert len(hass.states.async_all()) == 0 assert len(hass.states.async_all()) == 0
@ -73,9 +70,7 @@ async def test_binary_sensors(hass):
"""Test successful creation of binary sensor entities.""" """Test successful creation of binary sensor entities."""
data = deepcopy(DECONZ_WEB_REQUEST) data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS) data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(hass, get_state_response=data)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert "binary_sensor.presence_sensor" in gateway.deconz_ids assert "binary_sensor.presence_sensor" in gateway.deconz_ids
assert "binary_sensor.temperature_sensor" not in gateway.deconz_ids assert "binary_sensor.temperature_sensor" not in gateway.deconz_ids
assert "binary_sensor.clip_presence_sensor" not in gateway.deconz_ids assert "binary_sensor.clip_presence_sensor" not in gateway.deconz_ids
@ -118,7 +113,6 @@ async def test_allow_clip_sensor(hass):
data["sensors"] = deepcopy(SENSORS) data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(
hass, hass,
ENTRY_CONFIG,
options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True}, options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True},
get_state_response=data, get_state_response=data,
) )
@ -143,10 +137,7 @@ async def test_allow_clip_sensor(hass):
async def test_add_new_binary_sensor(hass): async def test_add_new_binary_sensor(hass):
"""Test that adding a new binary sensor works.""" """Test that adding a new binary sensor works."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert len(gateway.deconz_ids) == 0 assert len(gateway.deconz_ids) == 0
state_added_event = { state_added_event = {

View file

@ -7,7 +7,7 @@ from homeassistant.components import deconz
import homeassistant.components.climate as climate import homeassistant.components.climate as climate
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from .test_gateway import DECONZ_WEB_REQUEST, ENTRY_CONFIG, setup_deconz_integration from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
SENSORS = { SENSORS = {
"1": { "1": {
@ -56,10 +56,7 @@ async def test_platform_manually_configured(hass):
async def test_no_sensors(hass): async def test_no_sensors(hass):
"""Test that no sensors in deconz results in no climate entities.""" """Test that no sensors in deconz results in no climate entities."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert len(gateway.deconz_ids) == 0 assert len(gateway.deconz_ids) == 0
assert len(hass.states.async_all()) == 0 assert len(hass.states.async_all()) == 0
@ -68,9 +65,7 @@ async def test_climate_devices(hass):
"""Test successful creation of sensor entities.""" """Test successful creation of sensor entities."""
data = deepcopy(DECONZ_WEB_REQUEST) data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS) data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(hass, get_state_response=data)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert "climate.thermostat" in gateway.deconz_ids assert "climate.thermostat" in gateway.deconz_ids
assert "sensor.thermostat" not in gateway.deconz_ids assert "sensor.thermostat" not in gateway.deconz_ids
assert "sensor.thermostat_battery_level" in gateway.deconz_ids assert "sensor.thermostat_battery_level" in gateway.deconz_ids
@ -194,7 +189,6 @@ async def test_clip_climate_device(hass):
data["sensors"] = deepcopy(SENSORS) data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(
hass, hass,
ENTRY_CONFIG,
options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True}, options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True},
get_state_response=data, get_state_response=data,
) )
@ -225,9 +219,7 @@ async def test_verify_state_update(hass):
"""Test that state update properly.""" """Test that state update properly."""
data = deepcopy(DECONZ_WEB_REQUEST) data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS) data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(hass, get_state_response=data)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert "climate.thermostat" in gateway.deconz_ids assert "climate.thermostat" in gateway.deconz_ids
thermostat = hass.states.get("climate.thermostat") thermostat = hass.states.get("climate.thermostat")
@ -250,10 +242,7 @@ async def test_verify_state_update(hass):
async def test_add_new_climate_device(hass): async def test_add_new_climate_device(hass):
"""Test that adding a new climate device works.""" """Test that adding a new climate device works."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert len(gateway.deconz_ids) == 0 assert len(gateway.deconz_ids) == 0
state_added_event = { state_added_event = {

View file

@ -7,7 +7,7 @@ from homeassistant.components import deconz
import homeassistant.components.cover as cover import homeassistant.components.cover as cover
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from .test_gateway import DECONZ_WEB_REQUEST, ENTRY_CONFIG, setup_deconz_integration from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
COVERS = { COVERS = {
"1": { "1": {
@ -49,10 +49,7 @@ async def test_platform_manually_configured(hass):
async def test_no_covers(hass): async def test_no_covers(hass):
"""Test that no cover entities are created.""" """Test that no cover entities are created."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert len(gateway.deconz_ids) == 0 assert len(gateway.deconz_ids) == 0
assert len(hass.states.async_all()) == 0 assert len(hass.states.async_all()) == 0
@ -61,9 +58,7 @@ async def test_cover(hass):
"""Test that all supported cover entities are created.""" """Test that all supported cover entities are created."""
data = deepcopy(DECONZ_WEB_REQUEST) data = deepcopy(DECONZ_WEB_REQUEST)
data["lights"] = deepcopy(COVERS) data["lights"] = deepcopy(COVERS)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(hass, get_state_response=data)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert "cover.level_controllable_cover" in gateway.deconz_ids assert "cover.level_controllable_cover" in gateway.deconz_ids
assert "cover.window_covering_device" in gateway.deconz_ids assert "cover.window_covering_device" in gateway.deconz_ids
assert "cover.unsupported_cover" not in gateway.deconz_ids assert "cover.unsupported_cover" not in gateway.deconz_ids

View file

@ -5,7 +5,7 @@ from asynctest import Mock
from homeassistant.components.deconz.deconz_event import CONF_DECONZ_EVENT from homeassistant.components.deconz.deconz_event import CONF_DECONZ_EVENT
from .test_gateway import DECONZ_WEB_REQUEST, ENTRY_CONFIG, setup_deconz_integration from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
SENSORS = { SENSORS = {
"1": { "1": {
@ -31,9 +31,7 @@ async def test_deconz_events(hass):
"""Test successful creation of deconz events.""" """Test successful creation of deconz events."""
data = deepcopy(DECONZ_WEB_REQUEST) data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS) data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(hass, get_state_response=data)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert "sensor.switch_1" not in gateway.deconz_ids assert "sensor.switch_1" not in gateway.deconz_ids
assert "sensor.switch_1_battery_level" not in gateway.deconz_ids assert "sensor.switch_1_battery_level" not in gateway.deconz_ids
assert "sensor.switch_2" not in gateway.deconz_ids assert "sensor.switch_2" not in gateway.deconz_ids

View file

@ -3,7 +3,7 @@ from copy import deepcopy
from homeassistant.components.deconz import device_trigger from homeassistant.components.deconz import device_trigger
from .test_gateway import DECONZ_WEB_REQUEST, ENTRY_CONFIG, setup_deconz_integration from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
from tests.common import assert_lists_same, async_get_device_automations from tests.common import assert_lists_same, async_get_device_automations
@ -34,9 +34,7 @@ async def test_get_triggers(hass):
"""Test triggers work.""" """Test triggers work."""
data = deepcopy(DECONZ_WEB_REQUEST) data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS) data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(hass, get_state_response=data)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
device_id = gateway.events[0].device_id device_id = gateway.events[0].device_id
triggers = await async_get_device_automations(hass, "trigger", device_id) triggers = await async_get_device_automations(hass, "trigger", device_id)

View file

@ -7,9 +7,10 @@ import pytest
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components import deconz, ssdp from homeassistant.components import deconz, ssdp
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from tests.common import MockConfigEntry
BRIDGEID = "01234E56789A" BRIDGEID = "01234E56789A"
ENTRY_CONFIG = { ENTRY_CONFIG = {
@ -18,6 +19,8 @@ ENTRY_CONFIG = {
deconz.config_flow.CONF_PORT: 80, deconz.config_flow.CONF_PORT: 80,
} }
ENTRY_OPTIONS = {}
DECONZ_CONFIG = { DECONZ_CONFIG = {
"bridgeid": BRIDGEID, "bridgeid": BRIDGEID,
"ipaddress": "1.2.3.4", "ipaddress": "1.2.3.4",
@ -29,49 +32,48 @@ DECONZ_CONFIG = {
"websocketport": 1234, "websocketport": 1234,
} }
DECONZ_WEB_REQUEST = {"config": DECONZ_CONFIG} DECONZ_WEB_REQUEST = {
"config": DECONZ_CONFIG,
"groups": {},
"lights": {},
"sensors": {},
}
async def setup_deconz_integration(hass, config, options, get_state_response): async def setup_deconz_integration(
hass,
config=ENTRY_CONFIG,
options=ENTRY_OPTIONS,
get_state_response=DECONZ_WEB_REQUEST,
entry_id="1",
):
"""Create the deCONZ gateway.""" """Create the deCONZ gateway."""
config_entry = config_entries.ConfigEntry( config_entry = MockConfigEntry(
version=1,
domain=deconz.DOMAIN, domain=deconz.DOMAIN,
title="Mock Title", data=deepcopy(config),
data=config,
source="test",
connection_class=config_entries.CONN_CLASS_LOCAL_PUSH, connection_class=config_entries.CONN_CLASS_LOCAL_PUSH,
system_options={}, options=deepcopy(options),
options=options, entry_id=entry_id,
entry_id="1",
) )
config_entry.add_to_hass(hass)
for resource in ("groups", "lights", "sensors"):
if resource not in get_state_response:
get_state_response[resource] = {}
with patch( with patch(
"pydeconz.DeconzSession.request", return_value=get_state_response "pydeconz.DeconzSession.request", return_value=deepcopy(get_state_response)
), patch("pydeconz.DeconzSession.start", return_value=True): ), patch("pydeconz.DeconzSession.start", return_value=True):
await deconz.async_setup_entry(hass, config_entry) await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
hass.config_entries._entries.append(config_entry)
bridgeid = get_state_response["config"]["bridgeid"] bridgeid = get_state_response["config"]["bridgeid"]
return hass.data[deconz.DOMAIN].get(bridgeid) return hass.data[deconz.DOMAIN].get(bridgeid)
async def test_gateway_setup(hass): async def test_gateway_setup(hass):
"""Successful setup.""" """Successful setup."""
data = deepcopy(DECONZ_WEB_REQUEST)
with patch( with patch(
"homeassistant.config_entries.ConfigEntries.async_forward_entry_setup", "homeassistant.config_entries.ConfigEntries.async_forward_entry_setup",
return_value=True, return_value=True,
) as forward_entry_setup: ) as forward_entry_setup:
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(hass)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert gateway.bridgeid == BRIDGEID assert gateway.bridgeid == BRIDGEID
assert gateway.master is True assert gateway.master is True
assert gateway.option_allow_clip_sensor is False assert gateway.option_allow_clip_sensor is False
@ -92,34 +94,26 @@ async def test_gateway_setup(hass):
async def test_gateway_retry(hass): async def test_gateway_retry(hass):
"""Retry setup.""" """Retry setup."""
data = deepcopy(DECONZ_WEB_REQUEST)
with patch( with patch(
"homeassistant.components.deconz.gateway.get_gateway", "homeassistant.components.deconz.gateway.get_gateway",
side_effect=deconz.errors.CannotConnect, side_effect=deconz.errors.CannotConnect,
), pytest.raises(ConfigEntryNotReady): ):
await setup_deconz_integration( await setup_deconz_integration(hass)
hass, ENTRY_CONFIG, options={}, get_state_response=data assert not hass.data[deconz.DOMAIN]
)
async def test_gateway_setup_fails(hass): async def test_gateway_setup_fails(hass):
"""Retry setup.""" """Retry setup."""
data = deepcopy(DECONZ_WEB_REQUEST)
with patch( with patch(
"homeassistant.components.deconz.gateway.get_gateway", side_effect=Exception "homeassistant.components.deconz.gateway.get_gateway", side_effect=Exception
): ):
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(hass)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert gateway is None assert gateway is None
async def test_connection_status_signalling(hass): async def test_connection_status_signalling(hass):
"""Make sure that connection status triggers a dispatcher send.""" """Make sure that connection status triggers a dispatcher send."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
event_call = Mock() event_call = Mock()
unsub = async_dispatcher_connect(hass, gateway.signal_reachable, event_call) unsub = async_dispatcher_connect(hass, gateway.signal_reachable, event_call)
@ -135,10 +129,7 @@ async def test_connection_status_signalling(hass):
async def test_update_address(hass): async def test_update_address(hass):
"""Make sure that connection status triggers a dispatcher send.""" """Make sure that connection status triggers a dispatcher send."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert gateway.api.host == "1.2.3.4" assert gateway.api.host == "1.2.3.4"
await hass.config_entries.flow.async_init( await hass.config_entries.flow.async_init(
@ -158,10 +149,7 @@ async def test_update_address(hass):
async def test_reset_after_successful_setup(hass): async def test_reset_after_successful_setup(hass):
"""Make sure that connection status triggers a dispatcher send.""" """Make sure that connection status triggers a dispatcher send."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
result = await gateway.async_reset() result = await gateway.async_reset()
await hass.async_block_till_done() await hass.async_block_till_done()

View file

@ -3,12 +3,10 @@ import asyncio
from copy import deepcopy from copy import deepcopy
from asynctest import patch from asynctest import patch
import pytest
from homeassistant.components import deconz from homeassistant.components import deconz
from homeassistant.exceptions import ConfigEntryNotReady
from .test_gateway import DECONZ_WEB_REQUEST, ENTRY_CONFIG, setup_deconz_integration from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
ENTRY1_HOST = "1.2.3.4" ENTRY1_HOST = "1.2.3.4"
ENTRY1_PORT = 80 ENTRY1_PORT = 80
@ -35,31 +33,21 @@ async def setup_entry(hass, entry):
async def test_setup_entry_fails(hass): async def test_setup_entry_fails(hass):
"""Test setup entry fails if deCONZ is not available.""" """Test setup entry fails if deCONZ is not available."""
data = deepcopy(DECONZ_WEB_REQUEST)
with patch("pydeconz.DeconzSession.initialize", side_effect=Exception): with patch("pydeconz.DeconzSession.initialize", side_effect=Exception):
await setup_deconz_integration( await setup_deconz_integration(hass)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert not hass.data[deconz.DOMAIN] assert not hass.data[deconz.DOMAIN]
async def test_setup_entry_no_available_bridge(hass): async def test_setup_entry_no_available_bridge(hass):
"""Test setup entry fails if deCONZ is not available.""" """Test setup entry fails if deCONZ is not available."""
data = deepcopy(DECONZ_WEB_REQUEST) with patch("pydeconz.DeconzSession.initialize", side_effect=asyncio.TimeoutError):
with patch( await setup_deconz_integration(hass)
"pydeconz.DeconzSession.initialize", side_effect=asyncio.TimeoutError assert not hass.data[deconz.DOMAIN]
), pytest.raises(ConfigEntryNotReady):
await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
async def test_setup_entry_successful(hass): async def test_setup_entry_successful(hass):
"""Test setup entry is successful.""" """Test setup entry is successful."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert hass.data[deconz.DOMAIN] assert hass.data[deconz.DOMAIN]
assert gateway.bridgeid in hass.data[deconz.DOMAIN] assert gateway.bridgeid in hass.data[deconz.DOMAIN]
@ -68,15 +56,12 @@ async def test_setup_entry_successful(hass):
async def test_setup_entry_multiple_gateways(hass): async def test_setup_entry_multiple_gateways(hass):
"""Test setup entry is successful with multiple gateways.""" """Test setup entry is successful with multiple gateways."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
data2 = deepcopy(DECONZ_WEB_REQUEST) data = deepcopy(DECONZ_WEB_REQUEST)
data2["config"]["bridgeid"] = "01234E56789B" data["config"]["bridgeid"] = "01234E56789B"
gateway2 = await setup_deconz_integration( gateway2 = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data2 hass, get_state_response=data, entry_id="2"
) )
assert len(hass.data[deconz.DOMAIN]) == 2 assert len(hass.data[deconz.DOMAIN]) == 2
@ -86,10 +71,7 @@ async def test_setup_entry_multiple_gateways(hass):
async def test_unload_entry(hass): async def test_unload_entry(hass):
"""Test being able to unload an entry.""" """Test being able to unload an entry."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert hass.data[deconz.DOMAIN] assert hass.data[deconz.DOMAIN]
assert await deconz.async_unload_entry(hass, gateway.config_entry) assert await deconz.async_unload_entry(hass, gateway.config_entry)
@ -98,15 +80,12 @@ async def test_unload_entry(hass):
async def test_unload_entry_multiple_gateways(hass): async def test_unload_entry_multiple_gateways(hass):
"""Test being able to unload an entry and master gateway gets moved.""" """Test being able to unload an entry and master gateway gets moved."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
data2 = deepcopy(DECONZ_WEB_REQUEST) data = deepcopy(DECONZ_WEB_REQUEST)
data2["config"]["bridgeid"] = "01234E56789B" data["config"]["bridgeid"] = "01234E56789B"
gateway2 = await setup_deconz_integration( gateway2 = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data2 hass, get_state_response=data, entry_id="2"
) )
assert len(hass.data[deconz.DOMAIN]) == 2 assert len(hass.data[deconz.DOMAIN]) == 2

View file

@ -7,7 +7,7 @@ from homeassistant.components import deconz
import homeassistant.components.light as light import homeassistant.components.light as light
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from .test_gateway import DECONZ_WEB_REQUEST, ENTRY_CONFIG, setup_deconz_integration from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
GROUPS = { GROUPS = {
"1": { "1": {
@ -75,10 +75,7 @@ async def test_platform_manually_configured(hass):
async def test_no_lights_or_groups(hass): async def test_no_lights_or_groups(hass):
"""Test that no lights or groups entities are created.""" """Test that no lights or groups entities are created."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert len(gateway.deconz_ids) == 0 assert len(gateway.deconz_ids) == 0
assert len(hass.states.async_all()) == 0 assert len(hass.states.async_all()) == 0
@ -88,9 +85,7 @@ async def test_lights_and_groups(hass):
data = deepcopy(DECONZ_WEB_REQUEST) data = deepcopy(DECONZ_WEB_REQUEST)
data["groups"] = deepcopy(GROUPS) data["groups"] = deepcopy(GROUPS)
data["lights"] = deepcopy(LIGHTS) data["lights"] = deepcopy(LIGHTS)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(hass, get_state_response=data)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert "light.rgb_light" in gateway.deconz_ids assert "light.rgb_light" in gateway.deconz_ids
assert "light.tunable_white_light" in gateway.deconz_ids assert "light.tunable_white_light" in gateway.deconz_ids
assert "light.light_group" in gateway.deconz_ids assert "light.light_group" in gateway.deconz_ids
@ -215,7 +210,6 @@ async def test_disable_light_groups(hass):
data["lights"] = deepcopy(LIGHTS) data["lights"] = deepcopy(LIGHTS)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(
hass, hass,
ENTRY_CONFIG,
options={deconz.gateway.CONF_ALLOW_DECONZ_GROUPS: False}, options={deconz.gateway.CONF_ALLOW_DECONZ_GROUPS: False},
get_state_response=data, get_state_response=data,
) )

View file

@ -7,7 +7,7 @@ from homeassistant.components import deconz
import homeassistant.components.scene as scene import homeassistant.components.scene as scene
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from .test_gateway import DECONZ_WEB_REQUEST, ENTRY_CONFIG, setup_deconz_integration from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
GROUPS = { GROUPS = {
"1": { "1": {
@ -35,10 +35,7 @@ async def test_platform_manually_configured(hass):
async def test_no_scenes(hass): async def test_no_scenes(hass):
"""Test that scenes can be loaded without scenes being available.""" """Test that scenes can be loaded without scenes being available."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert len(gateway.deconz_ids) == 0 assert len(gateway.deconz_ids) == 0
assert len(hass.states.async_all()) == 0 assert len(hass.states.async_all()) == 0
@ -47,9 +44,7 @@ async def test_scenes(hass):
"""Test that scenes works.""" """Test that scenes works."""
data = deepcopy(DECONZ_WEB_REQUEST) data = deepcopy(DECONZ_WEB_REQUEST)
data["groups"] = deepcopy(GROUPS) data["groups"] = deepcopy(GROUPS)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(hass, get_state_response=data)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert "scene.light_group_scene" in gateway.deconz_ids assert "scene.light_group_scene" in gateway.deconz_ids
assert len(hass.states.async_all()) == 1 assert len(hass.states.async_all()) == 1

View file

@ -5,7 +5,7 @@ from homeassistant.components import deconz
import homeassistant.components.sensor as sensor import homeassistant.components.sensor as sensor
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from .test_gateway import DECONZ_WEB_REQUEST, ENTRY_CONFIG, setup_deconz_integration from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
SENSORS = { SENSORS = {
"1": { "1": {
@ -88,10 +88,7 @@ async def test_platform_manually_configured(hass):
async def test_no_sensors(hass): async def test_no_sensors(hass):
"""Test that no sensors in deconz results in no sensor entities.""" """Test that no sensors in deconz results in no sensor entities."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert len(gateway.deconz_ids) == 0 assert len(gateway.deconz_ids) == 0
assert len(hass.states.async_all()) == 0 assert len(hass.states.async_all()) == 0
@ -100,9 +97,7 @@ async def test_sensors(hass):
"""Test successful creation of sensor entities.""" """Test successful creation of sensor entities."""
data = deepcopy(DECONZ_WEB_REQUEST) data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS) data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(hass, get_state_response=data)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert "sensor.light_level_sensor" in gateway.deconz_ids assert "sensor.light_level_sensor" in gateway.deconz_ids
assert "sensor.presence_sensor" not in gateway.deconz_ids assert "sensor.presence_sensor" not in gateway.deconz_ids
assert "sensor.switch_1" not in gateway.deconz_ids assert "sensor.switch_1" not in gateway.deconz_ids
@ -178,7 +173,6 @@ async def test_allow_clip_sensors(hass):
data["sensors"] = deepcopy(SENSORS) data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(
hass, hass,
ENTRY_CONFIG,
options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True}, options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True},
get_state_response=data, get_state_response=data,
) )
@ -227,10 +221,7 @@ async def test_allow_clip_sensors(hass):
async def test_add_new_sensor(hass): async def test_add_new_sensor(hass):
"""Test that adding a new sensor works.""" """Test that adding a new sensor works."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert len(gateway.deconz_ids) == 0 assert len(gateway.deconz_ids) == 0
state_added_event = { state_added_event = {
@ -253,9 +244,7 @@ async def test_add_battery_later(hass):
"""Test that a sensor without an initial battery state creates a battery sensor once state exist.""" """Test that a sensor without an initial battery state creates a battery sensor once state exist."""
data = deepcopy(DECONZ_WEB_REQUEST) data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = {"1": deepcopy(SENSORS["3"])} data["sensors"] = {"1": deepcopy(SENSORS["3"])}
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(hass, get_state_response=data)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
remote = gateway.api.sensors["1"] remote = gateway.api.sensors["1"]
assert len(gateway.deconz_ids) == 0 assert len(gateway.deconz_ids) == 0
assert len(gateway.events) == 1 assert len(gateway.events) == 1

View file

@ -1,5 +1,4 @@
"""deCONZ service tests.""" """deCONZ service tests."""
from copy import deepcopy
from asynctest import Mock, patch from asynctest import Mock, patch
import pytest import pytest
@ -8,12 +7,7 @@ import voluptuous as vol
from homeassistant.components import deconz from homeassistant.components import deconz
from homeassistant.components.deconz.const import CONF_BRIDGEID from homeassistant.components.deconz.const import CONF_BRIDGEID
from .test_gateway import ( from .test_gateway import BRIDGEID, setup_deconz_integration
BRIDGEID,
DECONZ_WEB_REQUEST,
ENTRY_CONFIG,
setup_deconz_integration,
)
GROUP = { GROUP = {
"1": { "1": {
@ -93,10 +87,7 @@ async def test_service_unload_not_registered(hass):
async def test_configure_service_with_field(hass): async def test_configure_service_with_field(hass):
"""Test that service invokes pydeconz with the correct path and data.""" """Test that service invokes pydeconz with the correct path and data."""
data = deepcopy(DECONZ_WEB_REQUEST) await setup_deconz_integration(hass)
await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
data = { data = {
deconz.services.SERVICE_FIELD: "/light/2", deconz.services.SERVICE_FIELD: "/light/2",
@ -116,10 +107,7 @@ async def test_configure_service_with_field(hass):
async def test_configure_service_with_entity(hass): async def test_configure_service_with_entity(hass):
"""Test that service invokes pydeconz with the correct path and data.""" """Test that service invokes pydeconz with the correct path and data."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway.deconz_ids["light.test"] = "/light/1" gateway.deconz_ids["light.test"] = "/light/1"
data = { data = {
@ -139,10 +127,7 @@ async def test_configure_service_with_entity(hass):
async def test_configure_service_with_entity_and_field(hass): async def test_configure_service_with_entity_and_field(hass):
"""Test that service invokes pydeconz with the correct path and data.""" """Test that service invokes pydeconz with the correct path and data."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway.deconz_ids["light.test"] = "/light/1" gateway.deconz_ids["light.test"] = "/light/1"
data = { data = {
@ -163,10 +148,7 @@ async def test_configure_service_with_entity_and_field(hass):
async def test_configure_service_with_faulty_field(hass): async def test_configure_service_with_faulty_field(hass):
"""Test that service invokes pydeconz with the correct path and data.""" """Test that service invokes pydeconz with the correct path and data."""
data = deepcopy(DECONZ_WEB_REQUEST) await setup_deconz_integration(hass)
await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
data = {deconz.services.SERVICE_FIELD: "light/2", deconz.services.SERVICE_DATA: {}} data = {deconz.services.SERVICE_FIELD: "light/2", deconz.services.SERVICE_DATA: {}}
@ -179,10 +161,7 @@ async def test_configure_service_with_faulty_field(hass):
async def test_configure_service_with_faulty_entity(hass): async def test_configure_service_with_faulty_entity(hass):
"""Test that service invokes pydeconz with the correct path and data.""" """Test that service invokes pydeconz with the correct path and data."""
data = deepcopy(DECONZ_WEB_REQUEST) await setup_deconz_integration(hass)
await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
data = { data = {
deconz.services.SERVICE_ENTITY: "light.nonexisting", deconz.services.SERVICE_ENTITY: "light.nonexisting",
@ -199,10 +178,7 @@ async def test_configure_service_with_faulty_entity(hass):
async def test_service_refresh_devices(hass): async def test_service_refresh_devices(hass):
"""Test that service can refresh devices.""" """Test that service can refresh devices."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
data = {CONF_BRIDGEID: BRIDGEID} data = {CONF_BRIDGEID: BRIDGEID}

View file

@ -7,7 +7,7 @@ from homeassistant.components import deconz
import homeassistant.components.switch as switch import homeassistant.components.switch as switch
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from .test_gateway import DECONZ_WEB_REQUEST, ENTRY_CONFIG, setup_deconz_integration from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
SWITCHES = { SWITCHES = {
"1": { "1": {
@ -54,10 +54,7 @@ async def test_platform_manually_configured(hass):
async def test_no_switches(hass): async def test_no_switches(hass):
"""Test that no switch entities are created.""" """Test that no switch entities are created."""
data = deepcopy(DECONZ_WEB_REQUEST) gateway = await setup_deconz_integration(hass)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert len(gateway.deconz_ids) == 0 assert len(gateway.deconz_ids) == 0
assert len(hass.states.async_all()) == 0 assert len(hass.states.async_all()) == 0
@ -66,9 +63,7 @@ async def test_switches(hass):
"""Test that all supported switch entities are created.""" """Test that all supported switch entities are created."""
data = deepcopy(DECONZ_WEB_REQUEST) data = deepcopy(DECONZ_WEB_REQUEST)
data["lights"] = deepcopy(SWITCHES) data["lights"] = deepcopy(SWITCHES)
gateway = await setup_deconz_integration( gateway = await setup_deconz_integration(hass, get_state_response=data)
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
assert "switch.on_off_switch" in gateway.deconz_ids assert "switch.on_off_switch" in gateway.deconz_ids
assert "switch.smart_plug" in gateway.deconz_ids assert "switch.smart_plug" in gateway.deconz_ids
assert "switch.warning_device" in gateway.deconz_ids assert "switch.warning_device" in gateway.deconz_ids