mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Abort plaato flows when not connected to home assistant cloud (#64969)
This commit is contained in:
parent
5071b3b959
commit
664be84121
@ -85,7 +85,10 @@ class PlaatoConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
use_webhook = self._init_info[CONF_USE_WEBHOOK]
|
||||
|
||||
if use_webhook and user_input is None:
|
||||
try:
|
||||
webhook_id, webhook_url, cloudhook = await self._get_webhook_id()
|
||||
except cloud.CloudNotConnected:
|
||||
return self.async_abort(reason="cloud_not_connected")
|
||||
self._init_info[CONF_WEBHOOK_ID] = webhook_id
|
||||
self._init_info[CONF_CLOUDHOOK] = cloudhook
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
"no_api_method": "You need to add an auth token or select webhook"
|
||||
},
|
||||
"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%]",
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]"
|
||||
|
@ -12,7 +12,12 @@ from homeassistant.components.plaato.const import (
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.const import CONF_SCAN_INTERVAL, CONF_TOKEN, CONF_WEBHOOK_ID
|
||||
from homeassistant.data_entry_flow import RESULT_TYPE_CREATE_ENTRY, RESULT_TYPE_FORM
|
||||
from homeassistant.data_entry_flow import (
|
||||
RESULT_TYPE_ABORT,
|
||||
RESULT_TYPE_CREATE_ENTRY,
|
||||
RESULT_TYPE_FORM,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@ -95,12 +100,16 @@ async def test_show_config_form_validate_webhook(hass, webhook_id):
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "api_method"
|
||||
|
||||
hass.config.components.add("cloud")
|
||||
assert await async_setup_component(hass, "cloud", {})
|
||||
with patch(
|
||||
"homeassistant.components.cloud.async_active_subscription", return_value=True
|
||||
), patch(
|
||||
"homeassistant.components.cloud.async_create_cloudhook",
|
||||
return_value="https://hooks.nabu.casa/ABCD",
|
||||
"homeassistant.components.cloud.async_is_logged_in", return_value=True
|
||||
), patch(
|
||||
"homeassistant.components.cloud.async_is_connected", return_value=True
|
||||
), patch(
|
||||
"hass_nabucasa.cloudhooks.Cloudhooks.async_create",
|
||||
return_value={"cloudhook_url": "https://hooks.nabu.casa/ABCD"},
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
@ -114,6 +123,50 @@ async def test_show_config_form_validate_webhook(hass, webhook_id):
|
||||
assert result["step_id"] == "webhook"
|
||||
|
||||
|
||||
async def test_show_config_form_validate_webhook_not_connected(hass, webhook_id):
|
||||
"""Test validating webhook when not connected aborts."""
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_DEVICE_TYPE: PlaatoDeviceType.Airlock,
|
||||
CONF_DEVICE_NAME: "device_name",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "api_method"
|
||||
|
||||
assert await async_setup_component(hass, "cloud", {})
|
||||
with patch(
|
||||
"homeassistant.components.cloud.async_active_subscription", return_value=True
|
||||
), patch(
|
||||
"homeassistant.components.cloud.async_is_logged_in", return_value=True
|
||||
), patch(
|
||||
"homeassistant.components.cloud.async_is_connected", return_value=False
|
||||
), patch(
|
||||
"hass_nabucasa.cloudhooks.Cloudhooks.async_create",
|
||||
return_value={"cloudhook_url": "https://hooks.nabu.casa/ABCD"},
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_TOKEN: "",
|
||||
CONF_USE_WEBHOOK: True,
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "cloud_not_connected"
|
||||
|
||||
|
||||
async def test_show_config_form_validate_token(hass):
|
||||
"""Test show configuration form."""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user