From 4eee6267703c9287c893a58c2a2354cb56fc17a4 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Wed, 15 Mar 2023 18:54:28 +0100 Subject: [PATCH] Reolink check firmware (#88903) --- homeassistant/components/reolink/host.py | 20 +++++++++++++++++++ homeassistant/components/reolink/strings.json | 4 ++++ tests/components/reolink/test_init.py | 13 ++++++++++++ 3 files changed, 37 insertions(+) diff --git a/homeassistant/components/reolink/host.py b/homeassistant/components/reolink/host.py index 9d54191aadd..e8e96ffe9b9 100644 --- a/homeassistant/components/reolink/host.py +++ b/homeassistant/components/reolink/host.py @@ -138,6 +138,26 @@ class ReolinkHost: await self.subscribe() + if self._api.sw_version_update_required: + ir.async_create_issue( + self._hass, + DOMAIN, + "firmware_update", + is_fixable=False, + severity=ir.IssueSeverity.WARNING, + translation_key="firmware_update", + translation_placeholders={ + "required_firmware": self._api.sw_version_required.version_string, + "current_firmware": self._api.sw_version, + "model": self._api.model, + "hw_version": self._api.hardware_version, + "name": self._api.nvr_name, + "download_link": "https://reolink.com/download-center/", + }, + ) + else: + ir.async_delete_issue(self._hass, DOMAIN, "firmware_update") + async def update_states(self) -> None: """Call the API of the camera device to update the internal states.""" await self._api.get_states() diff --git a/homeassistant/components/reolink/strings.json b/homeassistant/components/reolink/strings.json index 5047c4f2713..06b588a119c 100644 --- a/homeassistant/components/reolink/strings.json +++ b/homeassistant/components/reolink/strings.json @@ -46,6 +46,10 @@ "enable_port": { "title": "Reolink port not enabled", "description": "Failed to automatically enable {ports}port(s) on {name}. Use the [Reolink client]({info_link}) to manually set it to ON" + }, + "firmware_update": { + "title": "Reolink firmware update required", + "description": "\"{name}\" with model \"{model}\" and hardware version \"{hw_version}\" is running a old firmware version \"{current_firmware}\", while at least firmware version \"{required_firmware}\" is required for proper operation of the Reolink integration. The latest firmware can be downloaded from the [Reolink download center]({download_link})." } }, "entity": { diff --git a/tests/components/reolink/test_init.py b/tests/components/reolink/test_init.py index 52bd2d8c5f8..8849c7d52d3 100644 --- a/tests/components/reolink/test_init.py +++ b/tests/components/reolink/test_init.py @@ -100,6 +100,7 @@ async def test_no_repair_issue( issue_registry = ir.async_get(hass) assert (const.DOMAIN, "https_webhook") not in issue_registry.issues assert (const.DOMAIN, "enable_port") not in issue_registry.issues + assert (const.DOMAIN, "firmware_update") not in issue_registry.issues async def test_https_repair_issue( @@ -135,3 +136,15 @@ async def test_port_repair_issue( issue_registry = ir.async_get(hass) assert (const.DOMAIN, "enable_port") in issue_registry.issues + + +async def test_firmware_repair_issue( + hass: HomeAssistant, config_entry: MockConfigEntry, reolink_connect: MagicMock +) -> None: + """Test firmware issue is raised when too old firmware is used.""" + reolink_connect.sw_version_update_required = True + assert await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + + issue_registry = ir.async_get(hass) + assert (const.DOMAIN, "firmware_update") in issue_registry.issues