1
mirror of https://github.com/home-assistant/core synced 2024-09-28 03:04:04 +02:00

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
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 = {
"1": {
@ -61,10 +61,7 @@ async def test_platform_manually_configured(hass):
async def test_no_binary_sensors(hass):
"""Test that no sensors in deconz results in no sensor entities."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
assert len(gateway.deconz_ids) == 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."""
data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass, get_state_response=data)
assert "binary_sensor.presence_sensor" 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
@ -118,7 +113,6 @@ async def test_allow_clip_sensor(hass):
data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration(
hass,
ENTRY_CONFIG,
options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True},
get_state_response=data,
)
@ -143,10 +137,7 @@ async def test_allow_clip_sensor(hass):
async def test_add_new_binary_sensor(hass):
"""Test that adding a new binary sensor works."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
assert len(gateway.deconz_ids) == 0
state_added_event = {

View File

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

View File

@ -7,7 +7,7 @@ from homeassistant.components import deconz
import homeassistant.components.cover as cover
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 = {
"1": {
@ -49,10 +49,7 @@ async def test_platform_manually_configured(hass):
async def test_no_covers(hass):
"""Test that no cover entities are created."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
assert len(gateway.deconz_ids) == 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."""
data = deepcopy(DECONZ_WEB_REQUEST)
data["lights"] = deepcopy(COVERS)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass, get_state_response=data)
assert "cover.level_controllable_cover" in gateway.deconz_ids
assert "cover.window_covering_device" 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 .test_gateway import DECONZ_WEB_REQUEST, ENTRY_CONFIG, setup_deconz_integration
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
SENSORS = {
"1": {
@ -31,9 +31,7 @@ async def test_deconz_events(hass):
"""Test successful creation of deconz events."""
data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass, get_state_response=data)
assert "sensor.switch_1" 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

View File

@ -3,7 +3,7 @@ from copy import deepcopy
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
@ -34,9 +34,7 @@ async def test_get_triggers(hass):
"""Test triggers work."""
data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass, get_state_response=data)
device_id = gateway.events[0].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.components import deconz, ssdp
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from tests.common import MockConfigEntry
BRIDGEID = "01234E56789A"
ENTRY_CONFIG = {
@ -18,6 +19,8 @@ ENTRY_CONFIG = {
deconz.config_flow.CONF_PORT: 80,
}
ENTRY_OPTIONS = {}
DECONZ_CONFIG = {
"bridgeid": BRIDGEID,
"ipaddress": "1.2.3.4",
@ -29,49 +32,48 @@ DECONZ_CONFIG = {
"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."""
config_entry = config_entries.ConfigEntry(
version=1,
config_entry = MockConfigEntry(
domain=deconz.DOMAIN,
title="Mock Title",
data=config,
source="test",
data=deepcopy(config),
connection_class=config_entries.CONN_CLASS_LOCAL_PUSH,
system_options={},
options=options,
entry_id="1",
options=deepcopy(options),
entry_id=entry_id,
)
for resource in ("groups", "lights", "sensors"):
if resource not in get_state_response:
get_state_response[resource] = {}
config_entry.add_to_hass(hass)
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):
await deconz.async_setup_entry(hass, config_entry)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
hass.config_entries._entries.append(config_entry)
bridgeid = get_state_response["config"]["bridgeid"]
return hass.data[deconz.DOMAIN].get(bridgeid)
async def test_gateway_setup(hass):
"""Successful setup."""
data = deepcopy(DECONZ_WEB_REQUEST)
with patch(
"homeassistant.config_entries.ConfigEntries.async_forward_entry_setup",
return_value=True,
) as forward_entry_setup:
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
assert gateway.bridgeid == BRIDGEID
assert gateway.master is True
assert gateway.option_allow_clip_sensor is False
@ -92,34 +94,26 @@ async def test_gateway_setup(hass):
async def test_gateway_retry(hass):
"""Retry setup."""
data = deepcopy(DECONZ_WEB_REQUEST)
with patch(
"homeassistant.components.deconz.gateway.get_gateway",
side_effect=deconz.errors.CannotConnect,
), pytest.raises(ConfigEntryNotReady):
await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
):
await setup_deconz_integration(hass)
assert not hass.data[deconz.DOMAIN]
async def test_gateway_setup_fails(hass):
"""Retry setup."""
data = deepcopy(DECONZ_WEB_REQUEST)
with patch(
"homeassistant.components.deconz.gateway.get_gateway", side_effect=Exception
):
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
assert gateway is None
async def test_connection_status_signalling(hass):
"""Make sure that connection status triggers a dispatcher send."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
event_call = Mock()
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):
"""Make sure that connection status triggers a dispatcher send."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
assert gateway.api.host == "1.2.3.4"
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):
"""Make sure that connection status triggers a dispatcher send."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
result = await gateway.async_reset()
await hass.async_block_till_done()

View File

@ -3,12 +3,10 @@ import asyncio
from copy import deepcopy
from asynctest import patch
import pytest
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_PORT = 80
@ -35,31 +33,21 @@ async def setup_entry(hass, entry):
async def test_setup_entry_fails(hass):
"""Test setup entry fails if deCONZ is not available."""
data = deepcopy(DECONZ_WEB_REQUEST)
with patch("pydeconz.DeconzSession.initialize", side_effect=Exception):
await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
await setup_deconz_integration(hass)
assert not hass.data[deconz.DOMAIN]
async def test_setup_entry_no_available_bridge(hass):
"""Test setup entry fails if deCONZ is not available."""
data = deepcopy(DECONZ_WEB_REQUEST)
with patch(
"pydeconz.DeconzSession.initialize", side_effect=asyncio.TimeoutError
), pytest.raises(ConfigEntryNotReady):
await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
with patch("pydeconz.DeconzSession.initialize", side_effect=asyncio.TimeoutError):
await setup_deconz_integration(hass)
assert not hass.data[deconz.DOMAIN]
async def test_setup_entry_successful(hass):
"""Test setup entry is successful."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
assert 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):
"""Test setup entry is successful with multiple gateways."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
data2 = deepcopy(DECONZ_WEB_REQUEST)
data2["config"]["bridgeid"] = "01234E56789B"
data = deepcopy(DECONZ_WEB_REQUEST)
data["config"]["bridgeid"] = "01234E56789B"
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
@ -86,10 +71,7 @@ async def test_setup_entry_multiple_gateways(hass):
async def test_unload_entry(hass):
"""Test being able to unload an entry."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
assert hass.data[deconz.DOMAIN]
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):
"""Test being able to unload an entry and master gateway gets moved."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
data2 = deepcopy(DECONZ_WEB_REQUEST)
data2["config"]["bridgeid"] = "01234E56789B"
data = deepcopy(DECONZ_WEB_REQUEST)
data["config"]["bridgeid"] = "01234E56789B"
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

View File

@ -7,7 +7,7 @@ from homeassistant.components import deconz
import homeassistant.components.light as light
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 = {
"1": {
@ -75,10 +75,7 @@ async def test_platform_manually_configured(hass):
async def test_no_lights_or_groups(hass):
"""Test that no lights or groups entities are created."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
assert len(gateway.deconz_ids) == 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["groups"] = deepcopy(GROUPS)
data["lights"] = deepcopy(LIGHTS)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass, get_state_response=data)
assert "light.rgb_light" in gateway.deconz_ids
assert "light.tunable_white_light" 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)
gateway = await setup_deconz_integration(
hass,
ENTRY_CONFIG,
options={deconz.gateway.CONF_ALLOW_DECONZ_GROUPS: False},
get_state_response=data,
)

View File

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

View File

@ -5,7 +5,7 @@ from homeassistant.components import deconz
import homeassistant.components.sensor as sensor
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 = {
"1": {
@ -88,10 +88,7 @@ async def test_platform_manually_configured(hass):
async def test_no_sensors(hass):
"""Test that no sensors in deconz results in no sensor entities."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
assert len(gateway.deconz_ids) == 0
assert len(hass.states.async_all()) == 0
@ -100,9 +97,7 @@ async def test_sensors(hass):
"""Test successful creation of sensor entities."""
data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass, get_state_response=data)
assert "sensor.light_level_sensor" in gateway.deconz_ids
assert "sensor.presence_sensor" 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)
gateway = await setup_deconz_integration(
hass,
ENTRY_CONFIG,
options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True},
get_state_response=data,
)
@ -227,10 +221,7 @@ async def test_allow_clip_sensors(hass):
async def test_add_new_sensor(hass):
"""Test that adding a new sensor works."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
assert len(gateway.deconz_ids) == 0
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."""
data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = {"1": deepcopy(SENSORS["3"])}
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass, get_state_response=data)
remote = gateway.api.sensors["1"]
assert len(gateway.deconz_ids) == 0
assert len(gateway.events) == 1

View File

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

View File

@ -7,7 +7,7 @@ from homeassistant.components import deconz
import homeassistant.components.switch as switch
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 = {
"1": {
@ -54,10 +54,7 @@ async def test_platform_manually_configured(hass):
async def test_no_switches(hass):
"""Test that no switch entities are created."""
data = deepcopy(DECONZ_WEB_REQUEST)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass)
assert len(gateway.deconz_ids) == 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."""
data = deepcopy(DECONZ_WEB_REQUEST)
data["lights"] = deepcopy(SWITCHES)
gateway = await setup_deconz_integration(
hass, ENTRY_CONFIG, options={}, get_state_response=data
)
gateway = await setup_deconz_integration(hass, get_state_response=data)
assert "switch.on_off_switch" in gateway.deconz_ids
assert "switch.smart_plug" in gateway.deconz_ids
assert "switch.warning_device" in gateway.deconz_ids