Mark Reolink camera entities as unavailable when camera is offline (#127127)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
starkillerOG 2024-09-30 19:00:37 +02:00 committed by Franck Nijhof
parent f0c3900842
commit d3e6069095
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
3 changed files with 16 additions and 0 deletions

View file

@ -155,6 +155,11 @@ class ReolinkChannelCoordinatorEntity(ReolinkHostCoordinatorEntity):
configuration_url=self._conf_url,
)
@property
def available(self) -> bool:
"""Return True if entity is available."""
return super().available and self._host.api.camera_online(self._channel)
async def async_added_to_hass(self) -> None:
"""Entity created."""
await super().async_added_to_hass()

View file

@ -92,6 +92,7 @@ def reolink_connect_class() -> Generator[MagicMock]:
host_mock.camera_sw_version.return_value = "v1.1.0.0.0.0000"
host_mock.camera_sw_version_update_required.return_value = False
host_mock.camera_uid.return_value = TEST_UID_CAM
host_mock.camera_online.return_value = True
host_mock.channel_for_uid.return_value = 0
host_mock.get_encoding.return_value = "h264"
host_mock.firmware_update_available.return_value = False

View file

@ -17,6 +17,7 @@ from homeassistant.const import (
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
Platform,
)
from homeassistant.core import HomeAssistant
@ -302,6 +303,15 @@ async def test_switch(
reolink_connect.set_recording.reset_mock(side_effect=True)
reolink_connect.camera_online.return_value = False
freezer.tick(DEVICE_UPDATE_INTERVAL)
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE
reolink_connect.camera_online.return_value = True
async def test_host_switch(
hass: HomeAssistant,