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
This commit is contained in:
Pascal Reeb 2023-04-03 14:49:15 +02:00 committed by Paulus Schoutsen
parent 0d6177dbdb
commit c43dc37713
2 changed files with 41 additions and 12 deletions

View File

@ -26,7 +26,11 @@ from homeassistant.const import (
) )
from homeassistant.core import Event, HomeAssistant from homeassistant.core import Event, HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady 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.network import get_url
from homeassistant.helpers.update_coordinator import ( from homeassistant.helpers.update_coordinator import (
CoordinatorEntity, CoordinatorEntity,
@ -152,6 +156,23 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass, allow_cloud=False, allow_external=False, allow_ip=True, require_ssl=False hass, allow_cloud=False, allow_external=False, allow_ip=True, require_ssl=False
) )
url = f"{hass_url}{webhook_url}" url = f"{hass_url}{webhook_url}"
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: try:
async with async_timeout.timeout(10): async with async_timeout.timeout(10):
await hass.async_add_executor_job( await hass.async_add_executor_job(
@ -162,7 +183,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
raise ConfigEntryNotReady(f"Invalid credentials for Bridge: {err}") from err raise ConfigEntryNotReady(f"Invalid credentials for Bridge: {err}") from err
except RequestException as err: except RequestException as err:
webhook.async_unregister(hass, entry.entry_id) webhook.async_unregister(hass, entry.entry_id)
raise ConfigEntryNotReady(f"Error communicating with Bridge: {err}") from err raise ConfigEntryNotReady(
f"Error communicating with Bridge: {err}"
) from err
async def _stop_nuki(_: Event): async def _stop_nuki(_: Event):
"""Stop and remove the Nuki webhook.""" """Stop and remove the Nuki webhook."""

View File

@ -25,5 +25,11 @@
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]", "already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]" "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"
}
} }
} }