From 3a672642ea004197b857f4bc73a6c058be63780b Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 16 Jun 2024 14:02:10 +0200 Subject: [PATCH] Reolink extend diagnostic data (#119745) * Add diagnostic info * fix * change order * update tests --- .../components/reolink/diagnostics.py | 4 + homeassistant/components/reolink/host.py | 16 +-- tests/components/reolink/conftest.py | 2 + .../reolink/snapshots/test_diagnostics.ambr | 108 ++++++++++++++++++ 4 files changed, 122 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/reolink/diagnostics.py b/homeassistant/components/reolink/diagnostics.py index 5c13bccf58d..b06ddcd458f 100644 --- a/homeassistant/components/reolink/diagnostics.py +++ b/homeassistant/components/reolink/diagnostics.py @@ -23,7 +23,9 @@ async def async_get_config_entry_diagnostics( for ch in api.channels: IPC_cam[ch] = {} IPC_cam[ch]["model"] = api.camera_model(ch) + IPC_cam[ch]["hardware version"] = api.camera_hardware_version(ch) IPC_cam[ch]["firmware version"] = api.camera_sw_version(ch) + IPC_cam[ch]["encoding main"] = await api.get_encoding(ch) return { "model": api.model, @@ -42,6 +44,8 @@ async def async_get_config_entry_diagnostics( "stream channels": api.stream_channels, "IPC cams": IPC_cam, "capabilities": api.capabilities, + "cmd list": host.update_cmd, + "firmware ch list": host.firmware_ch_list, "api versions": api.checked_api_versions, "abilities": api.abilities, } diff --git a/homeassistant/components/reolink/host.py b/homeassistant/components/reolink/host.py index 83f366005f9..8256ef7f017 100644 --- a/homeassistant/components/reolink/host.py +++ b/homeassistant/components/reolink/host.py @@ -74,7 +74,7 @@ class ReolinkHost: ) self.last_wake: float = 0 - self._update_cmd: defaultdict[str, defaultdict[int | None, int]] = defaultdict( + self.update_cmd: defaultdict[str, defaultdict[int | None, int]] = defaultdict( lambda: defaultdict(int) ) self.firmware_ch_list: list[int | None] = [] @@ -97,16 +97,16 @@ class ReolinkHost: @callback def async_register_update_cmd(self, cmd: str, channel: int | None = None) -> None: """Register the command to update the state.""" - self._update_cmd[cmd][channel] += 1 + self.update_cmd[cmd][channel] += 1 @callback def async_unregister_update_cmd(self, cmd: str, channel: int | None = None) -> None: """Unregister the command to update the state.""" - self._update_cmd[cmd][channel] -= 1 - if not self._update_cmd[cmd][channel]: - del self._update_cmd[cmd][channel] - if not self._update_cmd[cmd]: - del self._update_cmd[cmd] + self.update_cmd[cmd][channel] -= 1 + if not self.update_cmd[cmd][channel]: + del self.update_cmd[cmd][channel] + if not self.update_cmd[cmd]: + del self.update_cmd[cmd] @property def unique_id(self) -> str: @@ -350,7 +350,7 @@ class ReolinkHost: wake = True self.last_wake = time() - await self._api.get_states(cmd_list=self._update_cmd, wake=wake) + await self._api.get_states(cmd_list=self.update_cmd, wake=wake) async def disconnect(self) -> None: """Disconnect from the API, so the connection will be released.""" diff --git a/tests/components/reolink/conftest.py b/tests/components/reolink/conftest.py index 9b7dd481c9d..4fed102b320 100644 --- a/tests/components/reolink/conftest.py +++ b/tests/components/reolink/conftest.py @@ -84,8 +84,10 @@ def reolink_connect_class() -> Generator[MagicMock]: host_mock.model = TEST_HOST_MODEL host_mock.camera_model.return_value = TEST_CAM_MODEL host_mock.camera_name.return_value = TEST_NVR_NAME + host_mock.camera_hardware_version.return_value = "IPC_00001" host_mock.camera_sw_version.return_value = "v1.1.0.0.0.0000" host_mock.camera_uid.return_value = TEST_UID + host_mock.get_encoding.return_value = "h264" host_mock.firmware_update_available.return_value = False host_mock.session_active = True host_mock.timeout = 60 diff --git a/tests/components/reolink/snapshots/test_diagnostics.ambr b/tests/components/reolink/snapshots/test_diagnostics.ambr index 9f70673695c..00363023d14 100644 --- a/tests/components/reolink/snapshots/test_diagnostics.ambr +++ b/tests/components/reolink/snapshots/test_diagnostics.ambr @@ -5,7 +5,9 @@ 'HTTPS': True, 'IPC cams': dict({ '0': dict({ + 'encoding main': 'h264', 'firmware version': 'v1.1.0.0.0.0000', + 'hardware version': 'IPC_00001', 'model': 'RLC-123', }), }), @@ -38,7 +40,113 @@ 'channels': list([ 0, ]), + 'cmd list': dict({ + 'GetAiAlarm': dict({ + '0': 5, + 'null': 5, + }), + 'GetAiCfg': dict({ + '0': 4, + 'null': 4, + }), + 'GetAudioAlarm': dict({ + '0': 1, + 'null': 1, + }), + 'GetAudioCfg': dict({ + '0': 2, + 'null': 2, + }), + 'GetAutoFocus': dict({ + '0': 1, + 'null': 1, + }), + 'GetAutoReply': dict({ + '0': 2, + 'null': 2, + }), + 'GetBatteryInfo': dict({ + '0': 1, + 'null': 1, + }), + 'GetBuzzerAlarmV20': dict({ + '0': 1, + 'null': 2, + }), + 'GetChannelstatus': dict({ + '0': 1, + 'null': 1, + }), + 'GetEmail': dict({ + '0': 1, + 'null': 2, + }), + 'GetEnc': dict({ + '0': 1, + 'null': 1, + }), + 'GetFtp': dict({ + '0': 1, + 'null': 2, + }), + 'GetIrLights': dict({ + '0': 1, + 'null': 1, + }), + 'GetIsp': dict({ + '0': 1, + 'null': 1, + }), + 'GetManualRec': dict({ + '0': 1, + 'null': 1, + }), + 'GetMdAlarm': dict({ + '0': 1, + 'null': 1, + }), + 'GetPirInfo': dict({ + '0': 1, + 'null': 1, + }), + 'GetPowerLed': dict({ + '0': 2, + 'null': 2, + }), + 'GetPtzCurPos': dict({ + '0': 1, + 'null': 1, + }), + 'GetPtzGuard': dict({ + '0': 2, + 'null': 2, + }), + 'GetPtzTraceSection': dict({ + '0': 2, + 'null': 2, + }), + 'GetPush': dict({ + '0': 1, + 'null': 2, + }), + 'GetRec': dict({ + '0': 1, + 'null': 2, + }), + 'GetWhiteLed': dict({ + '0': 3, + 'null': 3, + }), + 'GetZoomFocus': dict({ + '0': 2, + 'null': 2, + }), + }), 'event connection': 'Fast polling', + 'firmware ch list': list([ + 0, + None, + ]), 'firmware version': 'v1.0.0.0.0.0000', 'hardware version': 'IPC_00000', 'model': 'RLN8-410',