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:
Eugenio Panadero 2023-01-13 13:27:11 +01:00 committed by GitHub
parent ae302bbec0
commit d748894b88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 15 deletions

View file

@ -52,7 +52,7 @@ async def async_update_options(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update."""
if any(
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
hass.config_entries.async_update_entry(

View file

@ -1,12 +1,15 @@
"""Config flow for pvpc_hourly_pricing."""
from __future__ import annotations
from typing import Any
import voluptuous as vol
from homeassistant import config_entries
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
@ -23,7 +26,9 @@ class TariffSelectorConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Get the options flow for this handler."""
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."""
if user_input is not None:
await self.async_set_unique_id(user_input[ATTR_TARIFF])
@ -40,15 +45,14 @@ class PVPCOptionsFlowHandler(config_entries.OptionsFlow):
"""Initialize options flow."""
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."""
if user_input is not None:
return self.async_create_entry(title="", data=user_input)
# 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(
ATTR_POWER, self.config_entry.data[ATTR_POWER]
)
@ -57,7 +61,6 @@ class PVPCOptionsFlowHandler(config_entries.OptionsFlow):
)
schema = vol.Schema(
{
vol.Required(ATTR_TARIFF, default=tariff): VALID_TARIFF,
vol.Required(ATTR_POWER, default=power): VALID_POWER,
vol.Required(ATTR_POWER_P3, default=power_valley): VALID_POWER,
}

View file

@ -18,9 +18,8 @@
"step": {
"init": {
"data": {
"tariff": "Applicable tariff by geographic zone",
"power": "Contracted power (kW)",
"power_p3": "Contracted power for valley period P3 (kW)"
"power": "[%key:component::pvpc_hourly_pricing::config::step::user::data::power%]",
"power_p3": "[%key:component::pvpc_hourly_pricing::config::step::user::data::power_p3%]"
}
}
}

View file

@ -19,8 +19,7 @@
"init": {
"data": {
"power": "Contracted power (kW)",
"power_p3": "Contracted power for valley period P3 (kW)",
"tariff": "Applicable tariff by geographic zone"
"power_p3": "Contracted power for valley period P3 (kW)"
}
}
}

View file

@ -102,11 +102,11 @@ async def test_config_flow(hass, pvpc_aioclient_mock: AiohttpClientMocker):
result = await hass.config_entries.options.async_configure(
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()
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 state.attributes["period"] == "P3"
assert state.attributes["next_period"] == "P2"