From 4ef234bc967ec61cca02489a1ff953062905019b Mon Sep 17 00:00:00 2001 From: z-master42 <66380371+z-master42@users.noreply.github.com> Date: Mon, 6 Jan 2025 18:13:10 +0100 Subject: [PATCH 1/4] Optimize OptionsFlow --- custom_components/powercalc/config_flow.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/custom_components/powercalc/config_flow.py b/custom_components/powercalc/config_flow.py index 578ed7603..a96d4edd8 100644 --- a/custom_components/powercalc/config_flow.py +++ b/custom_components/powercalc/config_flow.py @@ -29,6 +29,7 @@ UnitOfEnergy, UnitOfPower, UnitOfTime, + __version__ as HAVERSION, ) from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult @@ -36,6 +37,7 @@ from homeassistant.helpers import selector from homeassistant.helpers.schema_config_entry_flow import SchemaFlowError from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType +from awesomeversion import AwesomeVersion from .common import SourceEntity, create_source_entity from .const import ( @@ -1675,7 +1677,8 @@ class PowercalcOptionsFlow(PowercalcCommonFlow, OptionsFlow): def __init__(self, config_entry: ConfigEntry) -> None: """Initialize options flow.""" super().__init__() - self._config_entry = config_entry + if AwesomeVersion(HAVERSION) < '2024.12': + self.config_entry = config_entry self.sensor_config = dict(config_entry.data) self.sensor_type: SensorType = self.sensor_config.get(CONF_SENSOR_TYPE) or SensorType.VIRTUAL_POWER self.source_entity_id: str = self.sensor_config.get(CONF_ENTITY_ID) # type: ignore @@ -1686,11 +1689,11 @@ async def async_step_init( user_input: dict[str, Any] | None = None, ) -> FlowResult: """Handle options flow.""" - if self._config_entry.unique_id == ENTRY_GLOBAL_CONFIG_UNIQUE_ID: + if self.config_entry.unique_id == ENTRY_GLOBAL_CONFIG_UNIQUE_ID: self.global_config = self.get_global_powercalc_config() return self.async_show_menu(step_id=Step.INIT, menu_options=self.build_global_config_menu()) - self.sensor_config = dict(self._config_entry.data) + self.sensor_config = dict(self.config_entry.data) if self.source_entity_id: self.source_entity = await create_source_entity( self.source_entity_id, @@ -1830,7 +1833,7 @@ async def async_step_real_power(self, user_input: dict[str, Any] | None = None) async def async_step_group_custom(self, user_input: dict[str, Any] | None = None) -> FlowResult: """Handle the group options flow.""" schema = self.fill_schema_defaults( - self.create_schema_group_custom(self._config_entry, True), + self.create_schema_group_custom(self.config_entry, True), self.sensor_config, ) return await self.async_handle_options_step(user_input, schema, Step.GROUP_CUSTOM) @@ -1928,10 +1931,10 @@ async def async_handle_options_step(self, user_input: dict[str, Any] | None, sch def persist_config_entry(self) -> FlowResult: """Persist changed options on the config entry.""" - data = (self._config_entry.unique_id == ENTRY_GLOBAL_CONFIG_UNIQUE_ID and self.global_config) or self.sensor_config + data = (self.config_entry.unique_id == ENTRY_GLOBAL_CONFIG_UNIQUE_ID and self.global_config) or self.sensor_config self.hass.config_entries.async_update_entry( - self._config_entry, + self.config_entry, data=data, ) return self.async_create_entry(title="", data={}) From 205e89f7390a47395581ff997ecf707448a6114d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:18:48 +0000 Subject: [PATCH 2/4] chore(lint): [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- custom_components/powercalc/config_flow.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/custom_components/powercalc/config_flow.py b/custom_components/powercalc/config_flow.py index a96d4edd8..223097b2f 100644 --- a/custom_components/powercalc/config_flow.py +++ b/custom_components/powercalc/config_flow.py @@ -13,6 +13,7 @@ from typing import Any, cast import voluptuous as vol +from awesomeversion import AwesomeVersion from homeassistant.components.sensor import SensorDeviceClass from homeassistant.components.utility_meter import CONF_METER_TYPE, METER_TYPES from homeassistant.config_entries import ConfigEntry, ConfigEntryBaseFlow, ConfigFlow, ConfigFlowResult, OptionsFlow @@ -29,6 +30,8 @@ UnitOfEnergy, UnitOfPower, UnitOfTime, +) +from homeassistant.const import ( __version__ as HAVERSION, ) from homeassistant.core import callback @@ -37,7 +40,6 @@ from homeassistant.helpers import selector from homeassistant.helpers.schema_config_entry_flow import SchemaFlowError from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from awesomeversion import AwesomeVersion from .common import SourceEntity, create_source_entity from .const import ( @@ -1677,7 +1679,7 @@ class PowercalcOptionsFlow(PowercalcCommonFlow, OptionsFlow): def __init__(self, config_entry: ConfigEntry) -> None: """Initialize options flow.""" super().__init__() - if AwesomeVersion(HAVERSION) < '2024.12': + if AwesomeVersion(HAVERSION) < "2024.12": self.config_entry = config_entry self.sensor_config = dict(config_entry.data) self.sensor_type: SensorType = self.sensor_config.get(CONF_SENSOR_TYPE) or SensorType.VIRTUAL_POWER From 51f70aabf1e1e66c656b02b3bf1bbd95348d9ea9 Mon Sep 17 00:00:00 2001 From: z-master42 <66380371+z-master42@users.noreply.github.com> Date: Mon, 6 Jan 2025 18:42:37 +0100 Subject: [PATCH 3/4] Optimize OptionsFlow --- custom_components/powercalc/config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/powercalc/config_flow.py b/custom_components/powercalc/config_flow.py index 223097b2f..170a3f17b 100644 --- a/custom_components/powercalc/config_flow.py +++ b/custom_components/powercalc/config_flow.py @@ -32,7 +32,7 @@ UnitOfTime, ) from homeassistant.const import ( - __version__ as HAVERSION, + __version__ as HAVERSION, #noqa ) from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult From fc21b95d625c51abc672f545ad32e3c531dba47a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:42:47 +0000 Subject: [PATCH 4/4] chore(lint): [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- custom_components/powercalc/config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/powercalc/config_flow.py b/custom_components/powercalc/config_flow.py index 170a3f17b..cf17159c7 100644 --- a/custom_components/powercalc/config_flow.py +++ b/custom_components/powercalc/config_flow.py @@ -32,7 +32,7 @@ UnitOfTime, ) from homeassistant.const import ( - __version__ as HAVERSION, #noqa + __version__ as HAVERSION, # noqa ) from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult