Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions tests/components/deconz/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
DEVICE_CLASS_MOTION,
DEVICE_CLASS_VIBRATION,
)
from homeassistant.components.deconz.gateway import get_gateway_from_config_entry
from homeassistant.helpers.entity_registry import async_entries_for_config_entry
from homeassistant.setup import async_setup_component

Expand Down Expand Up @@ -74,7 +75,8 @@ 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, get_state_response=data)
config_entry = await setup_deconz_integration(hass, get_state_response=data)
gateway = get_gateway_from_config_entry(hass, config_entry)

assert len(hass.states.async_all()) == 3
presence_sensor = hass.states.get("binary_sensor.presence_sensor")
Expand All @@ -98,7 +100,7 @@ async def test_binary_sensors(hass):

assert hass.states.get("binary_sensor.presence_sensor").state == "on"

await gateway.async_reset()
await hass.config_entries.async_unload(config_entry.entry_id)

assert len(hass.states.async_all()) == 0

Expand All @@ -107,7 +109,7 @@ async def test_allow_clip_sensor(hass):
"""Test that CLIP sensors can be allowed."""
data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration(
config_entry = await setup_deconz_integration(
hass,
options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True},
get_state_response=data,
Expand All @@ -122,7 +124,7 @@ async def test_allow_clip_sensor(hass):
# Disallow clip sensors

hass.config_entries.async_update_entry(
gateway.config_entry, options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: False}
config_entry, options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: False}
)
await hass.async_block_till_done()

Expand All @@ -132,7 +134,7 @@ async def test_allow_clip_sensor(hass):
# Allow clip sensors

hass.config_entries.async_update_entry(
gateway.config_entry, options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True}
config_entry, options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True}
)
await hass.async_block_till_done()

Expand All @@ -142,7 +144,8 @@ async def test_allow_clip_sensor(hass):

async def test_add_new_binary_sensor(hass):
"""Test that adding a new binary sensor works."""
gateway = await setup_deconz_integration(hass)
config_entry = await setup_deconz_integration(hass)
gateway = deconz.gateway.get_gateway_from_config_entry(hass, config_entry)
assert len(hass.states.async_all()) == 0

state_added_event = {
Expand All @@ -161,10 +164,11 @@ async def test_add_new_binary_sensor(hass):

async def test_add_new_binary_sensor_ignored(hass):
"""Test that adding a new binary sensor is not allowed."""
gateway = await setup_deconz_integration(
config_entry = await setup_deconz_integration(
hass,
options={deconz.gateway.CONF_ALLOW_NEW_DEVICES: False},
)
gateway = get_gateway_from_config_entry(hass, config_entry)
assert len(hass.states.async_all()) == 0

state_added_event = {
Expand All @@ -181,10 +185,5 @@ async def test_add_new_binary_sensor_ignored(hass):

entity_registry = await hass.helpers.entity_registry.async_get_registry()
assert (
len(
async_entries_for_config_entry(
entity_registry, gateway.config_entry.entry_id
)
)
== 0
len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 0
)
18 changes: 11 additions & 7 deletions tests/components/deconz/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from homeassistant.components import deconz
import homeassistant.components.climate as climate
from homeassistant.components.deconz.gateway import get_gateway_from_config_entry
from homeassistant.setup import async_setup_component

from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
Expand Down Expand Up @@ -56,7 +57,8 @@ 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, get_state_response=data)
config_entry = await setup_deconz_integration(hass, get_state_response=data)
gateway = get_gateway_from_config_entry(hass, config_entry)

assert len(hass.states.async_all()) == 2
assert hass.states.get("climate.thermostat").state == "auto"
Expand Down Expand Up @@ -166,7 +168,7 @@ async def test_climate_devices(hass):
"put", "/sensors/1/config", json={"heatsetpoint": 2000.0}
)

await gateway.async_reset()
await hass.config_entries.async_unload(config_entry.entry_id)

assert len(hass.states.async_all()) == 0

Expand All @@ -175,7 +177,7 @@ async def test_clip_climate_device(hass):
"""Test successful creation of sensor entities."""
data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration(
config_entry = await setup_deconz_integration(
hass,
options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True},
get_state_response=data,
Expand All @@ -190,7 +192,7 @@ async def test_clip_climate_device(hass):
# Disallow clip sensors

hass.config_entries.async_update_entry(
gateway.config_entry, options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: False}
config_entry, options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: False}
)
await hass.async_block_till_done()

Expand All @@ -200,7 +202,7 @@ async def test_clip_climate_device(hass):
# Allow clip sensors

hass.config_entries.async_update_entry(
gateway.config_entry, options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True}
config_entry, options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True}
)
await hass.async_block_till_done()

Expand All @@ -212,7 +214,8 @@ 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, get_state_response=data)
config_entry = await setup_deconz_integration(hass, get_state_response=data)
gateway = get_gateway_from_config_entry(hass, config_entry)

assert hass.states.get("climate.thermostat").state == "auto"

Expand All @@ -232,7 +235,8 @@ async def test_verify_state_update(hass):

async def test_add_new_climate_device(hass):
"""Test that adding a new climate device works."""
gateway = await setup_deconz_integration(hass)
config_entry = await setup_deconz_integration(hass)
gateway = get_gateway_from_config_entry(hass, config_entry)
assert len(hass.states.async_all()) == 0

state_added_event = {
Expand Down
28 changes: 14 additions & 14 deletions tests/components/deconz/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async def test_manual_configuration_after_discovery_ResponseError(hass, aioclien

async def test_manual_configuration_update_configuration(hass, aioclient_mock):
"""Test that manual configuration can update existing config entry."""
gateway = await setup_deconz_integration(hass)
config_entry = await setup_deconz_integration(hass)

aioclient_mock.get(
pydeconz.utils.URL_DISCOVER,
Expand Down Expand Up @@ -240,7 +240,7 @@ async def test_manual_configuration_update_configuration(hass, aioclient_mock):

assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
assert gateway.config_entry.data[CONF_HOST] == "2.3.4.5"
assert config_entry.data[CONF_HOST] == "2.3.4.5"


async def test_manual_configuration_dont_update_configuration(hass, aioclient_mock):
Expand Down Expand Up @@ -436,7 +436,7 @@ async def test_ssdp_discovery_not_deconz_bridge(hass):

async def test_ssdp_discovery_update_configuration(hass):
"""Test if a discovered bridge is configured but updates with new attributes."""
gateway = await setup_deconz_integration(hass)
config_entry = await setup_deconz_integration(hass)

with patch(
"homeassistant.components.deconz.async_setup_entry",
Expand All @@ -455,13 +455,13 @@ async def test_ssdp_discovery_update_configuration(hass):

assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
assert gateway.config_entry.data[CONF_HOST] == "2.3.4.5"
assert config_entry.data[CONF_HOST] == "2.3.4.5"
assert len(mock_setup_entry.mock_calls) == 1


async def test_ssdp_discovery_dont_update_configuration(hass):
"""Test if a discovered bridge has already been configured."""
gateway = await setup_deconz_integration(hass)
config_entry = await setup_deconz_integration(hass)

result = await hass.config_entries.flow.async_init(
DOMAIN,
Expand All @@ -475,12 +475,12 @@ async def test_ssdp_discovery_dont_update_configuration(hass):

assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
assert gateway.config_entry.data[CONF_HOST] == "1.2.3.4"
assert config_entry.data[CONF_HOST] == "1.2.3.4"


async def test_ssdp_discovery_dont_update_existing_hassio_configuration(hass):
"""Test to ensure the SSDP discovery does not update an Hass.io entry."""
gateway = await setup_deconz_integration(hass, source="hassio")
config_entry = await setup_deconz_integration(hass, source="hassio")

result = await hass.config_entries.flow.async_init(
DOMAIN,
Expand All @@ -494,7 +494,7 @@ async def test_ssdp_discovery_dont_update_existing_hassio_configuration(hass):

assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
assert gateway.config_entry.data[CONF_HOST] == "1.2.3.4"
assert config_entry.data[CONF_HOST] == "1.2.3.4"


async def test_flow_hassio_discovery(hass):
Expand Down Expand Up @@ -537,7 +537,7 @@ async def test_flow_hassio_discovery(hass):

async def test_hassio_discovery_update_configuration(hass):
"""Test we can update an existing config entry."""
gateway = await setup_deconz_integration(hass)
config_entry = await setup_deconz_integration(hass)

with patch(
"homeassistant.components.deconz.async_setup_entry",
Expand All @@ -557,9 +557,9 @@ async def test_hassio_discovery_update_configuration(hass):

assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
assert gateway.config_entry.data[CONF_HOST] == "2.3.4.5"
assert gateway.config_entry.data[CONF_PORT] == 8080
assert gateway.config_entry.data[CONF_API_KEY] == "updated"
assert config_entry.data[CONF_HOST] == "2.3.4.5"
assert config_entry.data[CONF_PORT] == 8080
assert config_entry.data[CONF_API_KEY] == "updated"
assert len(mock_setup_entry.mock_calls) == 1


Expand All @@ -584,9 +584,9 @@ async def test_hassio_discovery_dont_update_configuration(hass):

async def test_option_flow(hass):
"""Test config flow options."""
gateway = await setup_deconz_integration(hass)
config_entry = await setup_deconz_integration(hass)

result = await hass.config_entries.options.async_init(gateway.config_entry.entry_id)
result = await hass.config_entries.options.async_init(config_entry.entry_id)

assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "deconz_devices"
Expand Down
6 changes: 4 additions & 2 deletions tests/components/deconz/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from homeassistant.components import deconz
import homeassistant.components.cover as cover
from homeassistant.components.deconz.gateway import get_gateway_from_config_entry
from homeassistant.setup import async_setup_component

from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
Expand Down Expand Up @@ -73,7 +74,8 @@ 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, get_state_response=data)
config_entry = await setup_deconz_integration(hass, get_state_response=data)
gateway = get_gateway_from_config_entry(hass, config_entry)

assert len(hass.states.async_all()) == 5
assert hass.states.get("cover.level_controllable_cover").state == "open"
Expand Down Expand Up @@ -161,6 +163,6 @@ async def test_cover(hass):
assert deconz_old_brightness_cover.state == "closed"
assert deconz_old_brightness_cover.attributes["current_position"] == 0

await gateway.async_reset()
await hass.config_entries.async_unload(config_entry.entry_id)

assert len(hass.states.async_all()) == 0
6 changes: 4 additions & 2 deletions tests/components/deconz/test_deconz_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from copy import deepcopy

from homeassistant.components.deconz.deconz_event import CONF_DECONZ_EVENT
from homeassistant.components.deconz.gateway import get_gateway_from_config_entry

from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration

Expand Down Expand Up @@ -55,7 +56,8 @@ 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, get_state_response=data)
config_entry = await setup_deconz_integration(hass, get_state_response=data)
gateway = get_gateway_from_config_entry(hass, config_entry)

assert len(hass.states.async_all()) == 3
assert len(gateway.events) == 5
Expand Down Expand Up @@ -112,7 +114,7 @@ async def test_deconz_events(hass):
"xy": [0.5982, 0.3897],
}

await gateway.async_reset()
await hass.config_entries.async_unload(config_entry.entry_id)

assert len(hass.states.async_all()) == 0
assert len(gateway.events) == 0
7 changes: 5 additions & 2 deletions tests/components/deconz/test_device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from copy import deepcopy

from homeassistant.components.deconz import device_trigger
from homeassistant.components.deconz.gateway import get_gateway_from_config_entry

from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration

Expand Down Expand Up @@ -34,7 +35,8 @@ async def test_get_triggers(hass):
"""Test triggers work."""
data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration(hass, get_state_response=data)
config_entry = await setup_deconz_integration(hass, get_state_response=data)
gateway = get_gateway_from_config_entry(hass, config_entry)
device_id = gateway.events[0].device_id
triggers = await async_get_device_automations(hass, "trigger", device_id)

Expand Down Expand Up @@ -97,7 +99,8 @@ async def test_helper_successful(hass):
"""Verify trigger helper."""
data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration(hass, get_state_response=data)
config_entry = await setup_deconz_integration(hass, get_state_response=data)
gateway = get_gateway_from_config_entry(hass, config_entry)
device_id = gateway.events[0].device_id
deconz_event = device_trigger._get_deconz_event_from_device_id(hass, device_id)
assert deconz_event == gateway.events[0]
Expand Down
Loading