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
|
@ -3,6 +3,7 @@ from copy import deepcopy
|
|||
|
||||
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
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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 = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue