From c43dc37713a668f5170347d387c838ef8f5a05c0 Mon Sep 17 00:00:00 2001 From: Pascal Reeb Date: Mon, 3 Apr 2023 14:49:15 +0200 Subject: [PATCH] Add Warning in the issue registry if a HTTPS webhook is used for Nuki (#90718) feat(nuki): create issue when https webhook URL was created --- homeassistant/components/nuki/__init__.py | 47 ++++++++++++++++------ homeassistant/components/nuki/strings.json | 6 +++ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/nuki/__init__.py b/homeassistant/components/nuki/__init__.py index 8a7985fe28c..ee8cc4e7e97 100644 --- a/homeassistant/components/nuki/__init__.py +++ b/homeassistant/components/nuki/__init__.py @@ -26,7 +26,11 @@ from homeassistant.const import ( ) from homeassistant.core import Event, HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady -from homeassistant.helpers import device_registry as dr, entity_registry as er +from homeassistant.helpers import ( + device_registry as dr, + entity_registry as er, + issue_registry as ir, +) from homeassistant.helpers.network import get_url from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, @@ -152,17 +156,36 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass, allow_cloud=False, allow_external=False, allow_ip=True, require_ssl=False ) url = f"{hass_url}{webhook_url}" - try: - async with async_timeout.timeout(10): - await hass.async_add_executor_job( - _register_webhook, bridge, entry.entry_id, url - ) - except InvalidCredentialsException as err: - webhook.async_unregister(hass, entry.entry_id) - raise ConfigEntryNotReady(f"Invalid credentials for Bridge: {err}") from err - except RequestException as err: - webhook.async_unregister(hass, entry.entry_id) - raise ConfigEntryNotReady(f"Error communicating with Bridge: {err}") from err + + if hass_url.startswith("https"): + ir.async_create_issue( + hass, + DOMAIN, + "https_webhook", + is_fixable=False, + severity=ir.IssueSeverity.WARNING, + translation_key="https_webhook", + translation_placeholders={ + "base_url": hass_url, + "network_link": "https://my.home-assistant.io/redirect/network/", + }, + ) + else: + ir.async_delete_issue(hass, DOMAIN, "https_webhook") + + try: + async with async_timeout.timeout(10): + await hass.async_add_executor_job( + _register_webhook, bridge, entry.entry_id, url + ) + except InvalidCredentialsException as err: + webhook.async_unregister(hass, entry.entry_id) + raise ConfigEntryNotReady(f"Invalid credentials for Bridge: {err}") from err + except RequestException as err: + webhook.async_unregister(hass, entry.entry_id) + raise ConfigEntryNotReady( + f"Error communicating with Bridge: {err}" + ) from err async def _stop_nuki(_: Event): """Stop and remove the Nuki webhook.""" diff --git a/homeassistant/components/nuki/strings.json b/homeassistant/components/nuki/strings.json index 32b72c74252..3b0263e0a30 100644 --- a/homeassistant/components/nuki/strings.json +++ b/homeassistant/components/nuki/strings.json @@ -25,5 +25,11 @@ "already_configured": "[%key:common::config_flow::abort::already_configured_device%]", "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]" } + }, + "issues": { + "https_webhook": { + "title": "Nuki webhook URL uses HTTPS (SSL)", + "description": "The Nuki bridge can not push 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}`, a valid address could, for example, be `http://192.168.1.10:8123` where `192.168.1.10` is the IP of the Home Assistant device" + } } }