Skip to content

Commit d748894

Browse files
authored
Remove 'tariff' edition from options-flow (home-assistant#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
1 parent ae302bb commit d748894

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

homeassistant/components/pvpc_hourly_pricing/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async def async_update_options(hass: HomeAssistant, entry: ConfigEntry) -> None:
5252
"""Handle options update."""
5353
if any(
5454
entry.data.get(attrib) != entry.options.get(attrib)
55-
for attrib in (ATTR_TARIFF, ATTR_POWER, ATTR_POWER_P3)
55+
for attrib in (ATTR_POWER, ATTR_POWER_P3)
5656
):
5757
# update entry replacing data with new options
5858
hass.config_entries.async_update_entry(

homeassistant/components/pvpc_hourly_pricing/config_flow.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
"""Config flow for pvpc_hourly_pricing."""
22
from __future__ import annotations
33

4+
from typing import Any
5+
46
import voluptuous as vol
57

68
from homeassistant import config_entries
79
from homeassistant.core import callback
10+
from homeassistant.data_entry_flow import FlowResult
811

9-
from . import CONF_NAME, UI_CONFIG_SCHEMA, VALID_POWER, VALID_TARIFF
12+
from . import CONF_NAME, UI_CONFIG_SCHEMA, VALID_POWER
1013
from .const import ATTR_POWER, ATTR_POWER_P3, ATTR_TARIFF, DOMAIN
1114

1215

@@ -23,7 +26,9 @@ def async_get_options_flow(
2326
"""Get the options flow for this handler."""
2427
return PVPCOptionsFlowHandler(config_entry)
2528

26-
async def async_step_user(self, user_input=None):
29+
async def async_step_user(
30+
self, user_input: dict[str, Any] | None = None
31+
) -> FlowResult:
2732
"""Handle the initial step."""
2833
if user_input is not None:
2934
await self.async_set_unique_id(user_input[ATTR_TARIFF])
@@ -40,15 +45,14 @@ def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
4045
"""Initialize options flow."""
4146
self.config_entry = config_entry
4247

43-
async def async_step_init(self, user_input=None):
48+
async def async_step_init(
49+
self, user_input: dict[str, Any] | None = None
50+
) -> FlowResult:
4451
"""Manage the options."""
4552
if user_input is not None:
4653
return self.async_create_entry(title="", data=user_input)
4754

4855
# Fill options with entry data
49-
tariff = self.config_entry.options.get(
50-
ATTR_TARIFF, self.config_entry.data[ATTR_TARIFF]
51-
)
5256
power = self.config_entry.options.get(
5357
ATTR_POWER, self.config_entry.data[ATTR_POWER]
5458
)
@@ -57,7 +61,6 @@ async def async_step_init(self, user_input=None):
5761
)
5862
schema = vol.Schema(
5963
{
60-
vol.Required(ATTR_TARIFF, default=tariff): VALID_TARIFF,
6164
vol.Required(ATTR_POWER, default=power): VALID_POWER,
6265
vol.Required(ATTR_POWER_P3, default=power_valley): VALID_POWER,
6366
}

homeassistant/components/pvpc_hourly_pricing/strings.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
"step": {
1919
"init": {
2020
"data": {
21-
"tariff": "Applicable tariff by geographic zone",
22-
"power": "Contracted power (kW)",
23-
"power_p3": "Contracted power for valley period P3 (kW)"
21+
"power": "[%key:component::pvpc_hourly_pricing::config::step::user::data::power%]",
22+
"power_p3": "[%key:component::pvpc_hourly_pricing::config::step::user::data::power_p3%]"
2423
}
2524
}
2625
}

homeassistant/components/pvpc_hourly_pricing/translations/en.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
"init": {
2020
"data": {
2121
"power": "Contracted power (kW)",
22-
"power_p3": "Contracted power for valley period P3 (kW)",
23-
"tariff": "Applicable tariff by geographic zone"
22+
"power_p3": "Contracted power for valley period P3 (kW)"
2423
}
2524
}
2625
}

tests/components/pvpc_hourly_pricing/test_config_flow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ async def test_config_flow(hass, pvpc_aioclient_mock: AiohttpClientMocker):
102102

103103
result = await hass.config_entries.options.async_configure(
104104
result["flow_id"],
105-
user_input={ATTR_TARIFF: TARIFFS[0], ATTR_POWER: 3.0, ATTR_POWER_P3: 4.6},
105+
user_input={ATTR_POWER: 3.0, ATTR_POWER_P3: 4.6},
106106
)
107107
await hass.async_block_till_done()
108108
state = hass.states.get("sensor.test")
109-
check_valid_state(state, tariff=TARIFFS[0])
109+
check_valid_state(state, tariff=TARIFFS[1])
110110
assert pvpc_aioclient_mock.call_count == 3
111111
assert state.attributes["period"] == "P3"
112112
assert state.attributes["next_period"] == "P2"

0 commit comments

Comments
 (0)