Refactor deCONZ tests (#41362)

* Use hass.config_entries.async_unload

* Return config_entry from setup_deconz_integration
This commit is contained in:
Robert Svensson
2020-10-06 23:25:57 +02:00
committed by GitHub
parent 42fb0e9545
commit cbb4324c84
14 changed files with 130 additions and 102 deletions

View File

@@ -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.switch as switch
from homeassistant.setup import async_setup_component
@@ -79,7 +80,8 @@ async def test_power_plugs(hass):
"""Test that all supported switch entities are created."""
data = deepcopy(DECONZ_WEB_REQUEST)
data["lights"] = deepcopy(POWER_PLUGS)
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()) == 4
assert hass.states.get("switch.on_off_switch").state == "on"
@@ -130,7 +132,7 @@ async def test_power_plugs(hass):
await hass.async_block_till_done()
set_callback.assert_called_with("put", "/lights/1/state", json={"on": False})
await gateway.async_reset()
await hass.config_entries.async_unload(config_entry.entry_id)
assert len(hass.states.async_all()) == 0
@@ -139,7 +141,8 @@ async def test_sirens(hass):
"""Test that siren entities are created."""
data = deepcopy(DECONZ_WEB_REQUEST)
data["lights"] = deepcopy(SIRENS)
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("switch.warning_device").state == "on"
@@ -192,6 +195,6 @@ async def test_sirens(hass):
"put", "/lights/1/state", json={"alert": "none"}
)
await gateway.async_reset()
await hass.config_entries.async_unload(config_entry.entry_id)
assert len(hass.states.async_all()) == 0