Skip to content

Commit e7ccf54

Browse files
committed
refactor(configflow): replace deprecated method to init the OptionsFlowHandler
1 parent 49abc79 commit e7ccf54

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

custom_components/tarif_edf/config_flow.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def async_get_options_flow(
6060
config_entry: config_entries.ConfigEntry,
6161
) -> config_entries.OptionsFlow:
6262
"""Create the options flow."""
63-
return OptionsFlowHandler(config_entry)
63+
return OptionsFlowHandler(config_entry.entry_id)
6464

6565
class CannotConnect(HomeAssistantError):
6666
"""Error to indicate we cannot connect."""
@@ -70,9 +70,9 @@ class InvalidAuth(HomeAssistantError):
7070
"""Error to indicate there is invalid auth."""
7171

7272
class OptionsFlowHandler(config_entries.OptionsFlow):
73-
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
73+
def __init__(self, config_entry_id: str) -> None:
7474
"""Initialize options flow."""
75-
self.config_entry = config_entry
75+
self.config_entry_id = config_entry_id
7676

7777
async def async_step_init(
7878
self, user_input: dict[str, Any] | None = None
@@ -81,16 +81,18 @@ async def async_step_init(
8181
if user_input is not None:
8282
return self.async_create_entry(title="", data=user_input)
8383

84+
config_entry = self.hass.config_entries.async_get_entry(self.config_entry_id)
85+
8486
default_offpeak_hours = None
85-
if self.config_entry.data['contract_type'] == CONTRACT_TYPE_TEMPO:
87+
if config_entry.data['contract_type'] == CONTRACT_TYPE_TEMPO:
8688
default_offpeak_hours = TEMPO_OFFPEAK_HOURS
8789

8890
return self.async_show_form(
8991
step_id="init",
9092
data_schema=vol.Schema(
9193
{
92-
vol.Optional("refresh_interval", default=self.config_entry.options.get("refresh_interval", DEFAULT_REFRESH_INTERVAL)): int,
93-
vol.Optional("off_peak_hours_ranges", default=self.config_entry.options.get("off_peak_hours_ranges", default_offpeak_hours)): str,
94+
vol.Optional("refresh_interval", default=config_entry.options.get("refresh_interval", DEFAULT_REFRESH_INTERVAL)): int,
95+
vol.Optional("off_peak_hours_ranges", default=config_entry.options.get("off_peak_hours_ranges", default_offpeak_hours)): str,
9496
}
9597
),
9698
)

0 commit comments

Comments
 (0)