mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Add reconfigure step to tedee (#122008)
* Add reconfigure to tedee * assert data update * add rconfigure_confirm to strings * Update integration name --------- Co-authored-by: G Johansson <goran.johansson@shiftit.se>
This commit is contained in:
parent
f551130d65
commit
02bb1ec8e7
@ -30,6 +30,7 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
MINOR_VERSION = 2
|
||||
|
||||
reauth_entry: ConfigEntry | None = None
|
||||
reconfigure_entry: ConfigEntry | None = None
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
@ -59,14 +60,17 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
errors["base"] = "cannot_connect"
|
||||
else:
|
||||
if self.reauth_entry:
|
||||
self.hass.config_entries.async_update_entry(
|
||||
return self.async_update_reload_and_abort(
|
||||
self.reauth_entry,
|
||||
data={**self.reauth_entry.data, **user_input},
|
||||
reason="reauth_successful",
|
||||
)
|
||||
await self.hass.config_entries.async_reload(
|
||||
self.context["entry_id"]
|
||||
if self.reconfigure_entry:
|
||||
return self.async_update_reload_and_abort(
|
||||
self.reconfigure_entry,
|
||||
data={**self.reconfigure_entry.data, **user_input},
|
||||
reason="reconfigure_successful",
|
||||
)
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
await self.async_set_unique_id(local_bridge.serial)
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_create_entry(
|
||||
@ -117,3 +121,37 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
),
|
||||
)
|
||||
return await self.async_step_user(user_input)
|
||||
|
||||
async def async_step_reconfigure(
|
||||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Perform a reconfiguration."""
|
||||
self.reconfigure_entry = self.hass.config_entries.async_get_entry(
|
||||
self.context["entry_id"]
|
||||
)
|
||||
return await self.async_step_reconfigure_confirm()
|
||||
|
||||
async def async_step_reconfigure_confirm(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Add reconfigure step to allow to reconfigure a config entry."""
|
||||
assert self.reconfigure_entry
|
||||
|
||||
if not user_input:
|
||||
return self.async_show_form(
|
||||
step_id="reconfigure_confirm",
|
||||
data_schema=vol.Schema(
|
||||
{
|
||||
vol.Required(
|
||||
CONF_HOST, default=self.reconfigure_entry.data[CONF_HOST]
|
||||
): str,
|
||||
vol.Required(
|
||||
CONF_LOCAL_ACCESS_TOKEN,
|
||||
default=self.reconfigure_entry.data[
|
||||
CONF_LOCAL_ACCESS_TOKEN
|
||||
],
|
||||
): str,
|
||||
}
|
||||
),
|
||||
)
|
||||
return await self.async_step_user(user_input)
|
||||
|
@ -21,11 +21,24 @@
|
||||
"data_description": {
|
||||
"local_access_token": "[%key:component::tedee::config::step::user::data_description::local_access_token%]"
|
||||
}
|
||||
},
|
||||
"reconfigure_confirm": {
|
||||
"title": "Reconfigure Tedee",
|
||||
"description": "Update the settings of this integration.",
|
||||
"data": {
|
||||
"host": "[%key:common::config_flow::data::host%]",
|
||||
"local_access_token": "[%key:component::tedee::config::step::user::data::local_access_token%]"
|
||||
},
|
||||
"data_description": {
|
||||
"host": "[%key:component::tedee::config::step::user::data_description::host%]",
|
||||
"local_access_token": "[%key:component::tedee::config::step::user::data_description::local_access_token%]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
|
||||
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]",
|
||||
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]"
|
||||
},
|
||||
"error": {
|
||||
"invalid_api_key": "[%key:common::config_flow::error::invalid_api_key%]",
|
||||
|
@ -10,7 +10,7 @@ from pytedee_async import (
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.tedee.const import CONF_LOCAL_ACCESS_TOKEN, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_RECONFIGURE, SOURCE_USER
|
||||
from homeassistant.const import CONF_HOST, CONF_WEBHOOK_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
@ -143,3 +143,44 @@ async def test_reauth_flow(
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reauth_successful"
|
||||
|
||||
|
||||
async def test_reconfigure_flow(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_tedee: MagicMock
|
||||
) -> None:
|
||||
"""Test that the reconfigure flow works."""
|
||||
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
reconfigure_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={
|
||||
"source": SOURCE_RECONFIGURE,
|
||||
"unique_id": mock_config_entry.unique_id,
|
||||
"entry_id": mock_config_entry.entry_id,
|
||||
},
|
||||
data={
|
||||
CONF_LOCAL_ACCESS_TOKEN: LOCAL_ACCESS_TOKEN,
|
||||
CONF_HOST: "192.168.1.42",
|
||||
},
|
||||
)
|
||||
|
||||
assert reconfigure_result["type"] is FlowResultType.FORM
|
||||
assert reconfigure_result["step_id"] == "reconfigure_confirm"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
reconfigure_result["flow_id"],
|
||||
{CONF_LOCAL_ACCESS_TOKEN: LOCAL_ACCESS_TOKEN, CONF_HOST: "192.168.1.43"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
|
||||
entry = hass.config_entries.async_get_entry(mock_config_entry.entry_id)
|
||||
assert entry
|
||||
assert entry.title == "My Tedee"
|
||||
assert entry.data == {
|
||||
CONF_HOST: "192.168.1.43",
|
||||
CONF_LOCAL_ACCESS_TOKEN: LOCAL_ACCESS_TOKEN,
|
||||
CONF_WEBHOOK_ID: WEBHOOK_ID,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user