mirror of
https://github.com/home-assistant/core.git
synced 2025-08-30 01:42:21 +02:00
Use OptionsFlowWithReload in pvpc_hourly_pricing
This commit is contained in:
@@ -4,7 +4,6 @@ from homeassistant.const import CONF_API_TOKEN, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .const import ATTR_POWER, ATTR_POWER_P3
|
||||
from .coordinator import ElecPricesDataUpdateCoordinator, PVPCConfigEntry
|
||||
from .helpers import get_enabled_sensor_keys
|
||||
|
||||
@@ -23,23 +22,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: PVPCConfigEntry) -> bool
|
||||
|
||||
entry.runtime_data = coordinator
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
entry.async_on_unload(entry.add_update_listener(async_update_options))
|
||||
return True
|
||||
|
||||
|
||||
async def async_update_options(hass: HomeAssistant, entry: PVPCConfigEntry) -> None:
|
||||
"""Handle options update."""
|
||||
if any(
|
||||
entry.data.get(attrib) != entry.options.get(attrib)
|
||||
for attrib in (ATTR_POWER, ATTR_POWER_P3, CONF_API_TOKEN)
|
||||
):
|
||||
# update entry replacing data with new options
|
||||
hass.config_entries.async_update_entry(
|
||||
entry, data={**entry.data, **entry.options}
|
||||
)
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: PVPCConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
@@ -13,7 +13,7 @@ from homeassistant.config_entries import (
|
||||
ConfigEntry,
|
||||
ConfigFlow,
|
||||
ConfigFlowResult,
|
||||
OptionsFlow,
|
||||
OptionsFlowWithReload,
|
||||
)
|
||||
from homeassistant.const import CONF_API_TOKEN, CONF_NAME
|
||||
from homeassistant.core import callback
|
||||
@@ -178,7 +178,7 @@ class TariffSelectorConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
return self.async_show_form(step_id="reauth_confirm", data_schema=data_schema)
|
||||
|
||||
|
||||
class PVPCOptionsFlowHandler(OptionsFlow):
|
||||
class PVPCOptionsFlowHandler(OptionsFlowWithReload):
|
||||
"""Handle PVPC options."""
|
||||
|
||||
_power: float | None = None
|
||||
|
@@ -29,13 +29,16 @@ class ElecPricesDataUpdateCoordinator(DataUpdateCoordinator[EsiosApiData]):
|
||||
self, hass: HomeAssistant, entry: PVPCConfigEntry, sensor_keys: set[str]
|
||||
) -> None:
|
||||
"""Initialize."""
|
||||
config = entry.data.copy()
|
||||
config.update({attr: value for attr, value in entry.options.items() if value})
|
||||
|
||||
self.api = PVPCData(
|
||||
session=async_get_clientsession(hass),
|
||||
tariff=entry.data[ATTR_TARIFF],
|
||||
tariff=config[ATTR_TARIFF],
|
||||
local_timezone=hass.config.time_zone,
|
||||
power=entry.data[ATTR_POWER],
|
||||
power_valley=entry.data[ATTR_POWER_P3],
|
||||
api_token=entry.data.get(CONF_API_TOKEN),
|
||||
power=config[ATTR_POWER],
|
||||
power_valley=config[ATTR_POWER_P3],
|
||||
api_token=config.get(CONF_API_TOKEN),
|
||||
sensor_keys=tuple(sensor_keys),
|
||||
)
|
||||
super().__init__(
|
||||
|
@@ -121,7 +121,6 @@ async def test_config_flow(
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "api_token"
|
||||
assert pvpc_aioclient_mock.call_count == 2
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], user_input={CONF_API_TOKEN: "test-token"}
|
||||
)
|
||||
|
Reference in New Issue
Block a user