1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

deCONZ improve gateway tests (#26709)

* Improve gateway tests

* Harmonize all tests to use the same gateway initialization method

* Improve scene tests

* Add gateway resync call to platform tests

* Forgot to change switch tests to use common gateway method

* Improve event tests
This commit is contained in:
Robert Svensson
2019-09-19 23:44:09 +02:00
committed by Paulus Schoutsen
parent 9e2cd5116a
commit f5d12669a5
12 changed files with 305 additions and 585 deletions

View File

@@ -3,13 +3,13 @@ from copy import deepcopy
from asynctest import patch
from homeassistant import config_entries
from homeassistant.components import deconz
from homeassistant.setup import async_setup_component
import homeassistant.components.switch as switch
from .test_gateway import ENTRY_CONFIG, DECONZ_WEB_REQUEST, setup_deconz_integration
SWITCHES = {
"1": {
"id": "On off switch id",
@@ -41,50 +41,6 @@ SWITCHES = {
},
}
BRIDGEID = "0123456789"
ENTRY_CONFIG = {
deconz.config_flow.CONF_API_KEY: "ABCDEF",
deconz.config_flow.CONF_BRIDGEID: BRIDGEID,
deconz.config_flow.CONF_HOST: "1.2.3.4",
deconz.config_flow.CONF_PORT: 80,
}
DECONZ_CONFIG = {
"bridgeid": BRIDGEID,
"mac": "00:11:22:33:44:55",
"name": "deCONZ mock gateway",
"sw_version": "2.05.69",
"websocketport": 1234,
}
DECONZ_WEB_REQUEST = {"config": DECONZ_CONFIG}
async def setup_deconz_integration(hass, config, options, get_state_response):
"""Create the deCONZ gateway."""
config_entry = config_entries.ConfigEntry(
version=1,
domain=deconz.DOMAIN,
title="Mock Title",
data=config,
source="test",
connection_class=config_entries.CONN_CLASS_LOCAL_PUSH,
system_options={},
options=options,
entry_id="1",
)
with patch(
"pydeconz.DeconzSession.async_get_state", return_value=get_state_response
), patch("pydeconz.DeconzSession.start", return_value=True):
await deconz.async_setup_entry(hass, config_entry)
await hass.async_block_till_done()
hass.config_entries._entries.append(config_entry)
return hass.data[deconz.DOMAIN][config[deconz.CONF_BRIDGEID]]
async def test_platform_manually_configured(hass):
"""Test that we do not discover anything or try to set up a gateway."""
@@ -189,3 +145,7 @@ async def test_switches(hass):
)
await hass.async_block_till_done()
set_callback.assert_called_with("/lights/3/state", {"alert": "none"})
await gateway.async_reset()
assert len(hass.states.async_all()) == 2