mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 10:17:51 +00:00
Use fixtures in deCONZ select tests (#120943)
This commit is contained in:
parent
ce54ca9c8e
commit
77fc1c991c
@ -1,6 +1,7 @@
|
|||||||
"""deCONZ select platform tests."""
|
"""deCONZ select platform tests."""
|
||||||
|
|
||||||
from unittest.mock import patch
|
from collections.abc import Callable
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from pydeconz.models.sensor.presence import (
|
from pydeconz.models.sensor.presence import (
|
||||||
PresenceConfigDeviceMode,
|
PresenceConfigDeviceMode,
|
||||||
@ -13,54 +14,38 @@ from homeassistant.components.select import (
|
|||||||
DOMAIN as SELECT_DOMAIN,
|
DOMAIN as SELECT_DOMAIN,
|
||||||
SERVICE_SELECT_OPTION,
|
SERVICE_SELECT_OPTION,
|
||||||
)
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, EntityCategory
|
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, EntityCategory
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
|
|
||||||
from .test_gateway import (
|
|
||||||
DECONZ_WEB_REQUEST,
|
|
||||||
mock_deconz_put_request,
|
|
||||||
setup_deconz_integration,
|
|
||||||
)
|
|
||||||
|
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
|
|
||||||
async def test_no_select_entities(
|
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
|
||||||
) -> None:
|
|
||||||
"""Test that no sensors in deconz results in no sensor entities."""
|
|
||||||
await setup_deconz_integration(hass, aioclient_mock)
|
|
||||||
assert len(hass.states.async_all()) == 0
|
|
||||||
|
|
||||||
|
|
||||||
TEST_DATA = [
|
TEST_DATA = [
|
||||||
( # Presence Device Mode
|
( # Presence Device Mode
|
||||||
{
|
{
|
||||||
"sensors": {
|
"1": {
|
||||||
"1": {
|
"config": {
|
||||||
"config": {
|
"devicemode": "undirected",
|
||||||
"devicemode": "undirected",
|
"on": True,
|
||||||
"on": True,
|
"reachable": True,
|
||||||
"reachable": True,
|
"sensitivity": 3,
|
||||||
"sensitivity": 3,
|
"triggerdistance": "medium",
|
||||||
"triggerdistance": "medium",
|
},
|
||||||
},
|
"etag": "13ff209f9401b317987d42506dd4cd79",
|
||||||
"etag": "13ff209f9401b317987d42506dd4cd79",
|
"lastannounced": None,
|
||||||
"lastannounced": None,
|
"lastseen": "2022-06-28T23:13Z",
|
||||||
"lastseen": "2022-06-28T23:13Z",
|
"manufacturername": "aqara",
|
||||||
"manufacturername": "aqara",
|
"modelid": "lumi.motion.ac01",
|
||||||
"modelid": "lumi.motion.ac01",
|
"name": "Aqara FP1",
|
||||||
"name": "Aqara FP1",
|
"state": {
|
||||||
"state": {
|
"lastupdated": "2022-06-28T23:13:38.577",
|
||||||
"lastupdated": "2022-06-28T23:13:38.577",
|
"presence": True,
|
||||||
"presence": True,
|
"presenceevent": "leave",
|
||||||
"presenceevent": "leave",
|
},
|
||||||
},
|
"swversion": "20210121",
|
||||||
"swversion": "20210121",
|
"type": "ZHAPresence",
|
||||||
"type": "ZHAPresence",
|
"uniqueid": "xx:xx:xx:xx:xx:xx:xx:xx-01-0406",
|
||||||
"uniqueid": "xx:xx:xx:xx:xx:xx:xx:xx-01-0406",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -80,30 +65,28 @@ TEST_DATA = [
|
|||||||
),
|
),
|
||||||
( # Presence Sensitivity
|
( # Presence Sensitivity
|
||||||
{
|
{
|
||||||
"sensors": {
|
"1": {
|
||||||
"1": {
|
"config": {
|
||||||
"config": {
|
"devicemode": "undirected",
|
||||||
"devicemode": "undirected",
|
"on": True,
|
||||||
"on": True,
|
"reachable": True,
|
||||||
"reachable": True,
|
"sensitivity": 3,
|
||||||
"sensitivity": 3,
|
"triggerdistance": "medium",
|
||||||
"triggerdistance": "medium",
|
},
|
||||||
},
|
"etag": "13ff209f9401b317987d42506dd4cd79",
|
||||||
"etag": "13ff209f9401b317987d42506dd4cd79",
|
"lastannounced": None,
|
||||||
"lastannounced": None,
|
"lastseen": "2022-06-28T23:13Z",
|
||||||
"lastseen": "2022-06-28T23:13Z",
|
"manufacturername": "aqara",
|
||||||
"manufacturername": "aqara",
|
"modelid": "lumi.motion.ac01",
|
||||||
"modelid": "lumi.motion.ac01",
|
"name": "Aqara FP1",
|
||||||
"name": "Aqara FP1",
|
"state": {
|
||||||
"state": {
|
"lastupdated": "2022-06-28T23:13:38.577",
|
||||||
"lastupdated": "2022-06-28T23:13:38.577",
|
"presence": True,
|
||||||
"presence": True,
|
"presenceevent": "leave",
|
||||||
"presenceevent": "leave",
|
},
|
||||||
},
|
"swversion": "20210121",
|
||||||
"swversion": "20210121",
|
"type": "ZHAPresence",
|
||||||
"type": "ZHAPresence",
|
"uniqueid": "xx:xx:xx:xx:xx:xx:xx:xx-01-0406",
|
||||||
"uniqueid": "xx:xx:xx:xx:xx:xx:xx:xx-01-0406",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -123,30 +106,28 @@ TEST_DATA = [
|
|||||||
),
|
),
|
||||||
( # Presence Trigger Distance
|
( # Presence Trigger Distance
|
||||||
{
|
{
|
||||||
"sensors": {
|
"1": {
|
||||||
"1": {
|
"config": {
|
||||||
"config": {
|
"devicemode": "undirected",
|
||||||
"devicemode": "undirected",
|
"on": True,
|
||||||
"on": True,
|
"reachable": True,
|
||||||
"reachable": True,
|
"sensitivity": 3,
|
||||||
"sensitivity": 3,
|
"triggerdistance": "medium",
|
||||||
"triggerdistance": "medium",
|
},
|
||||||
},
|
"etag": "13ff209f9401b317987d42506dd4cd79",
|
||||||
"etag": "13ff209f9401b317987d42506dd4cd79",
|
"lastannounced": None,
|
||||||
"lastannounced": None,
|
"lastseen": "2022-06-28T23:13Z",
|
||||||
"lastseen": "2022-06-28T23:13Z",
|
"manufacturername": "aqara",
|
||||||
"manufacturername": "aqara",
|
"modelid": "lumi.motion.ac01",
|
||||||
"modelid": "lumi.motion.ac01",
|
"name": "Aqara FP1",
|
||||||
"name": "Aqara FP1",
|
"state": {
|
||||||
"state": {
|
"lastupdated": "2022-06-28T23:13:38.577",
|
||||||
"lastupdated": "2022-06-28T23:13:38.577",
|
"presence": True,
|
||||||
"presence": True,
|
"presenceevent": "leave",
|
||||||
"presenceevent": "leave",
|
},
|
||||||
},
|
"swversion": "20210121",
|
||||||
"swversion": "20210121",
|
"type": "ZHAPresence",
|
||||||
"type": "ZHAPresence",
|
"uniqueid": "xx:xx:xx:xx:xx:xx:xx:xx-01-0406",
|
||||||
"uniqueid": "xx:xx:xx:xx:xx:xx:xx:xx-01-0406",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -167,19 +148,16 @@ TEST_DATA = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(("raw_data", "expected"), TEST_DATA)
|
@pytest.mark.parametrize(("sensor_payload", "expected"), TEST_DATA)
|
||||||
async def test_select(
|
async def test_select(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
config_entry_setup: ConfigEntry,
|
||||||
raw_data,
|
mock_put_request: Callable[[str, str], AiohttpClientMocker],
|
||||||
expected,
|
expected: dict[str, Any],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test successful creation of button entities."""
|
"""Test successful creation of button entities."""
|
||||||
with patch.dict(DECONZ_WEB_REQUEST, raw_data):
|
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == expected["entity_count"]
|
assert len(hass.states.async_all()) == expected["entity_count"]
|
||||||
|
|
||||||
# Verify state data
|
# Verify state data
|
||||||
@ -196,13 +174,16 @@ async def test_select(
|
|||||||
# Verify device registry data
|
# Verify device registry data
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
len(
|
||||||
|
dr.async_entries_for_config_entry(
|
||||||
|
device_registry, config_entry_setup.entry_id
|
||||||
|
)
|
||||||
|
)
|
||||||
== expected["device_count"]
|
== expected["device_count"]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Verify selecting option
|
# Verify selecting option
|
||||||
|
aioclient_mock = mock_put_request(expected["request"])
|
||||||
mock_deconz_put_request(aioclient_mock, config_entry.data, expected["request"])
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
SELECT_DOMAIN,
|
SELECT_DOMAIN,
|
||||||
@ -217,11 +198,11 @@ async def test_select(
|
|||||||
|
|
||||||
# Unload entry
|
# Unload entry
|
||||||
|
|
||||||
await hass.config_entries.async_unload(config_entry.entry_id)
|
await hass.config_entries.async_unload(config_entry_setup.entry_id)
|
||||||
assert hass.states.get(expected["entity_id"]).state == STATE_UNAVAILABLE
|
assert hass.states.get(expected["entity_id"]).state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
# Remove entry
|
# Remove entry
|
||||||
|
|
||||||
await hass.config_entries.async_remove(config_entry.entry_id)
|
await hass.config_entries.async_remove(config_entry_setup.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(hass.states.async_all()) == 0
|
assert len(hass.states.async_all()) == 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user