Improve deCONZ websocket fixture (#121332)

This commit is contained in:
Robert Svensson 2024-07-05 22:35:06 +02:00 committed by GitHub
parent 9d204613e8
commit 1b8944dab6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 185 additions and 114 deletions

View file

@ -2,7 +2,7 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable, Generator
from types import MappingProxyType from types import MappingProxyType
from typing import Any from typing import Any
from unittest.mock import patch from unittest.mock import patch
@ -20,6 +20,9 @@ from tests.components.light.conftest import mock_light_profiles # noqa: F401
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
type ConfigEntryFactoryType = Callable[[ConfigEntry | None], ConfigEntry] type ConfigEntryFactoryType = Callable[[ConfigEntry | None], ConfigEntry]
type WebsocketDataType = Callable[[dict[str, Any]], None]
type WebsocketStateType = Callable[[str], None]
type _WebsocketMock = Generator[Any, Any, Callable[[dict[str, Any] | None, str], None]]
# Config entry fixtures # Config entry fixtures
@ -217,22 +220,46 @@ async def fixture_config_entry_setup(
# Websocket fixtures # Websocket fixtures
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True, name="_mock_websocket")
def mock_deconz_websocket(): def fixture_websocket() -> _WebsocketMock:
"""No real websocket allowed.""" """No real websocket allowed."""
with patch("pydeconz.gateway.WSClient") as mock: with patch("pydeconz.gateway.WSClient") as mock:
async def make_websocket_call(data: dict | None = None, state: str = ""): async def make_websocket_call(
data: dict[str, Any] | None = None, state: str = ""
) -> None:
"""Generate a websocket call.""" """Generate a websocket call."""
pydeconz_gateway_session_handler = mock.call_args[0][3] pydeconz_gateway_session_handler = mock.call_args[0][3]
signal: Signal
if data: if data:
mock.return_value.data = data mock.return_value.data = data
await pydeconz_gateway_session_handler(signal=Signal.DATA) signal = Signal.DATA
elif state: elif state:
mock.return_value.state = state mock.return_value.state = state
await pydeconz_gateway_session_handler(signal=Signal.CONNECTION_STATE) signal = Signal.CONNECTION_STATE
else: await pydeconz_gateway_session_handler(signal)
raise NotImplementedError
yield make_websocket_call yield make_websocket_call
@pytest.fixture(name="mock_websocket_data")
def fixture_websocket_data(_mock_websocket: _WebsocketMock) -> WebsocketDataType:
"""Fixture to send websocket data."""
async def change_websocket_data(data: dict[str, Any]) -> None:
"""Provide new data on the websocket."""
await _mock_websocket(data=data)
return change_websocket_data
@pytest.fixture(name="mock_websocket_state")
def fixture_websocket_state(_mock_websocket: _WebsocketMock) -> WebsocketStateType:
"""Fixture to set websocket state."""
async def change_websocket_state(state: str) -> None:
"""Simulate a change to the websocket connection state."""
await _mock_websocket(state=state)
return change_websocket_state

View file

@ -28,6 +28,8 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from .conftest import WebsocketDataType
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
@ -102,7 +104,7 @@ async def test_alarm_control_panel(
aioclient_mock: AiohttpClientMocker, aioclient_mock: AiohttpClientMocker,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test successful creation of alarm control panel entities.""" """Test successful creation of alarm control panel entities."""
assert len(hass.states.async_all()) == 4 assert len(hass.states.async_all()) == 4
@ -117,7 +119,7 @@ async def test_alarm_control_panel(
"id": "0", "id": "0",
"state": {"panel": AncillaryControlPanel.ARMED_AWAY}, "state": {"panel": AncillaryControlPanel.ARMED_AWAY},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("alarm_control_panel.keypad").state == STATE_ALARM_ARMED_AWAY assert hass.states.get("alarm_control_panel.keypad").state == STATE_ALARM_ARMED_AWAY
@ -131,7 +133,7 @@ async def test_alarm_control_panel(
"id": "0", "id": "0",
"state": {"panel": AncillaryControlPanel.ARMED_NIGHT}, "state": {"panel": AncillaryControlPanel.ARMED_NIGHT},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert ( assert (
@ -147,7 +149,7 @@ async def test_alarm_control_panel(
"id": "0", "id": "0",
"state": {"panel": AncillaryControlPanel.ARMED_STAY}, "state": {"panel": AncillaryControlPanel.ARMED_STAY},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("alarm_control_panel.keypad").state == STATE_ALARM_ARMED_HOME assert hass.states.get("alarm_control_panel.keypad").state == STATE_ALARM_ARMED_HOME
@ -161,7 +163,7 @@ async def test_alarm_control_panel(
"id": "0", "id": "0",
"state": {"panel": AncillaryControlPanel.DISARMED}, "state": {"panel": AncillaryControlPanel.DISARMED},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("alarm_control_panel.keypad").state == STATE_ALARM_DISARMED assert hass.states.get("alarm_control_panel.keypad").state == STATE_ALARM_DISARMED
@ -180,7 +182,7 @@ async def test_alarm_control_panel(
"id": "0", "id": "0",
"state": {"panel": arming_event}, "state": {"panel": arming_event},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("alarm_control_panel.keypad").state == STATE_ALARM_ARMING assert hass.states.get("alarm_control_panel.keypad").state == STATE_ALARM_ARMING
@ -198,7 +200,7 @@ async def test_alarm_control_panel(
"id": "0", "id": "0",
"state": {"panel": pending_event}, "state": {"panel": pending_event},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert ( assert (
@ -214,7 +216,7 @@ async def test_alarm_control_panel(
"id": "0", "id": "0",
"state": {"panel": AncillaryControlPanel.IN_ALARM}, "state": {"panel": AncillaryControlPanel.IN_ALARM},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("alarm_control_panel.keypad").state == STATE_ALARM_TRIGGERED assert hass.states.get("alarm_control_panel.keypad").state == STATE_ALARM_TRIGGERED
@ -228,7 +230,7 @@ async def test_alarm_control_panel(
"id": "0", "id": "0",
"state": {"panel": AncillaryControlPanel.NOT_READY}, "state": {"panel": AncillaryControlPanel.NOT_READY},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("alarm_control_panel.keypad").state == STATE_ALARM_TRIGGERED assert hass.states.get("alarm_control_panel.keypad").state == STATE_ALARM_TRIGGERED

View file

@ -24,6 +24,8 @@ from homeassistant.const import (
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 .conftest import WebsocketDataType
TEST_DATA = [ TEST_DATA = [
( # Alarm binary sensor ( # Alarm binary sensor
{ {
@ -458,7 +460,7 @@ async def test_binary_sensors(
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
expected: dict[str, Any], expected: dict[str, Any],
) -> None: ) -> None:
"""Test successful creation of binary sensor entities.""" """Test successful creation of binary sensor entities."""
@ -497,7 +499,7 @@ async def test_binary_sensors(
"id": "1", "id": "1",
"state": expected["websocket_event"], "state": expected["websocket_event"],
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get(expected["entity_id"]).state == expected["next_state"] assert hass.states.get(expected["entity_id"]).state == expected["next_state"]
@ -598,7 +600,8 @@ async def test_allow_clip_sensor(hass: HomeAssistant, config_entry_setup) -> Non
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
async def test_add_new_binary_sensor( async def test_add_new_binary_sensor(
hass: HomeAssistant, mock_deconz_websocket hass: HomeAssistant,
mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test that adding a new binary sensor works.""" """Test that adding a new binary sensor works."""
assert len(hass.states.async_all()) == 0 assert len(hass.states.async_all()) == 0
@ -617,7 +620,7 @@ async def test_add_new_binary_sensor(
"uniqueid": "00:00:00:00:00:00:00:00-00", "uniqueid": "00:00:00:00:00:00:00:00-00",
}, },
} }
await mock_deconz_websocket(data=event_added_sensor) await mock_websocket_data(event_added_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1 assert len(hass.states.async_all()) == 1
@ -633,7 +636,7 @@ async def test_add_new_binary_sensor_ignored_load_entities_on_service_call(
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
deconz_payload: dict[str, Any], deconz_payload: dict[str, Any],
mock_requests: Callable[[str], None], mock_requests: Callable[[str], None],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test that adding a new binary sensor is not allowed.""" """Test that adding a new binary sensor is not allowed."""
sensor = { sensor = {
@ -653,7 +656,7 @@ async def test_add_new_binary_sensor_ignored_load_entities_on_service_call(
assert len(hass.states.async_all()) == 0 assert len(hass.states.async_all()) == 0
await mock_deconz_websocket(data=event_added_sensor) await mock_websocket_data(event_added_sensor)
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
@ -687,7 +690,7 @@ async def test_add_new_binary_sensor_ignored_load_entities_on_options_change(
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
deconz_payload: dict[str, Any], deconz_payload: dict[str, Any],
mock_requests: Callable[[str], None], mock_requests: Callable[[str], None],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test that adding a new binary sensor is not allowed.""" """Test that adding a new binary sensor is not allowed."""
sensor = { sensor = {
@ -707,7 +710,7 @@ async def test_add_new_binary_sensor_ignored_load_entities_on_options_change(
assert len(hass.states.async_all()) == 0 assert len(hass.states.async_all()) == 0
await mock_deconz_websocket(data=event_added_sensor) await mock_websocket_data(event_added_sensor)
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

View file

@ -45,6 +45,8 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError from homeassistant.exceptions import ServiceValidationError
from .conftest import WebsocketDataType
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
@ -89,7 +91,7 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_simple_climate_device( async def test_simple_climate_device(
hass: HomeAssistant, hass: HomeAssistant,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test successful creation of climate entities. """Test successful creation of climate entities.
@ -117,7 +119,7 @@ async def test_simple_climate_device(
"id": "0", "id": "0",
"state": {"on": False}, "state": {"on": False},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("climate.thermostat").state == STATE_OFF assert hass.states.get("climate.thermostat").state == STATE_OFF
@ -135,7 +137,7 @@ async def test_simple_climate_device(
"id": "0", "id": "0",
"state": {"on": True}, "state": {"on": True},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("climate.thermostat").state == HVACMode.HEAT assert hass.states.get("climate.thermostat").state == HVACMode.HEAT
@ -203,7 +205,7 @@ async def test_climate_device_without_cooling_support(
hass: HomeAssistant, hass: HomeAssistant,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test successful creation of sensor entities.""" """Test successful creation of sensor entities."""
assert len(hass.states.async_all()) == 2 assert len(hass.states.async_all()) == 2
@ -234,7 +236,7 @@ async def test_climate_device_without_cooling_support(
"id": "1", "id": "1",
"config": {"mode": "off"}, "config": {"mode": "off"},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("climate.thermostat").state == STATE_OFF assert hass.states.get("climate.thermostat").state == STATE_OFF
@ -253,7 +255,7 @@ async def test_climate_device_without_cooling_support(
"config": {"mode": "other"}, "config": {"mode": "other"},
"state": {"on": True}, "state": {"on": True},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("climate.thermostat").state == HVACMode.HEAT assert hass.states.get("climate.thermostat").state == HVACMode.HEAT
@ -271,7 +273,7 @@ async def test_climate_device_without_cooling_support(
"id": "1", "id": "1",
"state": {"on": False}, "state": {"on": False},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("climate.thermostat").state == STATE_OFF assert hass.states.get("climate.thermostat").state == STATE_OFF
@ -396,7 +398,7 @@ async def test_climate_device_without_cooling_support(
async def test_climate_device_with_cooling_support( async def test_climate_device_with_cooling_support(
hass: HomeAssistant, hass: HomeAssistant,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test successful creation of sensor entities.""" """Test successful creation of sensor entities."""
assert len(hass.states.async_all()) == 2 assert len(hass.states.async_all()) == 2
@ -424,7 +426,7 @@ async def test_climate_device_with_cooling_support(
"id": "0", "id": "0",
"config": {"mode": "cool"}, "config": {"mode": "cool"},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.async_block_till_done() await hass.async_block_till_done()
@ -443,7 +445,7 @@ async def test_climate_device_with_cooling_support(
"id": "0", "id": "0",
"state": {"on": True}, "state": {"on": True},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("climate.zen_01").state == HVACMode.COOL assert hass.states.get("climate.zen_01").state == HVACMode.COOL
@ -503,7 +505,7 @@ async def test_climate_device_with_cooling_support(
async def test_climate_device_with_fan_support( async def test_climate_device_with_fan_support(
hass: HomeAssistant, hass: HomeAssistant,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test successful creation of sensor entities.""" """Test successful creation of sensor entities."""
assert len(hass.states.async_all()) == 2 assert len(hass.states.async_all()) == 2
@ -532,7 +534,7 @@ async def test_climate_device_with_fan_support(
"id": "0", "id": "0",
"config": {"fanmode": "unsupported"}, "config": {"fanmode": "unsupported"},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("climate.zen_01").attributes["fan_mode"] == FAN_OFF assert hass.states.get("climate.zen_01").attributes["fan_mode"] == FAN_OFF
@ -550,7 +552,7 @@ async def test_climate_device_with_fan_support(
"config": {"fanmode": "unsupported"}, "config": {"fanmode": "unsupported"},
"state": {"on": True}, "state": {"on": True},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("climate.zen_01").attributes["fan_mode"] == FAN_ON assert hass.states.get("climate.zen_01").attributes["fan_mode"] == FAN_ON
@ -568,7 +570,7 @@ async def test_climate_device_with_fan_support(
"id": "0", "id": "0",
"config": {"fanmode": "unsupported"}, "config": {"fanmode": "unsupported"},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("climate.zen_01").attributes["fan_mode"] == FAN_ON assert hass.states.get("climate.zen_01").attributes["fan_mode"] == FAN_ON
@ -649,7 +651,7 @@ async def test_climate_device_with_fan_support(
async def test_climate_device_with_preset( async def test_climate_device_with_preset(
hass: HomeAssistant, hass: HomeAssistant,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test successful creation of sensor entities.""" """Test successful creation of sensor entities."""
assert len(hass.states.async_all()) == 2 assert len(hass.states.async_all()) == 2
@ -681,7 +683,7 @@ async def test_climate_device_with_preset(
"id": "0", "id": "0",
"config": {"preset": "manual"}, "config": {"preset": "manual"},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert ( assert (
@ -698,7 +700,7 @@ async def test_climate_device_with_preset(
"id": "0", "id": "0",
"config": {"preset": "unsupported"}, "config": {"preset": "unsupported"},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("climate.zen_01").attributes["preset_mode"] is None assert hass.states.get("climate.zen_01").attributes["preset_mode"] is None
@ -823,7 +825,10 @@ async def test_clip_climate_device(
], ],
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
async def test_verify_state_update(hass: HomeAssistant, mock_deconz_websocket) -> None: async def test_verify_state_update(
hass: HomeAssistant,
mock_websocket_data: WebsocketDataType,
) -> None:
"""Test that state update properly.""" """Test that state update properly."""
assert hass.states.get("climate.thermostat").state == HVACMode.AUTO assert hass.states.get("climate.thermostat").state == HVACMode.AUTO
assert ( assert (
@ -838,7 +843,7 @@ async def test_verify_state_update(hass: HomeAssistant, mock_deconz_websocket) -
"id": "1", "id": "1",
"state": {"on": False}, "state": {"on": False},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("climate.thermostat").state == HVACMode.AUTO assert hass.states.get("climate.thermostat").state == HVACMode.AUTO
@ -850,7 +855,8 @@ async def test_verify_state_update(hass: HomeAssistant, mock_deconz_websocket) -
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
async def test_add_new_climate_device( async def test_add_new_climate_device(
hass: HomeAssistant, mock_deconz_websocket hass: HomeAssistant,
mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test that adding a new climate device works.""" """Test that adding a new climate device works."""
event_added_sensor = { event_added_sensor = {
@ -876,7 +882,7 @@ async def test_add_new_climate_device(
assert len(hass.states.async_all()) == 0 assert len(hass.states.async_all()) == 0
await mock_deconz_websocket(data=event_added_sensor) await mock_websocket_data(event_added_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(hass.states.async_all()) == 2 assert len(hass.states.async_all()) == 2
@ -988,7 +994,10 @@ async def test_no_mode_no_state(hass: HomeAssistant) -> None:
], ],
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
async def test_boost_mode(hass: HomeAssistant, mock_deconz_websocket) -> None: async def test_boost_mode(
hass: HomeAssistant,
mock_websocket_data: WebsocketDataType,
) -> None:
"""Test that a climate device with boost mode and different state works.""" """Test that a climate device with boost mode and different state works."""
assert len(hass.states.async_all()) == 3 assert len(hass.states.async_all()) == 3
@ -1010,7 +1019,7 @@ async def test_boost_mode(hass: HomeAssistant, mock_deconz_websocket) -> None:
"state": {"valve": 100}, "state": {"valve": 100},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
climate_thermostat = hass.states.get("climate.thermostat") climate_thermostat = hass.states.get("climate.thermostat")

View file

@ -28,6 +28,8 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from .conftest import WebsocketDataType
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
@ -55,7 +57,7 @@ async def test_cover(
hass: HomeAssistant, hass: HomeAssistant,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test that all supported cover entities are created.""" """Test that all supported cover entities are created."""
assert len(hass.states.async_all()) == 2 assert len(hass.states.async_all()) == 2
@ -73,7 +75,7 @@ async def test_cover(
"id": "1", "id": "1",
"state": {"lift": 0, "open": True}, "state": {"lift": 0, "open": True},
} }
await mock_deconz_websocket(data=event_changed_light) await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
cover = hass.states.get("cover.window_covering_device") cover = hass.states.get("cover.window_covering_device")

View file

@ -28,6 +28,8 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr from homeassistant.helpers import device_registry as dr
from .conftest import WebsocketDataType
from tests.common import async_capture_events from tests.common import async_capture_events
@ -77,7 +79,7 @@ async def test_deconz_events(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test successful creation of deconz events.""" """Test successful creation of deconz events."""
assert len(hass.states.async_all()) == 3 assert len(hass.states.async_all()) == 3
@ -103,7 +105,7 @@ async def test_deconz_events(
"id": "1", "id": "1",
"state": {"buttonevent": 2000}, "state": {"buttonevent": 2000},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
device = device_registry.async_get_device( device = device_registry.async_get_device(
@ -125,7 +127,7 @@ async def test_deconz_events(
"id": "3", "id": "3",
"state": {"buttonevent": 2000}, "state": {"buttonevent": 2000},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
device = device_registry.async_get_device( device = device_registry.async_get_device(
@ -148,7 +150,7 @@ async def test_deconz_events(
"id": "4", "id": "4",
"state": {"gesture": 0}, "state": {"gesture": 0},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
device = device_registry.async_get_device( device = device_registry.async_get_device(
@ -171,7 +173,7 @@ async def test_deconz_events(
"id": "5", "id": "5",
"state": {"buttonevent": 6002, "angle": 110, "xy": [0.5982, 0.3897]}, "state": {"buttonevent": 6002, "angle": 110, "xy": [0.5982, 0.3897]},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
device = device_registry.async_get_device( device = device_registry.async_get_device(
@ -197,7 +199,7 @@ async def test_deconz_events(
"id": "1", "id": "1",
"name": "other name", "name": "other name",
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(captured_events) == 4 assert len(captured_events) == 4
@ -284,7 +286,7 @@ async def test_deconz_alarm_events(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test successful creation of deconz alarm events.""" """Test successful creation of deconz alarm events."""
assert len(hass.states.async_all()) == 4 assert len(hass.states.async_all()) == 4
@ -309,7 +311,7 @@ async def test_deconz_alarm_events(
"id": "1", "id": "1",
"state": {"action": AncillaryControlAction.EMERGENCY}, "state": {"action": AncillaryControlAction.EMERGENCY},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
device = device_registry.async_get_device( device = device_registry.async_get_device(
@ -333,7 +335,7 @@ async def test_deconz_alarm_events(
"id": "1", "id": "1",
"state": {"action": AncillaryControlAction.FIRE}, "state": {"action": AncillaryControlAction.FIRE},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
device = device_registry.async_get_device( device = device_registry.async_get_device(
@ -357,7 +359,7 @@ async def test_deconz_alarm_events(
"id": "1", "id": "1",
"state": {"action": AncillaryControlAction.INVALID_CODE}, "state": {"action": AncillaryControlAction.INVALID_CODE},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
device = device_registry.async_get_device( device = device_registry.async_get_device(
@ -381,7 +383,7 @@ async def test_deconz_alarm_events(
"id": "1", "id": "1",
"state": {"action": AncillaryControlAction.PANIC}, "state": {"action": AncillaryControlAction.PANIC},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
device = device_registry.async_get_device( device = device_registry.async_get_device(
@ -405,7 +407,7 @@ async def test_deconz_alarm_events(
"id": "1", "id": "1",
"state": {"action": AncillaryControlAction.ARMED_AWAY}, "state": {"action": AncillaryControlAction.ARMED_AWAY},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(captured_events) == 4 assert len(captured_events) == 4
@ -419,7 +421,7 @@ async def test_deconz_alarm_events(
"id": "1", "id": "1",
"state": {"panel": AncillaryControlPanel.ARMED_AWAY}, "state": {"panel": AncillaryControlPanel.ARMED_AWAY},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(captured_events) == 4 assert len(captured_events) == 4
@ -470,7 +472,7 @@ async def test_deconz_presence_events(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test successful creation of deconz presence events.""" """Test successful creation of deconz presence events."""
assert len(hass.states.async_all()) == 5 assert len(hass.states.async_all()) == 5
@ -506,7 +508,7 @@ async def test_deconz_presence_events(
"id": "1", "id": "1",
"state": {"presenceevent": presence_event}, "state": {"presenceevent": presence_event},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(captured_events) == 1 assert len(captured_events) == 1
@ -527,7 +529,7 @@ async def test_deconz_presence_events(
"id": "1", "id": "1",
"state": {"presenceevent": PresenceStatePresenceEvent.NINE}, "state": {"presenceevent": PresenceStatePresenceEvent.NINE},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(captured_events) == 0 assert len(captured_events) == 0
@ -577,7 +579,7 @@ async def test_deconz_relative_rotary_events(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test successful creation of deconz relative rotary events.""" """Test successful creation of deconz relative rotary events."""
assert len(hass.states.async_all()) == 1 assert len(hass.states.async_all()) == 1
@ -608,7 +610,7 @@ async def test_deconz_relative_rotary_events(
"expectedrotation": rotation, "expectedrotation": rotation,
}, },
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(captured_events) == 1 assert len(captured_events) == 1
@ -631,7 +633,7 @@ async def test_deconz_relative_rotary_events(
"id": "1", "id": "1",
"name": "123", "name": "123",
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(captured_events) == 0 assert len(captured_events) == 0

View file

@ -33,6 +33,8 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.trigger import async_initialize_triggers from homeassistant.helpers.trigger import async_initialize_triggers
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from .conftest import WebsocketDataType
from tests.common import async_get_device_automations from tests.common import async_get_device_automations
@ -318,7 +320,7 @@ async def test_functional_device_trigger(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
service_calls: list[ServiceCall], service_calls: list[ServiceCall],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test proper matching and attachment of device trigger automation.""" """Test proper matching and attachment of device trigger automation."""
device = device_registry.async_get_device( device = device_registry.async_get_device(
@ -356,7 +358,7 @@ async def test_functional_device_trigger(
"id": "1", "id": "1",
"state": {"buttonevent": 1002}, "state": {"buttonevent": 1002},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(service_calls) == 1 assert len(service_calls) == 1

View file

@ -6,6 +6,8 @@ from syrupy import SnapshotAssertion
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from .conftest import WebsocketStateType
from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator from tests.typing import ClientSessionGenerator
@ -14,11 +16,11 @@ async def test_entry_diagnostics(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_deconz_websocket, mock_websocket_state: WebsocketStateType,
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test config entry diagnostics.""" """Test config entry diagnostics."""
await mock_deconz_websocket(state=State.RUNNING) await mock_websocket_state(State.RUNNING)
await hass.async_block_till_done() await hass.async_block_till_done()
assert ( assert (

View file

@ -15,6 +15,8 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON, STATE_UNAVAILABLE from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON, STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from .conftest import WebsocketDataType
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
@ -47,7 +49,7 @@ async def test_fans(
aioclient_mock: AiohttpClientMocker, aioclient_mock: AiohttpClientMocker,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test that all supported fan entities are created.""" """Test that all supported fan entities are created."""
assert len(hass.states.async_all()) == 2 # Light and fan assert len(hass.states.async_all()) == 2 # Light and fan
@ -63,7 +65,7 @@ async def test_fans(
"id": "1", "id": "1",
"state": {"speed": 1}, "state": {"speed": 1},
} }
await mock_deconz_websocket(data=event_changed_light) await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON assert hass.states.get("fan.ceiling_fan").state == STATE_ON
@ -76,7 +78,7 @@ async def test_fans(
"id": "1", "id": "1",
"state": {"speed": 2}, "state": {"speed": 2},
} }
await mock_deconz_websocket(data=event_changed_light) await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON assert hass.states.get("fan.ceiling_fan").state == STATE_ON
@ -89,7 +91,7 @@ async def test_fans(
"id": "1", "id": "1",
"state": {"speed": 3}, "state": {"speed": 3},
} }
await mock_deconz_websocket(data=event_changed_light) await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON assert hass.states.get("fan.ceiling_fan").state == STATE_ON
@ -102,7 +104,7 @@ async def test_fans(
"id": "1", "id": "1",
"state": {"speed": 4}, "state": {"speed": 4},
} }
await mock_deconz_websocket(data=event_changed_light) await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON assert hass.states.get("fan.ceiling_fan").state == STATE_ON
@ -115,7 +117,7 @@ async def test_fans(
"id": "1", "id": "1",
"state": {"speed": 0}, "state": {"speed": 0},
} }
await mock_deconz_websocket(data=event_changed_light) await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_OFF assert hass.states.get("fan.ceiling_fan").state == STATE_OFF
@ -214,7 +216,7 @@ async def test_fans(
"id": "1", "id": "1",
"state": {"speed": 5}, "state": {"speed": 5},
} }
await mock_deconz_websocket(data=event_changed_light) await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("fan.ceiling_fan").state == STATE_ON assert hass.states.get("fan.ceiling_fan").state == STATE_ON

View file

@ -133,17 +133,17 @@ async def test_gateway_device_configuration_url_when_addon(
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
async def test_connection_status_signalling( async def test_connection_status_signalling(
hass: HomeAssistant, mock_deconz_websocket hass: HomeAssistant, mock_websocket_state
) -> None: ) -> None:
"""Make sure that connection status triggers a dispatcher send.""" """Make sure that connection status triggers a dispatcher send."""
assert hass.states.get("binary_sensor.presence").state == STATE_OFF assert hass.states.get("binary_sensor.presence").state == STATE_OFF
await mock_deconz_websocket(state=State.RETRYING) await mock_websocket_state(State.RETRYING)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("binary_sensor.presence").state == STATE_UNAVAILABLE assert hass.states.get("binary_sensor.presence").state == STATE_UNAVAILABLE
await mock_deconz_websocket(state=State.RUNNING) await mock_websocket_state(State.RUNNING)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("binary_sensor.presence").state == STATE_OFF assert hass.states.get("binary_sensor.presence").state == STATE_OFF

View file

@ -40,7 +40,7 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from .conftest import ConfigEntryFactoryType from .conftest import ConfigEntryFactoryType, WebsocketDataType
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
@ -471,7 +471,10 @@ async def test_lights(
], ],
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
async def test_light_state_change(hass: HomeAssistant, mock_deconz_websocket) -> None: async def test_light_state_change(
hass: HomeAssistant,
mock_websocket_data: WebsocketDataType,
) -> None:
"""Verify light can change state on websocket event.""" """Verify light can change state on websocket event."""
assert hass.states.get("light.hue_go").state == STATE_ON assert hass.states.get("light.hue_go").state == STATE_ON
@ -482,7 +485,7 @@ async def test_light_state_change(hass: HomeAssistant, mock_deconz_websocket) ->
"id": "0", "id": "0",
"state": {"on": False}, "state": {"on": False},
} }
await mock_deconz_websocket(data=event_changed_light) await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("light.hue_go").state == STATE_OFF assert hass.states.get("light.hue_go").state == STATE_OFF
@ -1295,7 +1298,8 @@ async def test_disable_light_groups(
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
async def test_non_color_light_reports_color( async def test_non_color_light_reports_color(
hass: HomeAssistant, mock_deconz_websocket hass: HomeAssistant,
mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Verify hs_color does not crash when a group gets updated with a bad color value. """Verify hs_color does not crash when a group gets updated with a bad color value.
@ -1331,7 +1335,7 @@ async def test_non_color_light_reports_color(
"t": "event", "t": "event",
"uniqueid": "ec:1b:bd:ff:fe:ee:ed:dd-01", "uniqueid": "ec:1b:bd:ff:fe:ee:ed:dd-01",
} }
await mock_deconz_websocket(data=event_changed_light) await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
group = hass.states.get("light.group") group = hass.states.get("light.group")
@ -1510,15 +1514,16 @@ async def test_verify_group_supported_features(hass: HomeAssistant) -> None:
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
async def test_verify_group_color_mode_fallback( async def test_verify_group_color_mode_fallback(
hass: HomeAssistant, mock_deconz_websocket hass: HomeAssistant,
mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test that group supported features reflect what included lights support.""" """Test that group supported features reflect what included lights support."""
group_state = hass.states.get("light.opbergruimte") group_state = hass.states.get("light.opbergruimte")
assert group_state.state == STATE_OFF assert group_state.state == STATE_OFF
assert group_state.attributes[ATTR_COLOR_MODE] is None assert group_state.attributes[ATTR_COLOR_MODE] is None
await mock_deconz_websocket( await mock_websocket_data(
data={ {
"e": "changed", "e": "changed",
"id": "13", "id": "13",
"r": "lights", "r": "lights",
@ -1533,8 +1538,8 @@ async def test_verify_group_color_mode_fallback(
"uniqueid": "00:17:88:01:08:11:22:33-01", "uniqueid": "00:17:88:01:08:11:22:33-01",
} }
) )
await mock_deconz_websocket( await mock_websocket_data(
data={ {
"e": "changed", "e": "changed",
"id": "43", "id": "43",
"r": "groups", "r": "groups",

View file

@ -18,6 +18,8 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from .conftest import WebsocketDataType
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
@ -45,7 +47,7 @@ async def test_lock_from_light(
hass: HomeAssistant, hass: HomeAssistant,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test that all supported lock entities based on lights are created.""" """Test that all supported lock entities based on lights are created."""
assert len(hass.states.async_all()) == 1 assert len(hass.states.async_all()) == 1
@ -58,7 +60,7 @@ async def test_lock_from_light(
"id": "1", "id": "1",
"state": {"on": True}, "state": {"on": True},
} }
await mock_deconz_websocket(data=event_changed_light) await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("lock.door_lock").state == STATE_LOCKED assert hass.states.get("lock.door_lock").state == STATE_LOCKED
@ -131,7 +133,7 @@ async def test_lock_from_sensor(
hass: HomeAssistant, hass: HomeAssistant,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test that all supported lock entities based on sensors are created.""" """Test that all supported lock entities based on sensors are created."""
assert len(hass.states.async_all()) == 2 assert len(hass.states.async_all()) == 2
@ -144,7 +146,7 @@ async def test_lock_from_sensor(
"id": "1", "id": "1",
"state": {"lockstate": "locked"}, "state": {"lockstate": "locked"},
} }
await mock_deconz_websocket(data=event_changed_light) await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("lock.door_lock").state == STATE_LOCKED assert hass.states.get("lock.door_lock").state == STATE_LOCKED

View file

@ -16,6 +16,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError from homeassistant.exceptions import ServiceValidationError
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 .conftest import WebsocketDataType
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
TEST_DATA = [ TEST_DATA = [
@ -104,7 +106,7 @@ async def test_number_entities(
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
expected: dict[str, Any], expected: dict[str, Any],
) -> None: ) -> None:
@ -142,7 +144,7 @@ async def test_number_entities(
"r": "sensors", "r": "sensors",
"id": "0", "id": "0",
} | expected["websocket_event"] } | expected["websocket_event"]
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get(expected["entity_id"]).state == expected["next_state"] assert hass.states.get(expected["entity_id"]).state == expected["next_state"]

View file

@ -11,6 +11,8 @@ from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE
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 .conftest import WebsocketDataType
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
TEST_DATA = [ TEST_DATA = [
@ -117,7 +119,8 @@ async def test_scenes(
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
async def test_only_new_scenes_are_created( async def test_only_new_scenes_are_created(
hass: HomeAssistant, mock_deconz_websocket hass: HomeAssistant,
mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test that scenes works.""" """Test that scenes works."""
assert len(hass.states.async_all()) == 2 assert len(hass.states.async_all()) == 2
@ -129,7 +132,7 @@ async def test_only_new_scenes_are_created(
"id": "1", "id": "1",
"scenes": [{"id": "1", "name": "Scene"}], "scenes": [{"id": "1", "name": "Scene"}],
} }
await mock_deconz_websocket(data=event_changed_group) await mock_websocket_data(event_changed_group)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(hass.states.async_all()) == 2 assert len(hass.states.async_all()) == 2

View file

@ -24,7 +24,7 @@ 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 homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
from .conftest import ConfigEntryFactoryType from .conftest import ConfigEntryFactoryType, WebsocketDataType
from tests.common import async_fire_time_changed from tests.common import async_fire_time_changed
@ -906,7 +906,7 @@ async def test_sensors(
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
expected: dict[str, Any], expected: dict[str, Any],
) -> None: ) -> None:
"""Test successful creation of sensor entities.""" """Test successful creation of sensor entities."""
@ -954,7 +954,7 @@ async def test_sensors(
event_changed_sensor = {"t": "event", "e": "changed", "r": "sensors", "id": "1"} event_changed_sensor = {"t": "event", "e": "changed", "r": "sensors", "id": "1"}
event_changed_sensor |= expected["websocket_event"] event_changed_sensor |= expected["websocket_event"]
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get(expected["entity_id"]).state == expected["next_state"] assert hass.states.get(expected["entity_id"]).state == expected["next_state"]
@ -1057,7 +1057,10 @@ async def test_allow_clip_sensors(
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
async def test_add_new_sensor(hass: HomeAssistant, mock_deconz_websocket) -> None: async def test_add_new_sensor(
hass: HomeAssistant,
mock_websocket_data: WebsocketDataType,
) -> None:
"""Test that adding a new sensor works.""" """Test that adding a new sensor works."""
event_added_sensor = { event_added_sensor = {
"t": "event", "t": "event",
@ -1076,7 +1079,7 @@ async def test_add_new_sensor(hass: HomeAssistant, mock_deconz_websocket) -> Non
assert len(hass.states.async_all()) == 0 assert len(hass.states.async_all()) == 0
await mock_deconz_websocket(data=event_added_sensor) await mock_websocket_data(event_added_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(hass.states.async_all()) == 2 assert len(hass.states.async_all()) == 2
@ -1168,7 +1171,10 @@ async def test_air_quality_sensor_without_ppb(hass: HomeAssistant) -> None:
], ],
) )
@pytest.mark.usefixtures("config_entry_setup") @pytest.mark.usefixtures("config_entry_setup")
async def test_add_battery_later(hass: HomeAssistant, mock_deconz_websocket) -> None: async def test_add_battery_later(
hass: HomeAssistant,
mock_websocket_data: WebsocketDataType,
) -> None:
"""Test that a battery sensor can be created later on. """Test that a battery sensor can be created later on.
Without an initial battery state a battery sensor Without an initial battery state a battery sensor
@ -1183,7 +1189,7 @@ async def test_add_battery_later(hass: HomeAssistant, mock_deconz_websocket) ->
"id": "2", "id": "2",
"config": {"battery": 50}, "config": {"battery": 50},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
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
@ -1195,7 +1201,7 @@ async def test_add_battery_later(hass: HomeAssistant, mock_deconz_websocket) ->
"id": "1", "id": "1",
"config": {"battery": 50}, "config": {"battery": 50},
} }
await mock_deconz_websocket(data=event_changed_sensor) await mock_websocket_data(event_changed_sensor)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1 assert len(hass.states.async_all()) == 1

View file

@ -16,6 +16,8 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from .conftest import WebsocketDataType
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
@ -41,7 +43,7 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_sirens( async def test_sirens(
hass: HomeAssistant, hass: HomeAssistant,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
) -> None: ) -> None:
"""Test that siren entities are created.""" """Test that siren entities are created."""
@ -56,7 +58,7 @@ async def test_sirens(
"id": "1", "id": "1",
"state": {"alert": None}, "state": {"alert": None},
} }
await mock_deconz_websocket(data=event_changed_light) await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("siren.warning_device").state == STATE_OFF assert hass.states.get("siren.warning_device").state == STATE_OFF

View file

@ -16,7 +16,7 @@ from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON, STATE_UNAVA
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from .conftest import ConfigEntryFactoryType from .conftest import ConfigEntryFactoryType, WebsocketDataType
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
@ -56,7 +56,7 @@ async def test_power_plugs(
hass: HomeAssistant, hass: HomeAssistant,
config_entry_setup: ConfigEntry, config_entry_setup: ConfigEntry,
mock_put_request: Callable[[str, str], AiohttpClientMocker], mock_put_request: Callable[[str, str], AiohttpClientMocker],
mock_deconz_websocket, mock_websocket_data: WebsocketDataType,
) -> None: ) -> None:
"""Test that all supported switch entities are created.""" """Test that all supported switch entities are created."""
assert len(hass.states.async_all()) == 4 assert len(hass.states.async_all()) == 4
@ -72,7 +72,7 @@ async def test_power_plugs(
"id": "1", "id": "1",
"state": {"on": False}, "state": {"on": False},
} }
await mock_deconz_websocket(data=event_changed_light) await mock_websocket_data(event_changed_light)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("switch.on_off_switch").state == STATE_OFF assert hass.states.get("switch.on_off_switch").state == STATE_OFF