2020-01-29 02:21:33 +00:00
|
|
|
"""Test ZHA Gateway."""
|
2020-02-10 02:45:35 +00:00
|
|
|
import pytest
|
2020-01-29 02:21:33 +00:00
|
|
|
import zigpy.zcl.clusters.general as general
|
|
|
|
|
2020-02-10 02:45:35 +00:00
|
|
|
from .common import async_enable_traffic
|
2020-01-29 02:21:33 +00:00
|
|
|
|
|
|
|
|
2020-02-10 02:45:35 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def zigpy_dev_basic(zigpy_device_mock):
|
|
|
|
"""Zigpy device with just a basic cluster."""
|
|
|
|
return zigpy_device_mock(
|
|
|
|
{
|
|
|
|
1: {
|
|
|
|
"in_clusters": [general.Basic.cluster_id],
|
|
|
|
"out_clusters": [],
|
|
|
|
"device_type": 0,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2020-01-29 02:21:33 +00:00
|
|
|
|
|
|
|
|
2020-02-10 02:45:35 +00:00
|
|
|
@pytest.fixture
|
|
|
|
async def zha_dev_basic(hass, zha_device_restored, zigpy_dev_basic):
|
|
|
|
"""ZHA device with just a basic cluster."""
|
|
|
|
|
|
|
|
zha_device = await zha_device_restored(zigpy_dev_basic)
|
|
|
|
return zha_device
|
2020-01-29 02:21:33 +00:00
|
|
|
|
|
|
|
|
2020-02-10 02:45:35 +00:00
|
|
|
async def test_device_left(hass, zha_gateway, zigpy_dev_basic, zha_dev_basic):
|
|
|
|
"""Device leaving the network should become unavailable."""
|
2020-01-29 02:21:33 +00:00
|
|
|
|
2020-02-10 02:45:35 +00:00
|
|
|
assert zha_dev_basic.available is False
|
2020-01-29 02:21:33 +00:00
|
|
|
|
2020-02-10 02:45:35 +00:00
|
|
|
await async_enable_traffic(hass, zha_gateway, [zha_dev_basic])
|
|
|
|
assert zha_dev_basic.available is True
|
2020-01-29 02:21:33 +00:00
|
|
|
|
2020-02-10 02:45:35 +00:00
|
|
|
zha_gateway.device_left(zigpy_dev_basic)
|
|
|
|
assert zha_dev_basic.available is False
|