Skip to content

Commit

Permalink
Delay creation of Reolink repair issues (home-assistant#97476)
Browse files Browse the repository at this point in the history
* delay creation of repair issues

* fix tests
  • Loading branch information
starkillerOG authored Jul 31, 2023
1 parent f218fb8 commit b266514
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
37 changes: 19 additions & 18 deletions homeassistant/components/reolink/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

DEFAULT_TIMEOUT = 60
FIRST_ONVIF_TIMEOUT = 10
FIRST_ONVIF_LONG_POLL_TIMEOUT = 90
SUBSCRIPTION_RENEW_THRESHOLD = 300
POLL_INTERVAL_NO_PUSH = 5
LONG_POLL_COOLDOWN = 0.75
Expand Down Expand Up @@ -205,7 +206,7 @@ async def _async_check_onvif(self, *_) -> None:
# ONVIF push is not received, start long polling and schedule check
await self._async_start_long_polling()
self._cancel_long_poll_check = async_call_later(
self._hass, FIRST_ONVIF_TIMEOUT, self._async_check_onvif_long_poll
self._hass, FIRST_ONVIF_LONG_POLL_TIMEOUT, self._async_check_onvif_long_poll
)

self._cancel_onvif_check = None
Expand All @@ -215,7 +216,7 @@ async def _async_check_onvif_long_poll(self, *_) -> None:
if not self._long_poll_received:
_LOGGER.debug(
"Did not receive state through ONVIF long polling after %i seconds",
FIRST_ONVIF_TIMEOUT,
FIRST_ONVIF_LONG_POLL_TIMEOUT,
)
ir.async_create_issue(
self._hass,
Expand All @@ -230,8 +231,24 @@ async def _async_check_onvif_long_poll(self, *_) -> None:
"network_link": "https://my.home-assistant.io/redirect/network/",
},
)
if self._base_url.startswith("https"):
ir.async_create_issue(
self._hass,
DOMAIN,
"https_webhook",
is_fixable=False,
severity=ir.IssueSeverity.WARNING,
translation_key="https_webhook",
translation_placeholders={
"base_url": self._base_url,
"network_link": "https://my.home-assistant.io/redirect/network/",
},
)
else:
ir.async_delete_issue(self._hass, DOMAIN, "https_webhook")
else:
ir.async_delete_issue(self._hass, DOMAIN, "webhook_url")
ir.async_delete_issue(self._hass, DOMAIN, "https_webhook")

# If no ONVIF push or long polling state is received, start fast polling
await self._async_poll_all_motion()
Expand Down Expand Up @@ -426,22 +443,6 @@ def register_webhook(self) -> None:
webhook_path = webhook.async_generate_path(event_id)
self._webhook_url = f"{self._base_url}{webhook_path}"

if self._base_url.startswith("https"):
ir.async_create_issue(
self._hass,
DOMAIN,
"https_webhook",
is_fixable=False,
severity=ir.IssueSeverity.WARNING,
translation_key="https_webhook",
translation_placeholders={
"base_url": self._base_url,
"network_link": "https://my.home-assistant.io/redirect/network/",
},
)
else:
ir.async_delete_issue(self._hass, DOMAIN, "https_webhook")

_LOGGER.debug("Registered webhook: %s", event_id)

def unregister_webhook(self):
Expand Down
11 changes: 10 additions & 1 deletion tests/components/reolink/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ async def test_https_repair_issue(
hass, {"country": "GB", "internal_url": "https://test_homeassistant_address"}
)

assert await hass.config_entries.async_setup(config_entry.entry_id)
with patch(
"homeassistant.components.reolink.host.FIRST_ONVIF_TIMEOUT", new=0
), patch(
"homeassistant.components.reolink.host.FIRST_ONVIF_LONG_POLL_TIMEOUT", new=0
), patch(
"homeassistant.components.reolink.host.ReolinkHost._async_long_polling",
):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()

issue_registry = ir.async_get(hass)
Expand Down Expand Up @@ -150,6 +157,8 @@ async def test_webhook_repair_issue(
"""Test repairs issue is raised when the webhook url is unreachable."""
with patch(
"homeassistant.components.reolink.host.FIRST_ONVIF_TIMEOUT", new=0
), patch(
"homeassistant.components.reolink.host.FIRST_ONVIF_LONG_POLL_TIMEOUT", new=0
), patch(
"homeassistant.components.reolink.host.ReolinkHost._async_long_polling",
):
Expand Down

0 comments on commit b266514

Please sign in to comment.