Refactor deCONZ tests (#41362)
* Use hass.config_entries.async_unload * Return config_entry from setup_deconz_integration
This commit is contained in:
parent
42fb0e9545
commit
cbb4324c84
14 changed files with 130 additions and 102 deletions
|
@ -2,6 +2,7 @@
|
|||
from copy import deepcopy
|
||||
|
||||
from homeassistant.components import deconz
|
||||
from homeassistant.components.deconz.gateway import get_gateway_from_config_entry
|
||||
import homeassistant.components.sensor as sensor
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_BATTERY,
|
||||
|
@ -101,7 +102,8 @@ 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, 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
|
||||
|
||||
|
@ -157,7 +159,7 @@ async def test_sensors(hass):
|
|||
|
||||
assert hass.states.get("sensor.switch_2_battery_level").state == "75"
|
||||
|
||||
await gateway.async_reset()
|
||||
await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
|
@ -166,7 +168,7 @@ async def test_allow_clip_sensors(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,
|
||||
|
@ -178,7 +180,7 @@ async def test_allow_clip_sensors(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()
|
||||
|
||||
|
@ -188,7 +190,7 @@ async def test_allow_clip_sensors(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()
|
||||
|
||||
|
@ -198,7 +200,8 @@ async def test_allow_clip_sensors(hass):
|
|||
|
||||
async def test_add_new_sensor(hass):
|
||||
"""Test that adding a new sensor 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 = {
|
||||
|
@ -219,7 +222,8 @@ 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, get_state_response=data)
|
||||
config_entry = await setup_deconz_integration(hass, get_state_response=data)
|
||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
||||
remote = gateway.api.sensors["1"]
|
||||
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue