mirror of
https://github.com/home-assistant/core.git
synced 2026-11-06 05:32:45 -04:00
Add Reolink sub channel support (#181570)
This commit is contained in:
@@ -112,6 +112,7 @@ def _init_host_mock(host_mock: MagicMock) -> None:
|
||||
host_mock.protocol = "rtsp"
|
||||
host_mock.channels = [0]
|
||||
host_mock.stream_channels = [0]
|
||||
host_mock.sub_channels.return_value = {None}
|
||||
host_mock.num_cameras = 1
|
||||
host_mock.new_devices = False
|
||||
host_mock.sw_version_update_required = False
|
||||
|
||||
@@ -283,7 +283,7 @@
|
||||
'suggested_object_id': None,
|
||||
'supported_features': <CameraEntityFeature: 2>,
|
||||
'translation_key': 'ptz_down',
|
||||
'unique_id': 'ABC1234567D89EFG_DEF7654321D89GHT_ptz_down',
|
||||
'unique_id': 'ABC1234567D89EFG_DEF7654321D89GHT_sub01_ptz_down',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
@@ -334,7 +334,7 @@
|
||||
'suggested_object_id': None,
|
||||
'supported_features': <CameraEntityFeature: 2>,
|
||||
'translation_key': 'ptz_left',
|
||||
'unique_id': 'ABC1234567D89EFG_DEF7654321D89GHT_ptz_left',
|
||||
'unique_id': 'ABC1234567D89EFG_DEF7654321D89GHT_sub01_ptz_left',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
@@ -487,7 +487,7 @@
|
||||
'suggested_object_id': None,
|
||||
'supported_features': <CameraEntityFeature: 2>,
|
||||
'translation_key': 'ptz_right',
|
||||
'unique_id': 'ABC1234567D89EFG_DEF7654321D89GHT_ptz_right',
|
||||
'unique_id': 'ABC1234567D89EFG_DEF7654321D89GHT_sub01_ptz_right',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
@@ -640,7 +640,7 @@
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'ptz_stop',
|
||||
'unique_id': 'ABC1234567D89EFG_DEF7654321D89GHT_ptz_stop',
|
||||
'unique_id': 'ABC1234567D89EFG_DEF7654321D89GHT_sub01_ptz_stop',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
@@ -690,7 +690,7 @@
|
||||
'suggested_object_id': None,
|
||||
'supported_features': <CameraEntityFeature: 2>,
|
||||
'translation_key': 'ptz_up',
|
||||
'unique_id': 'ABC1234567D89EFG_DEF7654321D89GHT_ptz_up',
|
||||
'unique_id': 'ABC1234567D89EFG_DEF7654321D89GHT_sub01_ptz_up',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
|
||||
@@ -27,8 +27,20 @@ async def test_all_entities(
|
||||
snapshot: SnapshotAssertion,
|
||||
config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
reolink_host: MagicMock,
|
||||
) -> None:
|
||||
"""Test all entities."""
|
||||
|
||||
def mock_supported(ch, capability, sub_channel=None):
|
||||
if capability in {"ptz_stop", "pan", "tilt"}:
|
||||
return sub_channel == 1
|
||||
if sub_channel is not None:
|
||||
return False
|
||||
return True
|
||||
|
||||
reolink_host.sub_channels.return_value = {None, 1}
|
||||
reolink_host.supported = mock_supported
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.reolink.PLATFORMS",
|
||||
[Platform.BUTTON],
|
||||
@@ -68,12 +80,22 @@ async def test_button(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"sub_channel",
|
||||
[
|
||||
None,
|
||||
1,
|
||||
],
|
||||
)
|
||||
async def test_ptz_move_service(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
reolink_host: MagicMock,
|
||||
sub_channel: int | None,
|
||||
) -> None:
|
||||
"""Test ptz_move entity service using PTZ button entity."""
|
||||
reolink_host.sub_channels.return_value = {sub_channel}
|
||||
|
||||
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.BUTTON]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
@@ -87,7 +109,9 @@ async def test_ptz_move_service(
|
||||
{ATTR_ENTITY_ID: entity_id, ATTR_SPEED: 5},
|
||||
blocking=True,
|
||||
)
|
||||
reolink_host.set_ptz_command.assert_called_with(0, command="Up", speed=5)
|
||||
reolink_host.set_ptz_command.assert_called_with(
|
||||
0, sub_channel, command="Up", speed=5
|
||||
)
|
||||
|
||||
reolink_host.set_ptz_command.side_effect = ReolinkError("Test error")
|
||||
with pytest.raises(HomeAssistantError):
|
||||
|
||||
Reference in New Issue
Block a user