diff --git a/homeassistant/components/tedee/__init__.py b/homeassistant/components/tedee/__init__.py index b661d993db8..a1b87cf13a4 100644 --- a/homeassistant/components/tedee/__init__.py +++ b/homeassistant/components/tedee/__init__.py @@ -12,7 +12,7 @@ from pytedee_async.exception import TedeeDataUpdateException, TedeeWebhookExcept from homeassistant.components.http import HomeAssistantView from homeassistant.components.webhook import ( async_generate_id as webhook_generate_id, - async_generate_path as webhook_generate_path, + async_generate_url as webhook_generate_url, async_register as webhook_register, async_unregister as webhook_unregister, ) @@ -66,8 +66,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: TedeeConfigEntry) -> boo await coordinator.tedee_client.cleanup_webhooks_by_host(instance_url) except (TedeeDataUpdateException, TedeeWebhookException) as ex: _LOGGER.warning("Failed to cleanup Tedee webhooks by host: %s", ex) - webhook_url = ( - f"{instance_url}{webhook_generate_path(entry.data[CONF_WEBHOOK_ID])}" + + webhook_url = webhook_generate_url( + hass, entry.data[CONF_WEBHOOK_ID], allow_external=False, allow_ip=True ) webhook_name = "Tedee" if entry.title != NAME: diff --git a/homeassistant/components/webhook/__init__.py b/homeassistant/components/webhook/__init__.py index 04234b2ac42..7d282b8aef3 100644 --- a/homeassistant/components/webhook/__init__.py +++ b/homeassistant/components/webhook/__init__.py @@ -87,10 +87,17 @@ def async_generate_id() -> str: @callback @bind_hass -def async_generate_url(hass: HomeAssistant, webhook_id: str) -> str: +def async_generate_url( + hass: HomeAssistant, + webhook_id: str, + allow_internal: bool = True, + allow_external: bool = True, + allow_ip: bool | None = None, + prefer_external: bool | None = True, +) -> str: """Generate the full URL for a webhook_id.""" return ( - f"{get_url(hass, prefer_external=True, allow_cloud=False)}" + f"{get_url(hass,allow_internal=allow_internal, allow_external=allow_external, allow_cloud=False, allow_ip=allow_ip, prefer_external=prefer_external,)}" f"{async_generate_path(webhook_id)}" ) diff --git a/tests/components/webhook/test_init.py b/tests/components/webhook/test_init.py index b3d309f1f24..6f4ae1ebefc 100644 --- a/tests/components/webhook/test_init.py +++ b/tests/components/webhook/test_init.py @@ -56,6 +56,22 @@ async def test_generate_webhook_url(hass: HomeAssistant) -> None: assert url == "https://example.com/api/webhook/some_id" +async def test_generate_webhook_url_internal(hass: HomeAssistant) -> None: + """Test we can get the internal URL.""" + await async_process_ha_core_config( + hass, + { + "internal_url": "http://192.168.1.100:8123", + "external_url": "https://example.com", + }, + ) + url = webhook.async_generate_url( + hass, "some_id", allow_external=False, allow_ip=True + ) + + assert url == "http://192.168.1.100:8123/api/webhook/some_id" + + async def test_async_generate_path(hass: HomeAssistant) -> None: """Test generating just the path component of the url correctly.""" path = webhook.async_generate_path("some_id")