Skip to content

Commit

Permalink
Mark Reolink camera entities as unavailable when camera is offline (h…
Browse files Browse the repository at this point in the history
…ome-assistant#127127)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
  • Loading branch information
starkillerOG and frenck committed Sep 30, 2024
1 parent f0c3900 commit d3e6069
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions homeassistant/components/reolink/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ def __init__(
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()
Expand Down
1 change: 1 addition & 0 deletions tests/components/reolink/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/components/reolink/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
Platform,
)
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d3e6069

Please sign in to comment.