44from abc import abstractmethod
55from collections .abc import Mapping
66from contextlib import suppress
7+ from copy import deepcopy
78from typing import Any , cast
89import zoneinfo
910
11+ from propcache .api import cached_property
1012import voluptuous as vol
1113
1214from homeassistant .components .binary_sensor import DOMAIN as BS_DOMAIN
1719 ConfigEntryBaseFlow ,
1820 ConfigFlow ,
1921 ConfigFlowResult ,
20- OptionsFlowWithConfigEntry ,
22+ OptionsFlow ,
2123)
2224from homeassistant .const import (
2325 CONF_BINARY_SENSORS ,
@@ -109,27 +111,21 @@ def loc_from_options(
109111class Sun2Flow (ConfigEntryBaseFlow ):
110112 """Sun2 flow mixin."""
111113
112- _existing_entries : list [ConfigEntry ] | None = None
113- _existing_entities : dict [str , str ] | None = None
114+ options : dict [str , Any ]
114115
115116 # Temporary variables between steps.
116117 _use_map : bool
117118 _sunrise_obstruction : bool
118119 _sunset_obstruction : bool
119120
120- @property
121+ @cached_property
121122 def _entries (self ) -> list [ConfigEntry ]:
122123 """Get existing config entries."""
123- if self ._existing_entries is None :
124- self ._existing_entries = self .hass .config_entries .async_entries (DOMAIN )
125- return self ._existing_entries
124+ return self .hass .config_entries .async_entries (DOMAIN )
126125
127- @property
126+ @cached_property
128127 def _entities (self ) -> dict [str , str ]:
129128 """Get existing configured entities."""
130- if self ._existing_entities is not None :
131- return self ._existing_entities
132-
133129 ent_reg = er .async_get (self .hass )
134130 existing_entities : dict [str , str ] = {}
135131 for key , domain in {
@@ -142,14 +138,8 @@ def _entities(self) -> dict[str, str]:
142138 str , ent_reg .async_get_entity_id (domain , DOMAIN , unique_id )
143139 )
144140 existing_entities [entity_id ] = unique_id
145- self ._existing_entities = existing_entities
146141 return existing_entities
147142
148- @property
149- @abstractmethod
150- def options (self ) -> dict [str , Any ]:
151- """Return mutable copy of options."""
152-
153143 def _any_using_ha_loc (self ) -> bool :
154144 """Determine if a config is using Home Assistant location."""
155145 return any (CONF_LATITUDE not in entry .options for entry in self ._entries )
@@ -550,7 +540,7 @@ class Sun2ConfigFlow(ConfigFlow, Sun2Flow, domain=DOMAIN):
550540
551541 def __init__ (self ) -> None :
552542 """Initialize config flow."""
553- self ._options : dict [ str , Any ] = {}
543+ self .options = {}
554544
555545 @staticmethod
556546 @callback
@@ -568,14 +558,7 @@ def async_get_options_flow(config_entry: ConfigEntry) -> Sun2OptionsFlow:
568558 @callback
569559 def async_supports_options_flow (cls , config_entry : ConfigEntry ) -> bool :
570560 """Return options flow support for this handler."""
571- if config_entry .source == SOURCE_IMPORT :
572- return False
573- return True
574-
575- @property
576- def options (self ) -> dict [str , Any ]:
577- """Return mutable copy of options."""
578- return self ._options
561+ return config_entry .source != SOURCE_IMPORT
579562
580563 async def async_step_import (self , data : dict [str , Any ]) -> ConfigFlowResult :
581564 """Import config entry from configuration."""
@@ -658,9 +641,13 @@ async def async_step_done(
658641 )
659642
660643
661- class Sun2OptionsFlow (OptionsFlowWithConfigEntry , Sun2Flow ):
644+ class Sun2OptionsFlow (OptionsFlow , Sun2Flow ):
662645 """Sun2 integration options flow."""
663646
647+ def __init__ (self , config_entry : ConfigEntry ) -> None :
648+ """Initialize flow."""
649+ self .options = deepcopy (dict (config_entry .options ))
650+
664651 async def async_step_done (
665652 self , _ : dict [str , Any ] | None = None
666653 ) -> ConfigFlowResult :
0 commit comments