mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Mark Reolink camera entities as unavailable when camera is offline (#127127)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
0a99c1c633
commit
0f4c50e83c
@ -155,6 +155,11 @@ class ReolinkChannelCoordinatorEntity(ReolinkHostCoordinatorEntity):
|
|||||||
configuration_url=self._conf_url,
|
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:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Entity created."""
|
"""Entity created."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
|
@ -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.return_value = "v1.1.0.0.0.0000"
|
||||||
host_mock.camera_sw_version_update_required.return_value = False
|
host_mock.camera_sw_version_update_required.return_value = False
|
||||||
host_mock.camera_uid.return_value = TEST_UID_CAM
|
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.channel_for_uid.return_value = 0
|
||||||
host_mock.get_encoding.return_value = "h264"
|
host_mock.get_encoding.return_value = "h264"
|
||||||
host_mock.firmware_update_available.return_value = False
|
host_mock.firmware_update_available.return_value = False
|
||||||
|
@ -17,6 +17,7 @@ from homeassistant.const import (
|
|||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
|
STATE_UNAVAILABLE,
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -302,6 +303,15 @@ async def test_switch(
|
|||||||
|
|
||||||
reolink_connect.set_recording.reset_mock(side_effect=True)
|
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(
|
async def test_host_switch(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user