mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Remove 'tariff' edition from options-flow (#85703)
* 🎨 Add missing typing for config-flow * 🐛 Remove 'tariff' edition from options-flow The `entry.data["tariff"]` is what makes the `entry.unique_id`, so it's an incoherence to be able to change it in the Options flow * 🌐 Update generated EN translation * 🎨 Link translations of option-flow to those of config-flow
This commit is contained in:
parent
ae302bbec0
commit
d748894b88
@ -52,7 +52,7 @@ async def async_update_options(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|||||||
"""Handle options update."""
|
"""Handle options update."""
|
||||||
if any(
|
if any(
|
||||||
entry.data.get(attrib) != entry.options.get(attrib)
|
entry.data.get(attrib) != entry.options.get(attrib)
|
||||||
for attrib in (ATTR_TARIFF, ATTR_POWER, ATTR_POWER_P3)
|
for attrib in (ATTR_POWER, ATTR_POWER_P3)
|
||||||
):
|
):
|
||||||
# update entry replacing data with new options
|
# update entry replacing data with new options
|
||||||
hass.config_entries.async_update_entry(
|
hass.config_entries.async_update_entry(
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
"""Config flow for pvpc_hourly_pricing."""
|
"""Config flow for pvpc_hourly_pricing."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
from . import CONF_NAME, UI_CONFIG_SCHEMA, VALID_POWER, VALID_TARIFF
|
from . import CONF_NAME, UI_CONFIG_SCHEMA, VALID_POWER
|
||||||
from .const import ATTR_POWER, ATTR_POWER_P3, ATTR_TARIFF, DOMAIN
|
from .const import ATTR_POWER, ATTR_POWER_P3, ATTR_TARIFF, DOMAIN
|
||||||
|
|
||||||
|
|
||||||
@ -23,7 +26,9 @@ class TariffSelectorConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
"""Get the options flow for this handler."""
|
"""Get the options flow for this handler."""
|
||||||
return PVPCOptionsFlowHandler(config_entry)
|
return PVPCOptionsFlowHandler(config_entry)
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
await self.async_set_unique_id(user_input[ATTR_TARIFF])
|
await self.async_set_unique_id(user_input[ATTR_TARIFF])
|
||||||
@ -40,15 +45,14 @@ class PVPCOptionsFlowHandler(config_entries.OptionsFlow):
|
|||||||
"""Initialize options flow."""
|
"""Initialize options flow."""
|
||||||
self.config_entry = config_entry
|
self.config_entry = config_entry
|
||||||
|
|
||||||
async def async_step_init(self, user_input=None):
|
async def async_step_init(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Manage the options."""
|
"""Manage the options."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return self.async_create_entry(title="", data=user_input)
|
return self.async_create_entry(title="", data=user_input)
|
||||||
|
|
||||||
# Fill options with entry data
|
# Fill options with entry data
|
||||||
tariff = self.config_entry.options.get(
|
|
||||||
ATTR_TARIFF, self.config_entry.data[ATTR_TARIFF]
|
|
||||||
)
|
|
||||||
power = self.config_entry.options.get(
|
power = self.config_entry.options.get(
|
||||||
ATTR_POWER, self.config_entry.data[ATTR_POWER]
|
ATTR_POWER, self.config_entry.data[ATTR_POWER]
|
||||||
)
|
)
|
||||||
@ -57,7 +61,6 @@ class PVPCOptionsFlowHandler(config_entries.OptionsFlow):
|
|||||||
)
|
)
|
||||||
schema = vol.Schema(
|
schema = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(ATTR_TARIFF, default=tariff): VALID_TARIFF,
|
|
||||||
vol.Required(ATTR_POWER, default=power): VALID_POWER,
|
vol.Required(ATTR_POWER, default=power): VALID_POWER,
|
||||||
vol.Required(ATTR_POWER_P3, default=power_valley): VALID_POWER,
|
vol.Required(ATTR_POWER_P3, default=power_valley): VALID_POWER,
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,8 @@
|
|||||||
"step": {
|
"step": {
|
||||||
"init": {
|
"init": {
|
||||||
"data": {
|
"data": {
|
||||||
"tariff": "Applicable tariff by geographic zone",
|
"power": "[%key:component::pvpc_hourly_pricing::config::step::user::data::power%]",
|
||||||
"power": "Contracted power (kW)",
|
"power_p3": "[%key:component::pvpc_hourly_pricing::config::step::user::data::power_p3%]"
|
||||||
"power_p3": "Contracted power for valley period P3 (kW)"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,7 @@
|
|||||||
"init": {
|
"init": {
|
||||||
"data": {
|
"data": {
|
||||||
"power": "Contracted power (kW)",
|
"power": "Contracted power (kW)",
|
||||||
"power_p3": "Contracted power for valley period P3 (kW)",
|
"power_p3": "Contracted power for valley period P3 (kW)"
|
||||||
"tariff": "Applicable tariff by geographic zone"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,11 +102,11 @@ async def test_config_flow(hass, pvpc_aioclient_mock: AiohttpClientMocker):
|
|||||||
|
|
||||||
result = await hass.config_entries.options.async_configure(
|
result = await hass.config_entries.options.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input={ATTR_TARIFF: TARIFFS[0], ATTR_POWER: 3.0, ATTR_POWER_P3: 4.6},
|
user_input={ATTR_POWER: 3.0, ATTR_POWER_P3: 4.6},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("sensor.test")
|
state = hass.states.get("sensor.test")
|
||||||
check_valid_state(state, tariff=TARIFFS[0])
|
check_valid_state(state, tariff=TARIFFS[1])
|
||||||
assert pvpc_aioclient_mock.call_count == 3
|
assert pvpc_aioclient_mock.call_count == 3
|
||||||
assert state.attributes["period"] == "P3"
|
assert state.attributes["period"] == "P3"
|
||||||
assert state.attributes["next_period"] == "P2"
|
assert state.attributes["next_period"] == "P2"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user