2018-11-06 09:34:24 +00:00
|
|
|
"""Test deCONZ gateway."""
|
2024-03-08 13:50:25 +00:00
|
|
|
|
2022-02-23 12:10:35 +00:00
|
|
|
from unittest.mock import patch
|
2019-09-19 21:44:09 +00:00
|
|
|
|
2022-08-05 23:34:27 +00:00
|
|
|
from pydeconz.websocket import State
|
2019-02-14 04:36:06 +00:00
|
|
|
import pytest
|
2024-07-23 19:29:48 +00:00
|
|
|
from syrupy import SnapshotAssertion
|
2019-02-14 04:36:06 +00:00
|
|
|
|
2021-12-01 18:38:20 +00:00
|
|
|
from homeassistant.components import ssdp
|
2020-10-17 16:20:06 +00:00
|
|
|
from homeassistant.components.deconz.config_flow import DECONZ_MANUFACTURERURL
|
|
|
|
from homeassistant.components.deconz.const import DOMAIN as DECONZ_DOMAIN
|
|
|
|
from homeassistant.components.ssdp import (
|
|
|
|
ATTR_UPNP_MANUFACTURER_URL,
|
|
|
|
ATTR_UPNP_SERIAL,
|
|
|
|
ATTR_UPNP_UDN,
|
|
|
|
)
|
2024-07-26 07:36:41 +00:00
|
|
|
from homeassistant.config_entries import SOURCE_SSDP
|
2024-07-05 18:47:43 +00:00
|
|
|
from homeassistant.const import STATE_OFF, STATE_UNAVAILABLE
|
2023-02-08 12:01:44 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2021-10-22 17:41:49 +00:00
|
|
|
from homeassistant.helpers import device_registry as dr
|
2021-02-09 07:31:29 +00:00
|
|
|
|
2024-07-23 19:29:48 +00:00
|
|
|
from .conftest import BRIDGE_ID
|
2018-11-06 09:34:24 +00:00
|
|
|
|
2024-07-26 07:36:41 +00:00
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
2018-11-06 09:34:24 +00:00
|
|
|
|
2024-07-23 19:29:48 +00:00
|
|
|
async def test_device_registry_entry(
|
2024-07-26 07:36:41 +00:00
|
|
|
config_entry_setup: MockConfigEntry,
|
2023-11-09 17:06:53 +00:00
|
|
|
device_registry: dr.DeviceRegistry,
|
2024-07-23 19:29:48 +00:00
|
|
|
snapshot: SnapshotAssertion,
|
2023-02-08 12:01:44 +00:00
|
|
|
) -> None:
|
2019-09-19 21:44:09 +00:00
|
|
|
"""Successful setup."""
|
2024-07-23 19:29:48 +00:00
|
|
|
device_entry = device_registry.async_get_device(
|
|
|
|
identifiers={(DECONZ_DOMAIN, config_entry_setup.unique_id)}
|
2021-11-14 10:49:02 +00:00
|
|
|
)
|
2024-07-23 19:29:48 +00:00
|
|
|
assert device_entry == snapshot
|
2021-10-22 17:41:49 +00:00
|
|
|
|
2019-09-19 21:44:09 +00:00
|
|
|
|
2024-07-05 14:59:10 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"sensor_payload",
|
|
|
|
[
|
|
|
|
{
|
2024-07-21 11:56:16 +00:00
|
|
|
"name": "presence",
|
|
|
|
"type": "ZHAPresence",
|
|
|
|
"state": {"presence": False},
|
|
|
|
"config": {"on": True, "reachable": True},
|
|
|
|
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
2021-03-12 20:03:29 +00:00
|
|
|
}
|
2024-07-05 14:59:10 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
@pytest.mark.usefixtures("config_entry_setup")
|
|
|
|
async def test_connection_status_signalling(
|
2024-07-05 20:35:06 +00:00
|
|
|
hass: HomeAssistant, mock_websocket_state
|
2024-07-05 14:59:10 +00:00
|
|
|
) -> None:
|
|
|
|
"""Make sure that connection status triggers a dispatcher send."""
|
2021-03-12 20:03:29 +00:00
|
|
|
assert hass.states.get("binary_sensor.presence").state == STATE_OFF
|
|
|
|
|
2024-07-05 20:35:06 +00:00
|
|
|
await mock_websocket_state(State.RETRYING)
|
2021-03-12 20:03:29 +00:00
|
|
|
await hass.async_block_till_done()
|
2018-11-06 09:34:24 +00:00
|
|
|
|
2021-03-12 20:03:29 +00:00
|
|
|
assert hass.states.get("binary_sensor.presence").state == STATE_UNAVAILABLE
|
2018-11-06 09:34:24 +00:00
|
|
|
|
2024-07-05 20:35:06 +00:00
|
|
|
await mock_websocket_state(State.RUNNING)
|
2019-09-19 21:44:09 +00:00
|
|
|
await hass.async_block_till_done()
|
2018-11-06 09:34:24 +00:00
|
|
|
|
2021-03-12 20:03:29 +00:00
|
|
|
assert hass.states.get("binary_sensor.presence").state == STATE_OFF
|
2018-11-06 09:34:24 +00:00
|
|
|
|
|
|
|
|
2023-02-08 12:01:44 +00:00
|
|
|
async def test_update_address(
|
2024-07-26 07:36:41 +00:00
|
|
|
hass: HomeAssistant, config_entry_setup: MockConfigEntry
|
2023-02-08 12:01:44 +00:00
|
|
|
) -> None:
|
2019-09-19 21:44:09 +00:00
|
|
|
"""Make sure that connection status triggers a dispatcher send."""
|
2024-07-29 09:43:04 +00:00
|
|
|
assert config_entry_setup.data["host"] == "1.2.3.4"
|
|
|
|
|
|
|
|
with (
|
|
|
|
patch(
|
|
|
|
"homeassistant.components.deconz.async_setup_entry",
|
|
|
|
return_value=True,
|
|
|
|
) as mock_setup_entry,
|
|
|
|
patch("pydeconz.gateway.WSClient") as ws_mock,
|
|
|
|
):
|
2020-08-08 18:23:56 +00:00
|
|
|
await hass.config_entries.flow.async_init(
|
2020-10-17 16:20:06 +00:00
|
|
|
DECONZ_DOMAIN,
|
2021-12-01 18:38:20 +00:00
|
|
|
data=ssdp.SsdpServiceInfo(
|
|
|
|
ssdp_st="mock_st",
|
|
|
|
ssdp_usn="mock_usn",
|
|
|
|
ssdp_location="http://2.3.4.5:80/",
|
|
|
|
upnp={
|
|
|
|
ATTR_UPNP_MANUFACTURER_URL: DECONZ_MANUFACTURERURL,
|
2024-07-23 19:29:48 +00:00
|
|
|
ATTR_UPNP_SERIAL: BRIDGE_ID,
|
2021-12-01 18:38:20 +00:00
|
|
|
ATTR_UPNP_UDN: "uuid:456DEF",
|
|
|
|
},
|
|
|
|
),
|
2020-10-17 16:20:06 +00:00
|
|
|
context={"source": SOURCE_SSDP},
|
2020-08-08 18:23:56 +00:00
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
2018-11-06 09:34:24 +00:00
|
|
|
|
2024-07-29 09:43:04 +00:00
|
|
|
assert ws_mock.call_args[0][1] == "2.3.4.5"
|
|
|
|
assert config_entry_setup.data["host"] == "2.3.4.5"
|
2020-08-08 18:23:56 +00:00
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|