1 parent
9e8c391c81
commit
d98114d2ab
6 files changed
+33
-9
No files matched your search
@@ -22,7 +22,7 @@ from pysmartthings import (
|
||||
SubscriptionEntity,
|
||||
)
|
||||
|
||||
from homeassistant.components import cloud, webhook
|
||||
from homeassistant.components import webhook
|
||||
from homeassistant.const import CONF_WEBHOOK_ID
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
@@ -88,7 +88,10 @@ async def validate_installed_app(api, installed_app_id: str):
|
||||
|
||||
def validate_webhook_requirements(hass: HomeAssistantType) -> bool:
|
||||
"""Ensure HASS is setup properly to receive webhooks."""
|
||||
if cloud.async_active_subscription(hass):
|
||||
if (
|
||||
"cloud" in hass.config.components
|
||||
and hass.components.cloud.async_active_subscription()
|
||||
):
|
||||
return True
|
||||
if hass.data[DOMAIN][CONF_CLOUDHOOK_URL] is not None:
|
||||
return True
|
||||
@@ -102,7 +105,11 @@ def get_webhook_url(hass: HomeAssistantType) -> str:
|
||||
Return the cloudhook if available, otherwise local webhook.
|
||||
"""
|
||||
cloudhook_url = hass.data[DOMAIN][CONF_CLOUDHOOK_URL]
|
||||
if cloud.async_active_subscription(hass) and cloudhook_url is not None:
|
||||
if (
|
||||
"cloud" in hass.config.components
|
||||
and hass.components.cloud.async_active_subscription()
|
||||
and cloudhook_url is not None
|
||||
):
|
||||
return cloudhook_url
|
||||
return webhook.async_generate_url(hass, hass.data[DOMAIN][CONF_WEBHOOK_ID])
|
||||
|
||||
@@ -222,10 +229,11 @@ async def setup_smartapp_endpoint(hass: HomeAssistantType):
|
||||
cloudhook_url = config.get(CONF_CLOUDHOOK_URL)
|
||||
if (
|
||||
cloudhook_url is None
|
||||
and cloud.async_active_subscription(hass)
|
||||
and "cloud" in hass.config.components
|
||||
and hass.components.cloud.async_active_subscription()
|
||||
and not hass.config_entries.async_entries(DOMAIN)
|
||||
):
|
||||
cloudhook_url = await cloud.async_create_cloudhook(
|
||||
cloudhook_url = await hass.components.cloud.async_create_cloudhook(
|
||||
hass, config[CONF_WEBHOOK_ID]
|
||||
)
|
||||
config[CONF_CLOUDHOOK_URL] = cloudhook_url
|
||||
@@ -273,8 +281,14 @@ async def unload_smartapp_endpoint(hass: HomeAssistantType):
|
||||
return
|
||||
# Remove the cloudhook if it was created
|
||||
cloudhook_url = hass.data[DOMAIN][CONF_CLOUDHOOK_URL]
|
||||
if cloudhook_url and cloud.async_is_logged_in(hass):
|
||||
await cloud.async_delete_cloudhook(hass, hass.data[DOMAIN][CONF_WEBHOOK_ID])
|
||||
if (
|
||||
cloudhook_url
|
||||
and "cloud" in hass.config.components
|
||||
and hass.components.cloud.async_is_logged_in()
|
||||
):
|
||||
await hass.components.cloud.async_delete_cloudhook(
|
||||
hass, hass.data[DOMAIN][CONF_WEBHOOK_ID]
|
||||
)
|
||||
# Remove cloudhook from storage
|
||||
store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY)
|
||||
await store.async_save(
|
||||
|
||||
Reference in new issue
Block a user