diff --git a/homeassistant/components/reolink/host.py b/homeassistant/components/reolink/host.py index 9994afe79a8..9d54191aadd 100644 --- a/homeassistant/components/reolink/host.py +++ b/homeassistant/components/reolink/host.py @@ -109,23 +109,30 @@ class ReolinkHost: enable_rtsp=enable_rtsp, ) except ReolinkError: + ports = "" if enable_onvif: - _LOGGER.error( - "Failed to enable ONVIF on %s. " - "Set it to ON to receive notifications", - self._api.nvr_name, - ) + ports += "ONVIF " if enable_rtmp: - _LOGGER.error( - "Failed to enable RTMP on %s. Set it to ON", - self._api.nvr_name, - ) + ports += "RTMP " elif enable_rtsp: - _LOGGER.error( - "Failed to enable RTSP on %s. Set it to ON", - self._api.nvr_name, - ) + ports += "RTSP " + + ir.async_create_issue( + self._hass, + DOMAIN, + "enable_port", + is_fixable=False, + severity=ir.IssueSeverity.WARNING, + translation_key="enable_port", + translation_placeholders={ + "name": self._api.nvr_name, + "ports": ports, + "info_link": "https://support.reolink.com/hc/en-us/articles/900004435763-How-to-Set-up-Reolink-Ports-Settings-via-Reolink-Client-New-Client-", + }, + ) + else: + ir.async_delete_issue(self._hass, DOMAIN, "enable_port") self._unique_id = format_mac(self._api.mac_address) diff --git a/homeassistant/components/reolink/strings.json b/homeassistant/components/reolink/strings.json index 3ab77d2b8f4..c86917b4de2 100644 --- a/homeassistant/components/reolink/strings.json +++ b/homeassistant/components/reolink/strings.json @@ -42,6 +42,10 @@ "https_webhook": { "title": "Reolink webhook URL uses HTTPS (SSL)", "description": "Reolink products can not push motion events to an HTTPS address (SSL), please configure a (local) HTTP address under \"Home Assistant URL\" in the [network settings]({network_link}). The current (local) address is: `{base_url}`" + }, + "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" } }, "entity": { diff --git a/tests/components/reolink/test_init.py b/tests/components/reolink/test_init.py index 035bfa6e538..52bd2d8c5f8 100644 --- a/tests/components/reolink/test_init.py +++ b/tests/components/reolink/test_init.py @@ -86,7 +86,7 @@ async def test_entry_reloading( assert config_entry.title == "New Name" -async def test_http_no_repair_issue( +async def test_no_repair_issue( hass: HomeAssistant, config_entry: MockConfigEntry ) -> None: """Test no repairs issue is raised when http local url is used.""" @@ -99,6 +99,7 @@ async def test_http_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 async def test_https_repair_issue( @@ -114,3 +115,23 @@ async def test_https_repair_issue( issue_registry = ir.async_get(hass) assert (const.DOMAIN, "https_webhook") in issue_registry.issues + + +@pytest.mark.parametrize("protocol", ["rtsp", "rtmp"]) +async def test_port_repair_issue( + hass: HomeAssistant, + config_entry: MockConfigEntry, + reolink_connect: MagicMock, + protocol: str, +) -> None: + """Test repairs issue is raised when auto enable of ports fails.""" + reolink_connect.set_net_port = AsyncMock(side_effect=ReolinkError("Test error")) + reolink_connect.onvif_enabled = False + reolink_connect.rtsp_enabled = False + reolink_connect.rtmp_enabled = False + reolink_connect.protocol = protocol + 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, "enable_port") in issue_registry.issues