Reolink check if camera and motion supported (#146666)

This commit is contained in:
starkillerOG 2025-06-12 23:19:46 +02:00 committed by GitHub
parent c78b66d5d5
commit 89ae68c5af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 5 deletions

View File

@ -63,6 +63,7 @@ BINARY_PUSH_SENSORS = (
cmd_id=33,
device_class=BinarySensorDeviceClass.MOTION,
value=lambda api, ch: api.motion_detected(ch),
supported=lambda api, ch: api.supported(ch, "motion_detection"),
),
ReolinkBinarySensorEntityDescription(
key=FACE_DETECTION_TYPE,

View File

@ -37,23 +37,27 @@ CAMERA_ENTITIES = (
key="sub",
stream="sub",
translation_key="sub",
supported=lambda api, ch: api.supported(ch, "stream"),
),
ReolinkCameraEntityDescription(
key="main",
stream="main",
translation_key="main",
supported=lambda api, ch: api.supported(ch, "stream"),
entity_registry_enabled_default=False,
),
ReolinkCameraEntityDescription(
key="snapshots_sub",
stream="snapshots_sub",
translation_key="snapshots_sub",
supported=lambda api, ch: api.supported(ch, "snapshot"),
entity_registry_enabled_default=False,
),
ReolinkCameraEntityDescription(
key="snapshots",
stream="snapshots_main",
translation_key="snapshots_main",
supported=lambda api, ch: api.supported(ch, "snapshot"),
entity_registry_enabled_default=False,
),
ReolinkCameraEntityDescription(

View File

@ -333,7 +333,14 @@ async def test_browsing_rec_playback_unsupported(
config_entry: MockConfigEntry,
) -> None:
"""Test browsing a Reolink camera which does not support playback of recordings."""
reolink_connect.supported.return_value = 0
def test_supported(ch, key):
"""Test supported function."""
if key == "replay":
return False
return True
reolink_connect.supported = test_supported
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.CAMERA]):
assert await hass.config_entries.async_setup(config_entry.entry_id)
@ -347,6 +354,8 @@ async def test_browsing_rec_playback_unsupported(
assert browse.identifier is None
assert browse.children == []
reolink_connect.supported = lambda ch, key: True # Reset supported function
async def test_browsing_errors(
hass: HomeAssistant,
@ -354,8 +363,6 @@ async def test_browsing_errors(
config_entry: MockConfigEntry,
) -> None:
"""Test browsing a Reolink camera errors."""
reolink_connect.supported.return_value = 1
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.CAMERA]):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
@ -373,8 +380,6 @@ async def test_browsing_not_loaded(
config_entry: MockConfigEntry,
) -> None:
"""Test browsing a Reolink camera integration which is not loaded."""
reolink_connect.supported.return_value = 1
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.CAMERA]):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()