Skip to content

Commit 7c84292

Browse files
committed
Drop support for HA versions before 2024.12.0
1 parent 4a4d526 commit 7c84292

File tree

5 files changed

+20
-43
lines changed

5 files changed

+20
-43
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ After it has been downloaded you will need to restart Home Assistant.
4444

4545
### Versions
4646

47-
This custom integration supports HomeAssistant versions 2024.8.3 or newer.
47+
This custom integration supports HomeAssistant versions 2024.12.0 or newer.
4848

4949
## Services
5050

custom_components/sun2/config_flow.py

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
from abc import abstractmethod
55
from collections.abc import Mapping
66
from contextlib import suppress
7+
from copy import deepcopy
78
from typing import Any, cast
89
import zoneinfo
910

11+
from propcache.api import cached_property
1012
import voluptuous as vol
1113

1214
from homeassistant.components.binary_sensor import DOMAIN as BS_DOMAIN
@@ -17,7 +19,7 @@
1719
ConfigEntryBaseFlow,
1820
ConfigFlow,
1921
ConfigFlowResult,
20-
OptionsFlowWithConfigEntry,
22+
OptionsFlow,
2123
)
2224
from homeassistant.const import (
2325
CONF_BINARY_SENSORS,
@@ -109,27 +111,21 @@ def loc_from_options(
109111
class 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:

custom_components/sun2/helpers.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@
66
from contextlib import suppress
77
from dataclasses import dataclass, field
88
from datetime import date, datetime, time, timedelta, tzinfo
9-
from functools import ( # pylint: disable=hass-deprecated-import
10-
cached_property,
11-
lru_cache,
12-
partial,
13-
)
9+
from functools import lru_cache, partial
1410
from math import copysign, fabs
1511
from typing import Any, Self, cast
1612

1713
from astral import LocationInfo, SunDirection
1814
from astral.location import Location
1915
from astral.sun import adjust_to_horizon, adjust_to_obscuring_feature
16+
from propcache.api import cached_property
2017

2118
from homeassistant.components.binary_sensor import (
2219
DOMAIN as BS_DOMAIN,
@@ -31,14 +28,7 @@
3128
CONF_TIME_ZONE,
3229
)
3330
from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, callback
34-
35-
# Config moved from core to core_config in 2024.11
36-
37-
try:
38-
from homeassistant.core_config import Config
39-
except ImportError:
40-
from homeassistant.core import Config # type: ignore[no-redef]
41-
31+
from homeassistant.core_config import Config
4232
from homeassistant.helpers import device_registry as dr, entity_registry as er
4333
from homeassistant.helpers.dispatcher import async_dispatcher_connect
4434
from homeassistant.helpers.entity import Entity

custom_components/sun2/sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from contextlib import suppress
88
from dataclasses import asdict, dataclass, make_dataclass
99
from datetime import date, datetime, time, timedelta
10-
from functools import cached_property # pylint: disable=hass-deprecated-import
1110
from itertools import chain
1211
from math import fabs
1312
from typing import Any, Generic, TypeVar, cast
1413

1514
from astral import SunDirection
1615
from astral.sun import SUN_APPARENT_RADIUS
16+
from propcache.api import cached_property
1717

1818
from homeassistant.components.sensor import (
1919
SensorDeviceClass,

hacs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"name": "Sun2",
3-
"homeassistant": "2024.8.3"
3+
"homeassistant": "2024.12.0"
44
}

0 commit comments

Comments
 (0)