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

Add gui config option consider device unavailable (#51218)

* Add gui config option consider device unavailable

* Update tests
This commit is contained in:
astronaut
2021-05-30 01:13:09 +02:00
committed by GitHub
parent d1f0ec8db8
commit ceadb0cba0
7 changed files with 57 additions and 34 deletions

View File

@@ -8,7 +8,10 @@ import pytest
import zigpy.profiles.zha
import zigpy.zcl.clusters.general as general
import homeassistant.components.zha.core.device as zha_core_device
from homeassistant.components.zha.core.const import (
CONF_DEFAULT_CONSIDER_UNAVAILABLE_BATTERY,
CONF_DEFAULT_CONSIDER_UNAVAILABLE_MAINS,
)
from homeassistant.const import STATE_OFF, STATE_UNAVAILABLE
import homeassistant.helpers.device_registry as dr
import homeassistant.util.dt as dt_util
@@ -117,13 +120,13 @@ async def test_check_available_success(
basic_ch.read_attributes.reset_mock()
device_with_basic_channel.last_seen = None
assert zha_device.available is True
_send_time_changed(hass, zha_core_device.CONSIDER_UNAVAILABLE_MAINS + 2)
_send_time_changed(hass, zha_device.consider_unavailable_time + 2)
await hass.async_block_till_done()
assert zha_device.available is False
assert basic_ch.read_attributes.await_count == 0
device_with_basic_channel.last_seen = (
time.time() - zha_core_device.CONSIDER_UNAVAILABLE_MAINS - 2
time.time() - zha_device.consider_unavailable_time - 2
)
_seens = [time.time(), device_with_basic_channel.last_seen]
@@ -172,7 +175,7 @@ async def test_check_available_unsuccessful(
assert basic_ch.read_attributes.await_count == 0
device_with_basic_channel.last_seen = (
time.time() - zha_core_device.CONSIDER_UNAVAILABLE_MAINS - 2
time.time() - zha_device.consider_unavailable_time - 2
)
# unsuccessfuly ping zigpy device, but zha_device is still available
@@ -213,7 +216,7 @@ async def test_check_available_no_basic_channel(
assert zha_device.available is True
device_without_basic_channel.last_seen = (
time.time() - zha_core_device.CONSIDER_UNAVAILABLE_BATTERY - 2
time.time() - zha_device.consider_unavailable_time - 2
)
assert "does not have a mandatory basic cluster" not in caplog.text
@@ -246,38 +249,38 @@ async def test_ota_sw_version(hass, ota_zha_device):
("zigpy_device", 0, True),
(
"zigpy_device",
zha_core_device.CONSIDER_UNAVAILABLE_MAINS + 2,
CONF_DEFAULT_CONSIDER_UNAVAILABLE_MAINS + 2,
True,
),
(
"zigpy_device",
zha_core_device.CONSIDER_UNAVAILABLE_BATTERY - 2,
CONF_DEFAULT_CONSIDER_UNAVAILABLE_BATTERY - 2,
True,
),
(
"zigpy_device",
zha_core_device.CONSIDER_UNAVAILABLE_BATTERY + 2,
CONF_DEFAULT_CONSIDER_UNAVAILABLE_BATTERY + 2,
False,
),
("zigpy_device_mains", 0, True),
(
"zigpy_device_mains",
zha_core_device.CONSIDER_UNAVAILABLE_MAINS - 2,
CONF_DEFAULT_CONSIDER_UNAVAILABLE_MAINS - 2,
True,
),
(
"zigpy_device_mains",
zha_core_device.CONSIDER_UNAVAILABLE_MAINS + 2,
CONF_DEFAULT_CONSIDER_UNAVAILABLE_MAINS + 2,
False,
),
(
"zigpy_device_mains",
zha_core_device.CONSIDER_UNAVAILABLE_BATTERY - 2,
CONF_DEFAULT_CONSIDER_UNAVAILABLE_BATTERY - 2,
False,
),
(
"zigpy_device_mains",
zha_core_device.CONSIDER_UNAVAILABLE_BATTERY + 2,
CONF_DEFAULT_CONSIDER_UNAVAILABLE_BATTERY + 2,
False,
),
),