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:
parent
0042bb68d9
commit
e492cb5156
5 changed files with 17 additions and 18 deletions
|
@ -12,6 +12,7 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import cloud
|
from homeassistant.components import cloud
|
||||||
from homeassistant.components.webhook import (
|
from homeassistant.components.webhook import (
|
||||||
|
async_generate_url as webhook_generate_url,
|
||||||
async_register as webhook_register,
|
async_register as webhook_register,
|
||||||
async_unregister as webhook_unregister,
|
async_unregister as webhook_unregister,
|
||||||
)
|
)
|
||||||
|
@ -192,9 +193,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
else:
|
else:
|
||||||
webhook_url = entry.data[CONF_CLOUDHOOK_URL]
|
webhook_url = entry.data[CONF_CLOUDHOOK_URL]
|
||||||
else:
|
else:
|
||||||
webhook_url = hass.components.webhook.async_generate_url(
|
webhook_url = webhook_generate_url(hass, entry.data[CONF_WEBHOOK_ID])
|
||||||
entry.data[CONF_WEBHOOK_ID]
|
|
||||||
)
|
|
||||||
|
|
||||||
if entry.data[
|
if entry.data[
|
||||||
"auth_implementation"
|
"auth_implementation"
|
||||||
|
|
|
@ -106,5 +106,5 @@ def selected_platforms(platforms):
|
||||||
"""Restrict loaded platforms to list given."""
|
"""Restrict loaded platforms to list given."""
|
||||||
with patch("homeassistant.components.netatmo.PLATFORMS", platforms), patch(
|
with patch("homeassistant.components.netatmo.PLATFORMS", platforms), patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"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
|
yield
|
||||||
|
|
|
@ -345,7 +345,7 @@ async def test_camera_reconnect_webhook(hass, config_entry):
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.webhook.async_generate_url"
|
"homeassistant.components.netatmo.webhook_generate_url"
|
||||||
) as mock_webhook:
|
) as mock_webhook:
|
||||||
mock_auth.return_value.async_post_request.side_effect = fake_post
|
mock_auth.return_value.async_post_request.side_effect = fake_post
|
||||||
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
|
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
|
||||||
|
@ -437,7 +437,7 @@ async def test_setup_component_no_devices(hass, config_entry):
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
), patch(
|
), 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_post_request.side_effect = fake_post_no_data
|
||||||
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
|
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(
|
), patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
), patch(
|
), 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_post_request.side_effect = fake_post
|
||||||
mock_auth.return_value.async_get_image.side_effect = fake_post
|
mock_auth.return_value.async_get_image.side_effect = fake_post
|
||||||
|
|
|
@ -58,7 +58,7 @@ async def test_setup_component(hass, config_entry):
|
||||||
) as mock_auth, patch(
|
) as mock_auth, patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
) as mock_impl, patch(
|
) as mock_impl, patch(
|
||||||
"homeassistant.components.webhook.async_generate_url"
|
"homeassistant.components.netatmo.webhook_generate_url"
|
||||||
) as mock_webhook:
|
) as mock_webhook:
|
||||||
mock_auth.return_value.async_post_request.side_effect = fake_post_request
|
mock_auth.return_value.async_post_request.side_effect = fake_post_request
|
||||||
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
|
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(
|
with patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
) as mock_impl, patch(
|
) as mock_impl, patch(
|
||||||
"homeassistant.components.webhook.async_generate_url"
|
"homeassistant.components.netatmo.webhook_generate_url"
|
||||||
) as mock_webhook, patch(
|
) as mock_webhook, patch(
|
||||||
"homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth",
|
"homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth",
|
||||||
) as mock_auth, patch(
|
) as mock_auth, patch(
|
||||||
|
@ -160,7 +160,7 @@ async def test_setup_without_https(hass, config_entry, caplog):
|
||||||
) as mock_auth, patch(
|
) as mock_auth, patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.webhook.async_generate_url"
|
"homeassistant.components.netatmo.webhook_generate_url"
|
||||||
) as mock_async_generate_url:
|
) as mock_async_generate_url:
|
||||||
mock_auth.return_value.async_post_request.side_effect = fake_post_request
|
mock_auth.return_value.async_post_request.side_effect = fake_post_request
|
||||||
mock_async_generate_url.return_value = "http://example.com"
|
mock_async_generate_url.return_value = "http://example.com"
|
||||||
|
@ -196,7 +196,7 @@ async def test_setup_with_cloud(hass, config_entry):
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
), patch(
|
), 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_post_request.side_effect = fake_post_request
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
@ -259,7 +259,7 @@ async def test_setup_with_cloudhook(hass):
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
), patch(
|
), 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_post_request.side_effect = fake_post_request
|
||||||
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
|
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(
|
) as mock_auth, patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
) as mock_impl, patch(
|
) 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 = (
|
mock_auth.return_value.async_post_request.side_effect = (
|
||||||
pyatmo.exceptions.ApiError()
|
pyatmo.exceptions.ApiError()
|
||||||
|
@ -314,7 +314,7 @@ async def test_setup_component_api_timeout(hass, config_entry):
|
||||||
) as mock_auth, patch(
|
) as mock_auth, patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
) as mock_impl, patch(
|
) 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 = (
|
mock_auth.return_value.async_post_request.side_effect = (
|
||||||
asyncio.exceptions.TimeoutError()
|
asyncio.exceptions.TimeoutError()
|
||||||
|
@ -341,7 +341,7 @@ async def test_setup_component_with_delay(hass, config_entry):
|
||||||
) as mock_dropwebhook, patch(
|
) as mock_dropwebhook, patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
) as mock_impl, patch(
|
) as mock_impl, patch(
|
||||||
"homeassistant.components.webhook.async_generate_url"
|
"homeassistant.components.netatmo.webhook_generate_url"
|
||||||
) as mock_webhook, patch(
|
) as mock_webhook, patch(
|
||||||
"pyatmo.AbstractAsyncAuth.async_post_request", side_effect=fake_post_request
|
"pyatmo.AbstractAsyncAuth.async_post_request", side_effect=fake_post_request
|
||||||
) as mock_post_request, patch(
|
) as mock_post_request, patch(
|
||||||
|
@ -415,7 +415,7 @@ async def test_setup_component_invalid_token_scope(hass):
|
||||||
) as mock_auth, patch(
|
) as mock_auth, patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
) as mock_impl, patch(
|
) as mock_impl, patch(
|
||||||
"homeassistant.components.webhook.async_generate_url"
|
"homeassistant.components.netatmo.webhook_generate_url"
|
||||||
) as mock_webhook:
|
) as mock_webhook:
|
||||||
mock_auth.return_value.async_post_request.side_effect = fake_post_request
|
mock_auth.return_value.async_post_request.side_effect = fake_post_request
|
||||||
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
|
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(
|
) as mock_auth, patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
) as mock_impl, patch(
|
) as mock_impl, patch(
|
||||||
"homeassistant.components.webhook.async_generate_url"
|
"homeassistant.components.netatmo.webhook_generate_url"
|
||||||
) as mock_webhook, patch(
|
) as mock_webhook, patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.OAuth2Session"
|
"homeassistant.helpers.config_entry_oauth2_flow.OAuth2Session"
|
||||||
) as mock_session:
|
) as mock_session:
|
||||||
|
|
|
@ -98,7 +98,7 @@ async def test_setup_component_no_devices(hass, config_entry):
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.webhook.async_generate_url"
|
"homeassistant.components.netatmo.webhook_generate_url"
|
||||||
):
|
):
|
||||||
mock_auth.return_value.async_post_request.side_effect = (
|
mock_auth.return_value.async_post_request.side_effect = (
|
||||||
fake_post_request_no_data
|
fake_post_request_no_data
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue