mirror of
https://github.com/elisspace/core.git
synced 2026-10-05 16:56:19 +00:00
Abort webhook flow when not connected to home assistant cloud (#64963)
This commit is contained in:
@@ -114,6 +114,10 @@ class CloudNotAvailable(HomeAssistantError):
|
||||
"""Raised when an action requires the cloud but it's not available."""
|
||||
|
||||
|
||||
class CloudNotConnected(CloudNotAvailable):
|
||||
"""Raised when an action requires the cloud but it's not connected."""
|
||||
|
||||
|
||||
@bind_hass
|
||||
@callback
|
||||
def async_is_logged_in(hass: HomeAssistant) -> bool:
|
||||
@@ -124,6 +128,13 @@ def async_is_logged_in(hass: HomeAssistant) -> bool:
|
||||
return DOMAIN in hass.data and hass.data[DOMAIN].is_logged_in
|
||||
|
||||
|
||||
@bind_hass
|
||||
@callback
|
||||
def async_is_connected(hass: HomeAssistant) -> bool:
|
||||
"""Test if connected to the cloud."""
|
||||
return DOMAIN in hass.data and hass.data[DOMAIN].iot.connected
|
||||
|
||||
|
||||
@bind_hass
|
||||
@callback
|
||||
def async_active_subscription(hass: HomeAssistant) -> bool:
|
||||
@@ -134,6 +145,9 @@ def async_active_subscription(hass: HomeAssistant) -> bool:
|
||||
@bind_hass
|
||||
async def async_create_cloudhook(hass: HomeAssistant, webhook_id: str) -> str:
|
||||
"""Create a cloudhook."""
|
||||
if not async_is_connected(hass):
|
||||
raise CloudNotConnected
|
||||
|
||||
if not async_is_logged_in(hass):
|
||||
raise CloudNotAvailable
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"cloud_not_connected": "[%key:common::config_flow::abort::cloud_not_connected%]",
|
||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
|
||||
"webhook_not_internet_accessible": "[%key:common::config_flow::abort::webhook_not_internet_accessible%]"
|
||||
},
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"cloud_not_connected": "[%key:common::config_flow::abort::cloud_not_connected%]",
|
||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
|
||||
"webhook_not_internet_accessible": "[%key:common::config_flow::abort::webhook_not_internet_accessible%]"
|
||||
},
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"cloud_not_connected": "[%key:common::config_flow::abort::cloud_not_connected%]",
|
||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
|
||||
"webhook_not_internet_accessible": "[%key:common::config_flow::abort::webhook_not_internet_accessible%]"
|
||||
},
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"cloud_not_connected": "[%key:common::config_flow::abort::cloud_not_connected%]",
|
||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
|
||||
"webhook_not_internet_accessible": "[%key:common::config_flow::abort::webhook_not_internet_accessible%]"
|
||||
},
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"cloud_not_connected": "[%key:common::config_flow::abort::cloud_not_connected%]",
|
||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
|
||||
"webhook_not_internet_accessible": "[%key:common::config_flow::abort::webhook_not_internet_accessible%]"
|
||||
},
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"cloud_not_connected": "[%key:common::config_flow::abort::cloud_not_connected%]",
|
||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
|
||||
"webhook_not_internet_accessible": "[%key:common::config_flow::abort::webhook_not_internet_accessible%]"
|
||||
},
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"cloud_not_connected": "[%key:common::config_flow::abort::cloud_not_connected%]",
|
||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
|
||||
"webhook_not_internet_accessible": "[%key:common::config_flow::abort::webhook_not_internet_accessible%]"
|
||||
},
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"cloud_not_connected": "[%key:common::config_flow::abort::cloud_not_connected%]",
|
||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
|
||||
"webhook_not_internet_accessible": "[%key:common::config_flow::abort::webhook_not_internet_accessible%]"
|
||||
},
|
||||
|
||||
@@ -215,6 +215,9 @@ class WebhookFlowHandler(config_entries.ConfigFlow):
|
||||
"cloud" in self.hass.config.components
|
||||
and self.hass.components.cloud.async_active_subscription()
|
||||
):
|
||||
if not self.hass.components.cloud.async_is_connected():
|
||||
return self.async_abort(reason="cloud_not_connected")
|
||||
|
||||
webhook_url = await self.hass.components.cloud.async_create_cloudhook(
|
||||
webhook_id
|
||||
)
|
||||
|
||||
@@ -73,7 +73,8 @@
|
||||
"oauth2_authorize_url_timeout": "Timeout generating authorize URL.",
|
||||
"oauth2_no_url_available": "No URL available. For information about this error, [check the help section]({docs_url})",
|
||||
"reauth_successful": "Re-authentication was successful",
|
||||
"unknown_authorize_url_generation": "Unknown error generating an authorize URL."
|
||||
"unknown_authorize_url_generation": "Unknown error generating an authorize URL.",
|
||||
"cloud_not_connected": "Not connected to Home Assistant Cloud."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user