Implement entity available for battery cameras (#171838)

This commit is contained in:
starkillerOG
2026-05-26 21:14:31 +02:00
committed by GitHub
parent b3199bac88
commit 995707160f
3 changed files with 50 additions and 0 deletions
@@ -96,6 +96,13 @@ class ReolinkHostCoordinatorEntity(CoordinatorEntity[ReolinkCoordinator]):
if self.entity_description.always_available:
return True
if self._host.api.is_battery:
return (
self._host.api.baichuan.login_sucess
and not self._host.api.baichuan.privacy_mode()
and super().available
)
return (
self._host.api.session_active
and not self._host.api.baichuan.privacy_mode()
+2
View File
@@ -93,6 +93,7 @@ def _init_host_mock(host_mock: MagicMock) -> None:
host_mock.update_firmware = AsyncMock()
host_mock.is_nvr = True
host_mock.is_hub = False
host_mock.is_battery = False
host_mock.mac_address = TEST_MAC
host_mock.uid = TEST_UID
host_mock.onvif_enabled = True
@@ -162,6 +163,7 @@ def _init_host_mock(host_mock: MagicMock) -> None:
# Disable tcp push by default for tests
host_mock.baichuan.port = TEST_BC_PORT
host_mock.baichuan.events_active = False
host_mock.baichuan.login_sucess = True
host_mock.baichuan.subscribe_events = AsyncMock()
host_mock.baichuan.unsubscribe_events = AsyncMock()
host_mock.baichuan.check_subscribe_events = AsyncMock()
+41
View File
@@ -0,0 +1,41 @@
"""Test the Reolink entity file."""
from unittest.mock import MagicMock, patch
from freezegun.api import FrozenDateTimeFactory
from homeassistant.components.reolink.coordinator import DEVICE_UPDATE_INTERVAL_MIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import STATE_UNAVAILABLE, Platform
from homeassistant.core import HomeAssistant
from .conftest import TEST_CAM_NAME
from tests.common import MockConfigEntry, async_fire_time_changed
async def test_battery_available(
hass: HomeAssistant,
freezer: FrozenDateTimeFactory,
config_entry: MockConfigEntry,
reolink_host: MagicMock,
) -> None:
"""Test available property of a entity from a Reolink battery camera."""
reolink_host.volume.return_value = 80
reolink_host.is_battery = True
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.NUMBER]):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.LOADED
entity_id = f"{Platform.NUMBER}.{TEST_CAM_NAME}_volume"
assert hass.states.get(entity_id).state == "80"
reolink_host.baichuan.login_sucess = False
freezer.tick(2 * DEVICE_UPDATE_INTERVAL_MIN)
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE