mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Abort owntracks config flow when not connected to home assistant cloud (#64968)
This commit is contained in:
parent
664be84121
commit
67838518ab
@ -25,7 +25,10 @@ class OwnTracksFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
if user_input is None:
|
if user_input is None:
|
||||||
return self.async_show_form(step_id="user")
|
return self.async_show_form(step_id="user")
|
||||||
|
|
||||||
|
try:
|
||||||
webhook_id, webhook_url, cloudhook = await self._get_webhook_id()
|
webhook_id, webhook_url, cloudhook = await self._get_webhook_id()
|
||||||
|
except cloud.CloudNotConnected:
|
||||||
|
return self.async_abort(reason="cloud_not_connected")
|
||||||
|
|
||||||
secret = secrets.token_hex(16)
|
secret = secrets.token_hex(16)
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
|
"cloud_not_connected": "[%key:common::config_flow::abort::cloud_not_connected%]",
|
||||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
|
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
|
||||||
},
|
},
|
||||||
"create_entry": {
|
"create_entry": {
|
||||||
|
@ -149,20 +149,48 @@ async def test_unload(hass):
|
|||||||
|
|
||||||
async def test_with_cloud_sub(hass):
|
async def test_with_cloud_sub(hass):
|
||||||
"""Test creating a config flow while subscribed."""
|
"""Test creating a config flow while subscribed."""
|
||||||
hass.config.components.add("cloud")
|
assert await async_setup_component(hass, "cloud", {})
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.cloud.async_active_subscription", return_value=True
|
"homeassistant.components.cloud.async_active_subscription", return_value=True
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.cloud.async_create_cloudhook",
|
"homeassistant.components.cloud.async_is_logged_in", return_value=True
|
||||||
return_value="https://hooks.nabu.casa/ABCD",
|
), 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_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data={}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}, data={}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
entry = result["result"]
|
entry = result["result"]
|
||||||
assert entry.data["cloudhook"]
|
assert entry.data["cloudhook"]
|
||||||
assert (
|
assert (
|
||||||
result["description_placeholders"]["webhook_url"]
|
result["description_placeholders"]["webhook_url"]
|
||||||
== "https://hooks.nabu.casa/ABCD"
|
== "https://hooks.nabu.casa/ABCD"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_with_cloud_sub_not_connected(hass):
|
||||||
|
"""Test creating a config flow while subscribed."""
|
||||||
|
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_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_USER}, data={}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
|
assert result["reason"] == "cloud_not_connected"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user