mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Delete existing Withings cloudhook (#101527)
This commit is contained in:
parent
81f582eeb7
commit
76f78e249b
@ -5,6 +5,7 @@ For more details about this platform, please refer to the documentation at
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Awaitable, Callable
|
from collections.abc import Awaitable, Callable
|
||||||
|
import contextlib
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from aiohttp.hdrs import METH_HEAD, METH_POST
|
from aiohttp.hdrs import METH_HEAD, METH_POST
|
||||||
@ -214,9 +215,12 @@ async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|||||||
async def async_cloudhook_generate_url(hass: HomeAssistant, entry: ConfigEntry) -> str:
|
async def async_cloudhook_generate_url(hass: HomeAssistant, entry: ConfigEntry) -> str:
|
||||||
"""Generate the full URL for a webhook_id."""
|
"""Generate the full URL for a webhook_id."""
|
||||||
if CONF_CLOUDHOOK_URL not in entry.data:
|
if CONF_CLOUDHOOK_URL not in entry.data:
|
||||||
webhook_url = await cloud.async_create_cloudhook(
|
webhook_id = entry.data[CONF_WEBHOOK_ID]
|
||||||
hass, entry.data[CONF_WEBHOOK_ID]
|
# Some users already have their webhook as cloudhook.
|
||||||
)
|
# We remove them to be sure we can create a new one.
|
||||||
|
with contextlib.suppress(ValueError):
|
||||||
|
await cloud.async_delete_cloudhook(hass, webhook_id)
|
||||||
|
webhook_url = await cloud.async_create_cloudhook(hass, webhook_id)
|
||||||
data = {**entry.data, CONF_CLOUDHOOK_URL: webhook_url}
|
data = {**entry.data, CONF_CLOUDHOOK_URL: webhook_url}
|
||||||
hass.config_entries.async_update_entry(entry, data=data)
|
hass.config_entries.async_update_entry(entry, data=data)
|
||||||
return webhook_url
|
return webhook_url
|
||||||
|
@ -421,6 +421,7 @@ async def test_setup_with_cloud(
|
|||||||
assert hass.components.cloud.async_active_subscription() is True
|
assert hass.components.cloud.async_active_subscription() is True
|
||||||
assert hass.components.cloud.async_is_connected() is True
|
assert hass.components.cloud.async_is_connected() is True
|
||||||
fake_create_cloudhook.assert_called_once()
|
fake_create_cloudhook.assert_called_once()
|
||||||
|
fake_delete_cloudhook.assert_called_once()
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
hass.config_entries.async_entries("withings")[0].data["cloudhook_url"]
|
hass.config_entries.async_entries("withings")[0].data["cloudhook_url"]
|
||||||
@ -432,7 +433,7 @@ async def test_setup_with_cloud(
|
|||||||
|
|
||||||
for config_entry in hass.config_entries.async_entries("withings"):
|
for config_entry in hass.config_entries.async_entries("withings"):
|
||||||
await hass.config_entries.async_remove(config_entry.entry_id)
|
await hass.config_entries.async_remove(config_entry.entry_id)
|
||||||
fake_delete_cloudhook.assert_called_once()
|
fake_delete_cloudhook.call_count == 2
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert not hass.config_entries.async_entries(DOMAIN)
|
assert not hass.config_entries.async_entries(DOMAIN)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user