Import webhook in netatmo (#64105)

* Import webhook in netatmo

* Adjust tests

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-01-14 13:01:14 +01:00 committed by GitHub
parent 0042bb68d9
commit e492cb5156
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 18 deletions

View file

@ -12,6 +12,7 @@ import voluptuous as vol
from homeassistant.components import cloud
from homeassistant.components.webhook import (
async_generate_url as webhook_generate_url,
async_register as webhook_register,
async_unregister as webhook_unregister,
)
@ -192,9 +193,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
else:
webhook_url = entry.data[CONF_CLOUDHOOK_URL]
else:
webhook_url = hass.components.webhook.async_generate_url(
entry.data[CONF_WEBHOOK_ID]
)
webhook_url = webhook_generate_url(hass, entry.data[CONF_WEBHOOK_ID])
if entry.data[
"auth_implementation"

View file

@ -106,5 +106,5 @@ def selected_platforms(platforms):
"""Restrict loaded platforms to list given."""
with patch("homeassistant.components.netatmo.PLATFORMS", platforms), patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
), patch("homeassistant.components.webhook.async_generate_url"):
), patch("homeassistant.components.netatmo.webhook_generate_url"):
yield

View file

@ -345,7 +345,7 @@ async def test_camera_reconnect_webhook(hass, config_entry):
), patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
), patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
) as mock_webhook:
mock_auth.return_value.async_post_request.side_effect = fake_post
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
@ -437,7 +437,7 @@ async def test_setup_component_no_devices(hass, config_entry):
), patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
), patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
):
mock_auth.return_value.async_post_request.side_effect = fake_post_no_data
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
@ -475,7 +475,7 @@ async def test_camera_image_raises_exception(hass, config_entry, requests_mock):
), patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
), patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
):
mock_auth.return_value.async_post_request.side_effect = fake_post
mock_auth.return_value.async_get_image.side_effect = fake_post

View file

@ -58,7 +58,7 @@ async def test_setup_component(hass, config_entry):
) as mock_auth, patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
) as mock_impl, patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
) as mock_webhook:
mock_auth.return_value.async_post_request.side_effect = fake_post_request
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
@ -96,7 +96,7 @@ async def test_setup_component_with_config(hass, config_entry):
with patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
) as mock_impl, patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
) as mock_webhook, patch(
"homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth",
) as mock_auth, patch(
@ -160,7 +160,7 @@ async def test_setup_without_https(hass, config_entry, caplog):
) as mock_auth, patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
), patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
) as mock_async_generate_url:
mock_auth.return_value.async_post_request.side_effect = fake_post_request
mock_async_generate_url.return_value = "http://example.com"
@ -196,7 +196,7 @@ async def test_setup_with_cloud(hass, config_entry):
), patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
), patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
):
mock_auth.return_value.async_post_request.side_effect = fake_post_request
assert await async_setup_component(
@ -259,7 +259,7 @@ async def test_setup_with_cloudhook(hass):
), patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
), patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
):
mock_auth.return_value.async_post_request.side_effect = fake_post_request
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
@ -291,7 +291,7 @@ async def test_setup_component_api_error(hass, config_entry):
) as mock_auth, patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
) as mock_impl, patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
):
mock_auth.return_value.async_post_request.side_effect = (
pyatmo.exceptions.ApiError()
@ -314,7 +314,7 @@ async def test_setup_component_api_timeout(hass, config_entry):
) as mock_auth, patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
) as mock_impl, patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
):
mock_auth.return_value.async_post_request.side_effect = (
asyncio.exceptions.TimeoutError()
@ -341,7 +341,7 @@ async def test_setup_component_with_delay(hass, config_entry):
) as mock_dropwebhook, patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
) as mock_impl, patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
) as mock_webhook, patch(
"pyatmo.AbstractAsyncAuth.async_post_request", side_effect=fake_post_request
) as mock_post_request, patch(
@ -415,7 +415,7 @@ async def test_setup_component_invalid_token_scope(hass):
) as mock_auth, patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
) as mock_impl, patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
) as mock_webhook:
mock_auth.return_value.async_post_request.side_effect = fake_post_request
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
@ -456,7 +456,7 @@ async def test_setup_component_invalid_token(hass, config_entry):
) as mock_auth, patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
) as mock_impl, patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
) as mock_webhook, patch(
"homeassistant.helpers.config_entry_oauth2_flow.OAuth2Session"
) as mock_session:

View file

@ -98,7 +98,7 @@ async def test_setup_component_no_devices(hass, config_entry):
), patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
), patch(
"homeassistant.components.webhook.async_generate_url"
"homeassistant.components.netatmo.webhook_generate_url"
):
mock_auth.return_value.async_post_request.side_effect = (
fake_post_request_no_data