Assume Fritz!Smarthome device as unavailable (#56542)
parent
972db29c88
commit
7ece35cd6f
|
@ -68,6 +68,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
data = {}
|
||||
for device in devices:
|
||||
device.update()
|
||||
|
||||
# assume device as unavailable, see #55799
|
||||
if (
|
||||
device.has_powermeter
|
||||
and device.present
|
||||
and hasattr(device, "voltage")
|
||||
and device.voltage <= 0
|
||||
and device.power <= 0
|
||||
and device.energy <= 0
|
||||
):
|
||||
device.present = False
|
||||
|
||||
data[device.ain] = device
|
||||
return data
|
||||
|
||||
|
|
|
@ -108,6 +108,7 @@ class FritzDeviceSwitchMock(FritzDeviceBaseMock):
|
|||
battery_level = None
|
||||
device_lock = "fake_locked_device"
|
||||
energy = 1234
|
||||
voltage = 230
|
||||
fw_version = "1.2.3"
|
||||
has_alarm = False
|
||||
has_powermeter = True
|
||||
|
|
|
@ -26,6 +26,7 @@ from homeassistant.const import (
|
|||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -137,3 +138,18 @@ async def test_update_error(hass: HomeAssistant, fritz: Mock):
|
|||
|
||||
assert device.update.call_count == 2
|
||||
assert fritz().login.call_count == 2
|
||||
|
||||
|
||||
async def test_assume_device_unavailable(hass: HomeAssistant, fritz: Mock):
|
||||
"""Test assume device as unavailable."""
|
||||
device = FritzDeviceSwitchMock()
|
||||
device.voltage = 0
|
||||
device.energy = 0
|
||||
device.power = 0
|
||||
assert await setup_config_entry(
|
||||
hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz
|
||||
)
|
||||
|
||||
state = hass.states.get(ENTITY_ID)
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
|
Loading…
Reference in New Issue