Assume Fritz!Smarthome device as unavailable (#56542)

pull/56592/head
Michael 2021-09-23 22:29:12 +02:00 committed by GitHub
parent 972db29c88
commit 7ece35cd6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -68,6 +68,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
data = {} data = {}
for device in devices: for device in devices:
device.update() 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 data[device.ain] = device
return data return data

View File

@ -108,6 +108,7 @@ class FritzDeviceSwitchMock(FritzDeviceBaseMock):
battery_level = None battery_level = None
device_lock = "fake_locked_device" device_lock = "fake_locked_device"
energy = 1234 energy = 1234
voltage = 230
fw_version = "1.2.3" fw_version = "1.2.3"
has_alarm = False has_alarm = False
has_powermeter = True has_powermeter = True

View File

@ -26,6 +26,7 @@ from homeassistant.const import (
SERVICE_TURN_OFF, SERVICE_TURN_OFF,
SERVICE_TURN_ON, SERVICE_TURN_ON,
STATE_ON, STATE_ON,
STATE_UNAVAILABLE,
TEMP_CELSIUS, TEMP_CELSIUS,
) )
from homeassistant.core import HomeAssistant 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 device.update.call_count == 2
assert fritz().login.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