Use repair issue when port enable fails in Reolink (#89591)

* Reolink use repair issue for disabled ports

* fix styling

* Add port repair issue tests

* Update homeassistant/components/reolink/strings.json

Co-authored-by: Erik Montnemery <erik@montnemery.com>

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
starkillerOG 2023-03-13 11:43:41 +01:00 committed by GitHub
parent 62bd2e97f5
commit 6e10cd81dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 14 deletions

View file

@ -109,23 +109,30 @@ class ReolinkHost:
enable_rtsp=enable_rtsp, enable_rtsp=enable_rtsp,
) )
except ReolinkError: except ReolinkError:
ports = ""
if enable_onvif: if enable_onvif:
_LOGGER.error( ports += "ONVIF "
"Failed to enable ONVIF on %s. "
"Set it to ON to receive notifications",
self._api.nvr_name,
)
if enable_rtmp: if enable_rtmp:
_LOGGER.error( ports += "RTMP "
"Failed to enable RTMP on %s. Set it to ON",
self._api.nvr_name,
)
elif enable_rtsp: elif enable_rtsp:
_LOGGER.error( ports += "RTSP "
"Failed to enable RTSP on %s. Set it to ON",
self._api.nvr_name, 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) self._unique_id = format_mac(self._api.mac_address)

View file

@ -42,6 +42,10 @@
"https_webhook": { "https_webhook": {
"title": "Reolink webhook URL uses HTTPS (SSL)", "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}`" "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": { "entity": {

View file

@ -86,7 +86,7 @@ async def test_entry_reloading(
assert config_entry.title == "New Name" assert config_entry.title == "New Name"
async def test_http_no_repair_issue( async def test_no_repair_issue(
hass: HomeAssistant, config_entry: MockConfigEntry hass: HomeAssistant, config_entry: MockConfigEntry
) -> None: ) -> None:
"""Test no repairs issue is raised when http local url is used.""" """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) issue_registry = ir.async_get(hass)
assert (const.DOMAIN, "https_webhook") not in issue_registry.issues 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( async def test_https_repair_issue(
@ -114,3 +115,23 @@ async def test_https_repair_issue(
issue_registry = ir.async_get(hass) issue_registry = ir.async_get(hass)
assert (const.DOMAIN, "https_webhook") in issue_registry.issues 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