From 510da8f070edbc0f621eda00875416072a818ec7 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 2 Oct 2024 11:37:56 -0500 Subject: [PATCH 1/6] Switch to using fast cached_property implementation in propcache propcache is derived from yarl which uses an accelerated cached_property implementation. It also has an under_cached_property implementation which stores the cache in self._cache which is compatiblity with __slots__ which will allow use to restore __slots__ to many objects that we had to remove it from to allow for the stdlib @cached_property which does not support __slots__ Currently yarl and aiohttp both implement the same property caching code and cython code. The goal of the propcache library is to replace both implementations in yarl and aiohttp and maintain it in a single place in aiohttp 3.11 propcache is expected to replace the internal yarl and aiohttp implementations. --- homeassistant/auth/models.py | 2 +- homeassistant/backports/functools.py | 4 +++- homeassistant/components/airgradient/update.py | 3 ++- homeassistant/components/alarm_control_panel/__init__.py | 3 ++- homeassistant/components/automation/__init__.py | 3 ++- homeassistant/components/binary_sensor/__init__.py | 3 ++- homeassistant/components/button/__init__.py | 2 +- homeassistant/components/camera/__init__.py | 3 ++- homeassistant/components/climate/__init__.py | 2 +- homeassistant/components/cover/__init__.py | 2 +- homeassistant/components/date/__init__.py | 6 +++--- homeassistant/components/datetime/__init__.py | 6 +++--- homeassistant/components/device_tracker/config_entry.py | 3 ++- homeassistant/components/device_tracker/legacy.py | 2 +- homeassistant/components/dlna_dms/dms.py | 2 +- homeassistant/components/doorbird/device.py | 2 +- homeassistant/components/event/__init__.py | 3 ++- homeassistant/components/fan/__init__.py | 2 +- homeassistant/components/ffmpeg/__init__.py | 2 +- homeassistant/components/fints/sensor.py | 2 +- homeassistant/components/frontend/__init__.py | 3 ++- homeassistant/components/geo_location/__init__.py | 3 ++- homeassistant/components/homekit_controller/climate.py | 2 +- homeassistant/components/homekit_controller/cover.py | 2 +- homeassistant/components/homekit_controller/fan.py | 2 +- homeassistant/components/homekit_controller/humidifier.py | 2 +- homeassistant/components/homekit_controller/light.py | 2 +- homeassistant/components/humidifier/__init__.py | 3 ++- homeassistant/components/image/__init__.py | 2 +- homeassistant/components/intent/timers.py | 2 +- homeassistant/components/lawn_mower/__init__.py | 3 ++- homeassistant/components/lifx/coordinator.py | 3 ++- homeassistant/components/light/__init__.py | 2 +- homeassistant/components/lock/__init__.py | 2 +- homeassistant/components/logbook/models.py | 2 +- homeassistant/components/matter/entity.py | 2 +- homeassistant/components/media_player/__init__.py | 3 ++- homeassistant/components/nibe_heatpump/coordinator.py | 2 +- homeassistant/components/notify/__init__.py | 3 ++- homeassistant/components/number/__init__.py | 2 +- .../overkiz/climate/atlantic_pass_apc_zone_control_zone.py | 2 +- homeassistant/components/rainbird/coordinator.py | 2 +- homeassistant/components/recorder/core.py | 2 +- homeassistant/components/recorder/models/state.py | 2 +- homeassistant/components/remote/__init__.py | 2 +- homeassistant/components/roborock/coordinator.py | 2 +- homeassistant/components/script/__init__.py | 2 +- homeassistant/components/select/__init__.py | 2 +- homeassistant/components/sensor/__init__.py | 4 +++- homeassistant/components/shelly/coordinator.py | 2 +- homeassistant/components/siren/__init__.py | 3 ++- homeassistant/components/switch/__init__.py | 3 ++- homeassistant/components/template/template_entity.py | 2 +- homeassistant/components/text/__init__.py | 2 +- homeassistant/components/thread/dataset_store.py | 2 +- homeassistant/components/time/__init__.py | 6 +++--- homeassistant/components/todo/__init__.py | 2 +- homeassistant/components/tts/__init__.py | 3 ++- homeassistant/components/unifi/device_tracker.py | 2 +- homeassistant/components/update/__init__.py | 3 ++- homeassistant/components/vacuum/__init__.py | 3 ++- homeassistant/components/water_heater/__init__.py | 2 +- homeassistant/components/weather/__init__.py | 3 ++- homeassistant/components/zha/entity.py | 3 ++- homeassistant/core.py | 2 +- homeassistant/helpers/area_registry.py | 3 ++- homeassistant/helpers/device_registry.py | 3 ++- homeassistant/helpers/entity.py | 2 +- homeassistant/helpers/entity_registry.py | 2 +- homeassistant/helpers/frame.py | 3 ++- homeassistant/helpers/intent.py | 2 +- homeassistant/helpers/script.py | 3 ++- homeassistant/helpers/storage.py | 3 ++- homeassistant/helpers/update_coordinator.py | 2 +- homeassistant/loader.py | 2 +- homeassistant/package_constraints.txt | 1 + homeassistant/util/yaml/loader.py | 2 +- pyproject.toml | 1 + requirements.txt | 1 + tests/helpers/test_entity.py | 2 +- tests/test_backports.py | 2 +- tests/test_config_entries.py | 2 +- 82 files changed, 118 insertions(+), 85 deletions(-) diff --git a/homeassistant/auth/models.py b/homeassistant/auth/models.py index 7192f6345e1e27..0b6515ed9a5ea4 100644 --- a/homeassistant/auth/models.py +++ b/homeassistant/auth/models.py @@ -3,7 +3,6 @@ from __future__ import annotations from datetime import datetime, timedelta -from functools import cached_property import secrets from typing import Any, NamedTuple import uuid @@ -11,6 +10,7 @@ import attr from attr import Attribute from attr.setters import validate +from propcache import cached_property from homeassistant.const import __version__ from homeassistant.data_entry_flow import FlowResult diff --git a/homeassistant/backports/functools.py b/homeassistant/backports/functools.py index bad4236f9c8fe2..c838ca7f680c4e 100644 --- a/homeassistant/backports/functools.py +++ b/homeassistant/backports/functools.py @@ -9,7 +9,9 @@ from __future__ import annotations -from functools import cached_property as _cached_property, partial +from functools import partial + +from propcache import cached_property as _cached_property from homeassistant.helpers.deprecation import ( DeprecatedAlias, diff --git a/homeassistant/components/airgradient/update.py b/homeassistant/components/airgradient/update.py index eb6708afb67abb..47e71cb4e6537e 100644 --- a/homeassistant/components/airgradient/update.py +++ b/homeassistant/components/airgradient/update.py @@ -1,7 +1,8 @@ """Airgradient Update platform.""" from datetime import timedelta -from functools import cached_property + +from propcache import cached_property from homeassistant.components.update import UpdateDeviceClass, UpdateEntity from homeassistant.core import HomeAssistant diff --git a/homeassistant/components/alarm_control_panel/__init__.py b/homeassistant/components/alarm_control_panel/__init__.py index 5cc13c867294fd..e5c2745104dcca 100644 --- a/homeassistant/components/alarm_control_panel/__init__.py +++ b/homeassistant/components/alarm_control_panel/__init__.py @@ -3,10 +3,11 @@ from __future__ import annotations from datetime import timedelta -from functools import cached_property, partial +from functools import partial import logging from typing import Any, Final, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 8f1a38c2cd00cf..4fcd8a1416d66e 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -6,10 +6,11 @@ import asyncio from collections.abc import Callable, Mapping from dataclasses import dataclass -from functools import cached_property, partial +from functools import partial import logging from typing import Any, Protocol, cast +from propcache import cached_property import voluptuous as vol from homeassistant.components import websocket_api diff --git a/homeassistant/components/binary_sensor/__init__.py b/homeassistant/components/binary_sensor/__init__.py index 1aa6903d64d627..baf6bf985471fd 100644 --- a/homeassistant/components/binary_sensor/__init__.py +++ b/homeassistant/components/binary_sensor/__init__.py @@ -4,10 +4,11 @@ from datetime import timedelta from enum import StrEnum -from functools import cached_property, partial +from functools import partial import logging from typing import Literal, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/button/__init__.py b/homeassistant/components/button/__init__.py index 1f06a41bf2d607..14dc09ca33e1c0 100644 --- a/homeassistant/components/button/__init__.py +++ b/homeassistant/components/button/__init__.py @@ -4,10 +4,10 @@ from datetime import timedelta from enum import StrEnum -from functools import cached_property import logging from typing import final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index e5bce1b545b98f..f33f5feb6e9dd1 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -9,7 +9,7 @@ from dataclasses import asdict from datetime import datetime, timedelta from enum import IntFlag -from functools import cached_property, partial +from functools import partial import logging import os from random import SystemRandom @@ -18,6 +18,7 @@ from aiohttp import hdrs, web import attr +from propcache import cached_property import voluptuous as vol from homeassistant.components import websocket_api diff --git a/homeassistant/components/climate/__init__.py b/homeassistant/components/climate/__init__.py index 432fbffb84341e..94db8008aa1e0c 100644 --- a/homeassistant/components/climate/__init__.py +++ b/homeassistant/components/climate/__init__.py @@ -5,10 +5,10 @@ import asyncio from datetime import timedelta import functools as ft -from functools import cached_property import logging from typing import Any, Literal, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/cover/__init__.py b/homeassistant/components/cover/__init__.py index a9327965c4ed32..629d4c87ee35ed 100644 --- a/homeassistant/components/cover/__init__.py +++ b/homeassistant/components/cover/__init__.py @@ -6,10 +6,10 @@ from datetime import timedelta from enum import IntFlag, StrEnum import functools as ft -from functools import cached_property import logging from typing import Any, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/date/__init__.py b/homeassistant/components/date/__init__.py index f361d0a7896ce0..2f83de1233f50b 100644 --- a/homeassistant/components/date/__init__.py +++ b/homeassistant/components/date/__init__.py @@ -3,10 +3,10 @@ from __future__ import annotations from datetime import date, timedelta -from functools import cached_property import logging from typing import final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry @@ -80,13 +80,13 @@ class DateEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): @final def device_class(self) -> None: """Return the device class for the entity.""" - return None + return @cached_property @final def state_attributes(self) -> None: """Return the state attributes.""" - return None + return @property @final diff --git a/homeassistant/components/datetime/__init__.py b/homeassistant/components/datetime/__init__.py index 7e83da9c3cb414..5dfd1cdc25d381 100644 --- a/homeassistant/components/datetime/__init__.py +++ b/homeassistant/components/datetime/__init__.py @@ -3,10 +3,10 @@ from __future__ import annotations from datetime import UTC, datetime, timedelta -from functools import cached_property import logging from typing import final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry @@ -89,13 +89,13 @@ class DateTimeEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): @final def device_class(self) -> None: """Return entity device class.""" - return None + return @cached_property @final def state_attributes(self) -> None: """Return the state attributes.""" - return None + return @property @final diff --git a/homeassistant/components/device_tracker/config_entry.py b/homeassistant/components/device_tracker/config_entry.py index bea091c3fecc5c..50fc3d2d936733 100644 --- a/homeassistant/components/device_tracker/config_entry.py +++ b/homeassistant/components/device_tracker/config_entry.py @@ -3,9 +3,10 @@ from __future__ import annotations import asyncio -from functools import cached_property from typing import final +from propcache import cached_property + from homeassistant.components import zone from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( diff --git a/homeassistant/components/device_tracker/legacy.py b/homeassistant/components/device_tracker/legacy.py index 15cb67f5ee8d29..5dff5837b4b212 100644 --- a/homeassistant/components/device_tracker/legacy.py +++ b/homeassistant/components/device_tracker/legacy.py @@ -5,12 +5,12 @@ import asyncio from collections.abc import Callable, Coroutine, Sequence from datetime import datetime, timedelta -from functools import cached_property import hashlib from types import ModuleType from typing import Any, Final, Protocol, final import attr +from propcache import cached_property import voluptuous as vol from homeassistant import util diff --git a/homeassistant/components/dlna_dms/dms.py b/homeassistant/components/dlna_dms/dms.py index 6a81fa46f74d85..8f475d53280de1 100644 --- a/homeassistant/components/dlna_dms/dms.py +++ b/homeassistant/components/dlna_dms/dms.py @@ -7,7 +7,6 @@ from dataclasses import dataclass from enum import StrEnum import functools -from functools import cached_property from typing import Any, cast from async_upnp_client.aiohttp import AiohttpSessionRequester @@ -17,6 +16,7 @@ from async_upnp_client.exceptions import UpnpActionError, UpnpConnectionError, UpnpError from async_upnp_client.profiles.dlna import ContentDirectoryErrorCode, DmsDevice from didl_lite import didl_lite +from propcache import cached_property from homeassistant.components import ssdp from homeassistant.components.media_player import BrowseError, MediaClass diff --git a/homeassistant/components/doorbird/device.py b/homeassistant/components/doorbird/device.py index 1aaea257a4c5cf..eae5bb6804f704 100644 --- a/homeassistant/components/doorbird/device.py +++ b/homeassistant/components/doorbird/device.py @@ -4,7 +4,6 @@ from collections import defaultdict from dataclasses import dataclass -from functools import cached_property from http import HTTPStatus import logging from typing import Any @@ -16,6 +15,7 @@ DoorBirdScheduleEntryOutput, DoorBirdScheduleEntrySchedule, ) +from propcache import cached_property from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant diff --git a/homeassistant/components/event/__init__.py b/homeassistant/components/event/__init__.py index a7d96860a48471..c4a8fb2d0af1ca 100644 --- a/homeassistant/components/event/__init__.py +++ b/homeassistant/components/event/__init__.py @@ -5,10 +5,11 @@ from dataclasses import asdict, dataclass from datetime import datetime, timedelta from enum import StrEnum -from functools import cached_property import logging from typing import Any, Self, final +from propcache import cached_property + from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv diff --git a/homeassistant/components/fan/__init__.py b/homeassistant/components/fan/__init__.py index e05ed967eb32b0..b1c2b748520c8a 100644 --- a/homeassistant/components/fan/__init__.py +++ b/homeassistant/components/fan/__init__.py @@ -6,11 +6,11 @@ from datetime import timedelta from enum import IntFlag import functools as ft -from functools import cached_property import logging import math from typing import Any, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/ffmpeg/__init__.py b/homeassistant/components/ffmpeg/__init__.py index 94503108deb48c..9a88317027e8f2 100644 --- a/homeassistant/components/ffmpeg/__init__.py +++ b/homeassistant/components/ffmpeg/__init__.py @@ -3,11 +3,11 @@ from __future__ import annotations import asyncio -from functools import cached_property import re from haffmpeg.core import HAFFmpeg from haffmpeg.tools import IMAGE_JPEG, FFVersion, ImageFrame +from propcache import cached_property import voluptuous as vol from homeassistant.const import ( diff --git a/homeassistant/components/fints/sensor.py b/homeassistant/components/fints/sensor.py index e22b7072786ad3..a1cd565153f68e 100644 --- a/homeassistant/components/fints/sensor.py +++ b/homeassistant/components/fints/sensor.py @@ -4,12 +4,12 @@ from collections import namedtuple from datetime import timedelta -from functools import cached_property import logging from typing import Any from fints.client import FinTS3PinTanClient from fints.models import SEPAAccount +from propcache import cached_property import voluptuous as vol from homeassistant.components.sensor import ( diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index e6e26a661ae3b9..c1098ac19d3a37 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Callable, Iterator -from functools import cached_property, lru_cache, partial +from functools import lru_cache, partial import logging import os import pathlib @@ -11,6 +11,7 @@ from aiohttp import hdrs, web, web_urldispatcher import jinja2 +from propcache import cached_property import voluptuous as vol from yarl import URL diff --git a/homeassistant/components/geo_location/__init__.py b/homeassistant/components/geo_location/__init__.py index cafd30d76580bd..877471f002ac0e 100644 --- a/homeassistant/components/geo_location/__init__.py +++ b/homeassistant/components/geo_location/__init__.py @@ -3,10 +3,11 @@ from __future__ import annotations from datetime import timedelta -from functools import cached_property import logging from typing import Any, final +from propcache import cached_property + from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE from homeassistant.core import HomeAssistant diff --git a/homeassistant/components/homekit_controller/climate.py b/homeassistant/components/homekit_controller/climate.py index 544e23798d0959..3be0af17dbd7dd 100644 --- a/homeassistant/components/homekit_controller/climate.py +++ b/homeassistant/components/homekit_controller/climate.py @@ -2,7 +2,6 @@ from __future__ import annotations -from functools import cached_property import logging from typing import Any, Final @@ -17,6 +16,7 @@ ) from aiohomekit.model.services import Service, ServicesTypes from aiohomekit.utils import clamp_enum_to_char +from propcache import cached_property from homeassistant.components.climate import ( ATTR_HVAC_MODE, diff --git a/homeassistant/components/homekit_controller/cover.py b/homeassistant/components/homekit_controller/cover.py index 0eebb72c988a5f..33336d5a5ba2e9 100644 --- a/homeassistant/components/homekit_controller/cover.py +++ b/homeassistant/components/homekit_controller/cover.py @@ -2,11 +2,11 @@ from __future__ import annotations -from functools import cached_property from typing import Any from aiohomekit.model.characteristics import CharacteristicsTypes from aiohomekit.model.services import Service, ServicesTypes +from propcache import cached_property from homeassistant.components.cover import ( ATTR_POSITION, diff --git a/homeassistant/components/homekit_controller/fan.py b/homeassistant/components/homekit_controller/fan.py index 93ebbba62b1d83..63de146a0246d7 100644 --- a/homeassistant/components/homekit_controller/fan.py +++ b/homeassistant/components/homekit_controller/fan.py @@ -2,11 +2,11 @@ from __future__ import annotations -from functools import cached_property from typing import Any from aiohomekit.model.characteristics import CharacteristicsTypes from aiohomekit.model.services import Service, ServicesTypes +from propcache import cached_property from homeassistant.components.fan import ( DIRECTION_FORWARD, diff --git a/homeassistant/components/homekit_controller/humidifier.py b/homeassistant/components/homekit_controller/humidifier.py index cbfcfb6d3bb959..f82baab5df70ab 100644 --- a/homeassistant/components/homekit_controller/humidifier.py +++ b/homeassistant/components/homekit_controller/humidifier.py @@ -2,11 +2,11 @@ from __future__ import annotations -from functools import cached_property from typing import Any from aiohomekit.model.characteristics import CharacteristicsTypes from aiohomekit.model.services import Service, ServicesTypes +from propcache import cached_property from homeassistant.components.humidifier import ( DEFAULT_MAX_HUMIDITY, diff --git a/homeassistant/components/homekit_controller/light.py b/homeassistant/components/homekit_controller/light.py index d5f20723ff1468..472ccfbd55036f 100644 --- a/homeassistant/components/homekit_controller/light.py +++ b/homeassistant/components/homekit_controller/light.py @@ -2,11 +2,11 @@ from __future__ import annotations -from functools import cached_property from typing import Any from aiohomekit.model.characteristics import CharacteristicsTypes from aiohomekit.model.services import Service, ServicesTypes +from propcache import cached_property from homeassistant.components.light import ( ATTR_BRIGHTNESS, diff --git a/homeassistant/components/humidifier/__init__.py b/homeassistant/components/humidifier/__init__.py index 3979b66397f00b..b556a6961bb44b 100644 --- a/homeassistant/components/humidifier/__init__.py +++ b/homeassistant/components/humidifier/__init__.py @@ -4,10 +4,11 @@ from datetime import timedelta from enum import StrEnum -from functools import cached_property, partial +from functools import partial import logging from typing import Any, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/image/__init__.py b/homeassistant/components/image/__init__.py index 5fb5790f25c518..47019f3e92e7b9 100644 --- a/homeassistant/components/image/__init__.py +++ b/homeassistant/components/image/__init__.py @@ -7,13 +7,13 @@ from contextlib import suppress from dataclasses import dataclass from datetime import datetime, timedelta -from functools import cached_property import logging from random import SystemRandom from typing import Final, final from aiohttp import hdrs, web import httpx +from propcache import cached_property from homeassistant.components.http import KEY_AUTHENTICATED, KEY_HASS, HomeAssistantView from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/intent/timers.py b/homeassistant/components/intent/timers.py index a8576509a4bfb3..639744abc66ea6 100644 --- a/homeassistant/components/intent/timers.py +++ b/homeassistant/components/intent/timers.py @@ -6,11 +6,11 @@ from collections.abc import Callable from dataclasses import dataclass from enum import StrEnum -from functools import cached_property import logging import time from typing import Any +from propcache import cached_property import voluptuous as vol from homeassistant.const import ATTR_DEVICE_ID, ATTR_ID, ATTR_NAME diff --git a/homeassistant/components/lawn_mower/__init__.py b/homeassistant/components/lawn_mower/__init__.py index b9d5f70f9ed30d..a8c52b72a81cb3 100644 --- a/homeassistant/components/lawn_mower/__init__.py +++ b/homeassistant/components/lawn_mower/__init__.py @@ -3,10 +3,11 @@ from __future__ import annotations from datetime import timedelta -from functools import cached_property import logging from typing import final +from propcache import cached_property + from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv diff --git a/homeassistant/components/lifx/coordinator.py b/homeassistant/components/lifx/coordinator.py index 9d5532aeeb20a1..41fa04057f7cd0 100644 --- a/homeassistant/components/lifx/coordinator.py +++ b/homeassistant/components/lifx/coordinator.py @@ -6,7 +6,7 @@ from collections.abc import Callable from datetime import timedelta from enum import IntEnum -from functools import cached_property, partial +from functools import partial from math import floor, log10 from typing import Any, cast @@ -21,6 +21,7 @@ from aiolifx.connection import LIFXConnection from aiolifx_themes.themes import ThemeLibrary, ThemePainter from awesomeversion import AwesomeVersion +from propcache import cached_property from homeassistant.const import ( SIGNAL_STRENGTH_DECIBELS, diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index a496404401a00d..0bdabf26ff4cac 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -7,11 +7,11 @@ import dataclasses from datetime import timedelta from enum import IntFlag, StrEnum -from functools import cached_property import logging import os from typing import Any, Self, cast, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/lock/__init__.py b/homeassistant/components/lock/__init__.py index 7bc0d88addccc1..fad87145e0090b 100644 --- a/homeassistant/components/lock/__init__.py +++ b/homeassistant/components/lock/__init__.py @@ -5,11 +5,11 @@ from datetime import timedelta from enum import IntFlag import functools as ft -from functools import cached_property import logging import re from typing import TYPE_CHECKING, Any, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/logbook/models.py b/homeassistant/components/logbook/models.py index 8fd850b26fb392..c33325d7dcbf8a 100644 --- a/homeassistant/components/logbook/models.py +++ b/homeassistant/components/logbook/models.py @@ -4,9 +4,9 @@ from collections.abc import Callable, Mapping from dataclasses import dataclass -from functools import cached_property from typing import TYPE_CHECKING, Any, Final, NamedTuple, cast +from propcache import cached_property from sqlalchemy.engine.row import Row from homeassistant.components.recorder.filters import Filters diff --git a/homeassistant/components/matter/entity.py b/homeassistant/components/matter/entity.py index 5e6007f4418e61..1a454bb7357c8e 100644 --- a/homeassistant/components/matter/entity.py +++ b/homeassistant/components/matter/entity.py @@ -4,7 +4,6 @@ from collections.abc import Callable from dataclasses import dataclass -from functools import cached_property import logging from typing import TYPE_CHECKING, Any, cast @@ -12,6 +11,7 @@ from chip.clusters.Objects import ClusterAttributeDescriptor, NullValue from matter_server.common.helpers.util import create_attribute_path from matter_server.common.models import EventType, ServerInfoMessage +from propcache import cached_property from homeassistant.core import callback from homeassistant.helpers.device_registry import DeviceInfo diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index 2323c14b688f14..291b1ec1e2a1ca 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -9,7 +9,7 @@ import datetime as dt from enum import StrEnum import functools as ft -from functools import cached_property, lru_cache +from functools import lru_cache import hashlib from http import HTTPStatus import logging @@ -21,6 +21,7 @@ from aiohttp import web from aiohttp.hdrs import CACHE_CONTROL, CONTENT_TYPE from aiohttp.typedefs import LooseHeaders +from propcache import cached_property import voluptuous as vol from yarl import URL diff --git a/homeassistant/components/nibe_heatpump/coordinator.py b/homeassistant/components/nibe_heatpump/coordinator.py index 2c19703549ab63..ed6d18f788859e 100644 --- a/homeassistant/components/nibe_heatpump/coordinator.py +++ b/homeassistant/components/nibe_heatpump/coordinator.py @@ -6,13 +6,13 @@ from collections import defaultdict from collections.abc import Callable, Iterable from datetime import date, timedelta -from functools import cached_property from typing import Any from nibe.coil import Coil, CoilData from nibe.connection import Connection from nibe.exceptions import CoilNotFoundException, ReadException from nibe.heatpump import HeatPump, Series +from propcache import cached_property from homeassistant.config_entries import ConfigEntry from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback diff --git a/homeassistant/components/notify/__init__.py b/homeassistant/components/notify/__init__.py index a4ebfc7f6de22d..0b7a25ced3e8ed 100644 --- a/homeassistant/components/notify/__init__.py +++ b/homeassistant/components/notify/__init__.py @@ -4,10 +4,11 @@ from datetime import timedelta from enum import IntFlag -from functools import cached_property, partial +from functools import partial import logging from typing import Any, final, override +from propcache import cached_property import voluptuous as vol import homeassistant.components.persistent_notification as pn diff --git a/homeassistant/components/number/__init__.py b/homeassistant/components/number/__init__.py index 2b2faba8f18c09..dc169fcb348b86 100644 --- a/homeassistant/components/number/__init__.py +++ b/homeassistant/components/number/__init__.py @@ -6,11 +6,11 @@ from contextlib import suppress import dataclasses from datetime import timedelta -from functools import cached_property import logging from math import ceil, floor from typing import TYPE_CHECKING, Any, Self, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/overkiz/climate/atlantic_pass_apc_zone_control_zone.py b/homeassistant/components/overkiz/climate/atlantic_pass_apc_zone_control_zone.py index 9027dcf8d03e79..5ba9dabe03897c 100644 --- a/homeassistant/components/overkiz/climate/atlantic_pass_apc_zone_control_zone.py +++ b/homeassistant/components/overkiz/climate/atlantic_pass_apc_zone_control_zone.py @@ -3,9 +3,9 @@ from __future__ import annotations from asyncio import sleep -from functools import cached_property from typing import Any, cast +from propcache import cached_property from pyoverkiz.enums import OverkizCommand, OverkizCommandParam, OverkizState from homeassistant.components.climate import ( diff --git a/homeassistant/components/rainbird/coordinator.py b/homeassistant/components/rainbird/coordinator.py index 83db2d584d264e..2657fd6433ed31 100644 --- a/homeassistant/components/rainbird/coordinator.py +++ b/homeassistant/components/rainbird/coordinator.py @@ -5,10 +5,10 @@ import asyncio from dataclasses import dataclass import datetime -from functools import cached_property import logging import aiohttp +from propcache import cached_property from pyrainbird.async_client import ( AsyncRainbirdController, RainbirdApiException, diff --git a/homeassistant/components/recorder/core.py b/homeassistant/components/recorder/core.py index 4866c8d536a4bc..77d01088d67db6 100644 --- a/homeassistant/components/recorder/core.py +++ b/homeassistant/components/recorder/core.py @@ -7,7 +7,6 @@ from concurrent.futures import CancelledError import contextlib from datetime import datetime, timedelta -from functools import cached_property import logging import queue import sqlite3 @@ -15,6 +14,7 @@ import time from typing import TYPE_CHECKING, Any, cast +from propcache import cached_property import psutil_home_assistant as ha_psutil from sqlalchemy import create_engine, event as sqlalchemy_event, exc, select, update from sqlalchemy.engine import Engine diff --git a/homeassistant/components/recorder/models/state.py b/homeassistant/components/recorder/models/state.py index 139522a3d2007b..89281a85c15635 100644 --- a/homeassistant/components/recorder/models/state.py +++ b/homeassistant/components/recorder/models/state.py @@ -3,10 +3,10 @@ from __future__ import annotations from datetime import datetime -from functools import cached_property import logging from typing import TYPE_CHECKING, Any +from propcache import cached_property from sqlalchemy.engine.row import Row from homeassistant.const import ( diff --git a/homeassistant/components/remote/__init__.py b/homeassistant/components/remote/__init__.py index 8d027b95eef6b9..6a007bde0b447d 100644 --- a/homeassistant/components/remote/__init__.py +++ b/homeassistant/components/remote/__init__.py @@ -6,10 +6,10 @@ from datetime import timedelta from enum import IntFlag import functools as ft -from functools import cached_property import logging from typing import Any, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/roborock/coordinator.py b/homeassistant/components/roborock/coordinator.py index 6b520ba10d6e8a..20bc50f9855cde 100644 --- a/homeassistant/components/roborock/coordinator.py +++ b/homeassistant/components/roborock/coordinator.py @@ -4,9 +4,9 @@ import asyncio from datetime import timedelta -from functools import cached_property import logging +from propcache import cached_property from roborock import HomeDataRoom from roborock.code_mappings import RoborockCategory from roborock.containers import DeviceData, HomeDataDevice, HomeDataProduct, NetworkInfo diff --git a/homeassistant/components/script/__init__.py b/homeassistant/components/script/__init__.py index 6fd26b2ea8d8f0..c0d79c446bb8f4 100644 --- a/homeassistant/components/script/__init__.py +++ b/homeassistant/components/script/__init__.py @@ -5,10 +5,10 @@ from abc import ABC, abstractmethod import asyncio from dataclasses import dataclass -from functools import cached_property import logging from typing import TYPE_CHECKING, Any, cast +from propcache import cached_property import voluptuous as vol from homeassistant.components import websocket_api diff --git a/homeassistant/components/select/__init__.py b/homeassistant/components/select/__init__.py index b317f4ec601f2b..3834dc4a0c74b3 100644 --- a/homeassistant/components/select/__init__.py +++ b/homeassistant/components/select/__init__.py @@ -3,10 +3,10 @@ from __future__ import annotations from datetime import timedelta -from functools import cached_property import logging from typing import Any, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index 88d35217556a6c..31626b0b761198 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -8,11 +8,13 @@ from dataclasses import dataclass from datetime import UTC, date, datetime, timedelta from decimal import Decimal, InvalidOperation as DecimalInvalidOperation -from functools import cached_property, partial +from functools import partial import logging from math import ceil, floor, isfinite, log10 from typing import Any, Final, Self, cast, final, override +from propcache import cached_property + from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( # noqa: F401 _DEPRECATED_DEVICE_CLASS_AQI, diff --git a/homeassistant/components/shelly/coordinator.py b/homeassistant/components/shelly/coordinator.py index c8e6cc03a06c58..6332e139244b9d 100644 --- a/homeassistant/components/shelly/coordinator.py +++ b/homeassistant/components/shelly/coordinator.py @@ -6,7 +6,6 @@ from collections.abc import Callable, Coroutine from dataclasses import dataclass from datetime import timedelta -from functools import cached_property from typing import Any, cast from aioshelly.ble import async_ensure_ble_enabled, async_stop_scanner @@ -14,6 +13,7 @@ from aioshelly.const import MODEL_NAMES, MODEL_VALVE from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError, RpcCallError from aioshelly.rpc_device import RpcDevice, RpcUpdateType +from propcache import cached_property from homeassistant.config_entries import ConfigEntry, ConfigEntryState from homeassistant.const import ( diff --git a/homeassistant/components/siren/__init__.py b/homeassistant/components/siren/__init__.py index 15a46adeb3b153..91456d6fa3b493 100644 --- a/homeassistant/components/siren/__init__.py +++ b/homeassistant/components/siren/__init__.py @@ -3,10 +3,11 @@ from __future__ import annotations from datetime import timedelta -from functools import cached_property, partial +from functools import partial import logging from typing import Any, TypedDict, cast, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/switch/__init__.py b/homeassistant/components/switch/__init__.py index e11b392ec07f22..9838d9501f7257 100644 --- a/homeassistant/components/switch/__init__.py +++ b/homeassistant/components/switch/__init__.py @@ -4,9 +4,10 @@ from datetime import timedelta from enum import StrEnum -from functools import cached_property, partial +from functools import partial import logging +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/template/template_entity.py b/homeassistant/components/template/template_entity.py index 8930edc03e6ca9..c881b0ff2bbbad 100644 --- a/homeassistant/components/template/template_entity.py +++ b/homeassistant/components/template/template_entity.py @@ -4,11 +4,11 @@ from collections.abc import Callable, Mapping import contextlib -from functools import cached_property import itertools import logging from typing import Any +from propcache import cached_property import voluptuous as vol from homeassistant.const import ( diff --git a/homeassistant/components/text/__init__.py b/homeassistant/components/text/__init__.py index 633c29e7beb830..d0f5ac7d3b7634 100644 --- a/homeassistant/components/text/__init__.py +++ b/homeassistant/components/text/__init__.py @@ -5,11 +5,11 @@ from dataclasses import asdict, dataclass from datetime import timedelta from enum import StrEnum -from functools import cached_property import logging import re from typing import Any, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/thread/dataset_store.py b/homeassistant/components/thread/dataset_store.py index b880be801a43a1..fc95e524181c0d 100644 --- a/homeassistant/components/thread/dataset_store.py +++ b/homeassistant/components/thread/dataset_store.py @@ -5,10 +5,10 @@ from asyncio import Event, Task, wait import dataclasses from datetime import datetime -from functools import cached_property import logging from typing import Any, cast +from propcache import cached_property from python_otbr_api import tlv_parser from python_otbr_api.tlv_parser import MeshcopTLVType diff --git a/homeassistant/components/time/__init__.py b/homeassistant/components/time/__init__.py index 4888b525dee153..cfd0626aeb4e36 100644 --- a/homeassistant/components/time/__init__.py +++ b/homeassistant/components/time/__init__.py @@ -3,10 +3,10 @@ from __future__ import annotations from datetime import time, timedelta -from functools import cached_property import logging from typing import final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry @@ -80,13 +80,13 @@ class TimeEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): @final def device_class(self) -> None: """Return the device class for the entity.""" - return None + return @cached_property @final def state_attributes(self) -> None: """Return the state attributes.""" - return None + return @property @final diff --git a/homeassistant/components/todo/__init__.py b/homeassistant/components/todo/__init__.py index fa3241cd88495a..e4bc549a16b35d 100644 --- a/homeassistant/components/todo/__init__.py +++ b/homeassistant/components/todo/__init__.py @@ -5,10 +5,10 @@ from collections.abc import Callable, Iterable import dataclasses import datetime -from functools import cached_property import logging from typing import Any, final +from propcache import cached_property import voluptuous as vol from homeassistant.components import frontend, websocket_api diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index 671d5b13f37b69..ad267b9106b9d6 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -5,7 +5,7 @@ import asyncio from collections.abc import Mapping from datetime import datetime -from functools import cached_property, partial +from functools import partial import hashlib from http import HTTPStatus import io @@ -20,6 +20,7 @@ from aiohttp import web import mutagen from mutagen.id3 import ID3, TextFrame as ID3Text +from propcache import cached_property import voluptuous as vol from homeassistant.components import ffmpeg, websocket_api diff --git a/homeassistant/components/unifi/device_tracker.py b/homeassistant/components/unifi/device_tracker.py index c6694fce1096c7..735f76a73bf947 100644 --- a/homeassistant/components/unifi/device_tracker.py +++ b/homeassistant/components/unifi/device_tracker.py @@ -5,7 +5,6 @@ from collections.abc import Callable, Mapping from dataclasses import dataclass from datetime import timedelta -from functools import cached_property import logging from typing import Any @@ -17,6 +16,7 @@ from aiounifi.models.client import Client from aiounifi.models.device import Device from aiounifi.models.event import Event, EventKey +from propcache import cached_property from homeassistant.components.device_tracker import ( DOMAIN as DEVICE_TRACKER_DOMAIN, diff --git a/homeassistant/components/update/__init__.py b/homeassistant/components/update/__init__.py index 8897e9cc442592..82f2792afa3d7f 100644 --- a/homeassistant/components/update/__init__.py +++ b/homeassistant/components/update/__init__.py @@ -4,11 +4,12 @@ from datetime import timedelta from enum import StrEnum -from functools import cached_property, lru_cache +from functools import lru_cache import logging from typing import Any, Final, final from awesomeversion import AwesomeVersion, AwesomeVersionCompareException +from propcache import cached_property import voluptuous as vol from homeassistant.components import websocket_api diff --git a/homeassistant/components/vacuum/__init__.py b/homeassistant/components/vacuum/__init__.py index 0922ee75ee7a79..a81dbeacee1118 100644 --- a/homeassistant/components/vacuum/__init__.py +++ b/homeassistant/components/vacuum/__init__.py @@ -4,10 +4,11 @@ from datetime import timedelta from enum import IntFlag -from functools import cached_property, partial +from functools import partial import logging from typing import Any +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/water_heater/__init__.py b/homeassistant/components/water_heater/__init__.py index 502f7d226b0ccf..4bfe1ce4481725 100644 --- a/homeassistant/components/water_heater/__init__.py +++ b/homeassistant/components/water_heater/__init__.py @@ -5,10 +5,10 @@ from datetime import timedelta from enum import IntFlag import functools as ft -from functools import cached_property import logging from typing import Any, final +from propcache import cached_property import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/weather/__init__.py b/homeassistant/components/weather/__init__.py index 4db90f70bd89a1..557765795ee88d 100644 --- a/homeassistant/components/weather/__init__.py +++ b/homeassistant/components/weather/__init__.py @@ -6,10 +6,11 @@ from collections.abc import Callable, Iterable from contextlib import suppress from datetime import timedelta -from functools import cached_property, partial +from functools import partial import logging from typing import Any, Final, Generic, Literal, Required, TypedDict, cast, final +from propcache import cached_property from typing_extensions import TypeVar import voluptuous as vol diff --git a/homeassistant/components/zha/entity.py b/homeassistant/components/zha/entity.py index b9e2e0fb3d2c63..3e3d0642ca2298 100644 --- a/homeassistant/components/zha/entity.py +++ b/homeassistant/components/zha/entity.py @@ -4,10 +4,11 @@ import asyncio from collections.abc import Callable -from functools import cached_property, partial +from functools import partial import logging from typing import Any +from propcache import cached_property from zha.mixins import LogMixin from homeassistant.const import ATTR_MANUFACTURER, ATTR_MODEL, ATTR_NAME, EntityCategory diff --git a/homeassistant/core.py b/homeassistant/core.py index b797798134e9fe..020b9f1f6b35f2 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -23,7 +23,6 @@ import datetime import enum import functools -from functools import cached_property import inspect import logging import os @@ -45,6 +44,7 @@ ) from urllib.parse import urlparse +from propcache import cached_property from typing_extensions import TypeVar import voluptuous as vol import yarl diff --git a/homeassistant/helpers/area_registry.py b/homeassistant/helpers/area_registry.py index f20631aa0a4395..3f22a54196b02a 100644 --- a/homeassistant/helpers/area_registry.py +++ b/homeassistant/helpers/area_registry.py @@ -7,9 +7,10 @@ import dataclasses from dataclasses import dataclass, field from datetime import datetime -from functools import cached_property from typing import Any, Literal, TypedDict +from propcache import cached_property + from homeassistant.core import HomeAssistant, callback from homeassistant.util.dt import utc_from_timestamp, utcnow from homeassistant.util.event_type import EventType diff --git a/homeassistant/helpers/device_registry.py b/homeassistant/helpers/device_registry.py index af0baa75a01a93..0270f819d391b0 100644 --- a/homeassistant/helpers/device_registry.py +++ b/homeassistant/helpers/device_registry.py @@ -6,12 +6,13 @@ from collections.abc import Mapping from datetime import datetime from enum import StrEnum -from functools import cached_property, lru_cache, partial +from functools import lru_cache, partial import logging import time from typing import TYPE_CHECKING, Any, Literal, TypedDict import attr +from propcache import cached_property from yarl import URL from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index dbc1a036ef6f93..cc843b6d9b14e0 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -9,7 +9,6 @@ import dataclasses from enum import Enum, IntFlag, auto import functools as ft -from functools import cached_property import logging import math from operator import attrgetter @@ -19,6 +18,7 @@ from types import FunctionType from typing import TYPE_CHECKING, Any, Final, Literal, NotRequired, TypedDict, final +from propcache import cached_property import voluptuous as vol from homeassistant.config import DATA_CUSTOMIZE diff --git a/homeassistant/helpers/entity_registry.py b/homeassistant/helpers/entity_registry.py index df06a49e97fa17..cf8b173edac27d 100644 --- a/homeassistant/helpers/entity_registry.py +++ b/homeassistant/helpers/entity_registry.py @@ -14,12 +14,12 @@ from collections.abc import Callable, Container, Hashable, KeysView, Mapping from datetime import datetime, timedelta from enum import StrEnum -from functools import cached_property import logging import time from typing import TYPE_CHECKING, Any, Literal, NotRequired, TypedDict import attr +from propcache import cached_property import voluptuous as vol from homeassistant.const import ( diff --git a/homeassistant/helpers/frame.py b/homeassistant/helpers/frame.py index e8df1cea21b6eb..fd7e014b2ffed8 100644 --- a/homeassistant/helpers/frame.py +++ b/homeassistant/helpers/frame.py @@ -6,13 +6,14 @@ from collections.abc import Callable from dataclasses import dataclass import functools -from functools import cached_property import linecache import logging import sys from types import FrameType from typing import Any, cast +from propcache import cached_property + from homeassistant.core import async_get_hass_or_none from homeassistant.exceptions import HomeAssistantError from homeassistant.loader import async_suggest_report_issue diff --git a/homeassistant/helpers/intent.py b/homeassistant/helpers/intent.py index be9b57bf81423c..15e38d39dda2c1 100644 --- a/homeassistant/helpers/intent.py +++ b/homeassistant/helpers/intent.py @@ -8,11 +8,11 @@ import dataclasses from dataclasses import dataclass, field from enum import Enum, StrEnum, auto -from functools import cached_property from itertools import groupby import logging from typing import Any +from propcache import cached_property import voluptuous as vol from homeassistant.components.homeassistant.exposed_entities import async_should_expose diff --git a/homeassistant/helpers/script.py b/homeassistant/helpers/script.py index 0b5c0b99c35b43..ee2c4c647732e3 100644 --- a/homeassistant/helpers/script.py +++ b/homeassistant/helpers/script.py @@ -9,13 +9,14 @@ from copy import copy from dataclasses import dataclass from datetime import datetime, timedelta -from functools import cached_property, partial +from functools import partial import itertools import logging from types import MappingProxyType from typing import Any, Literal, TypedDict, cast, overload import async_interrupt +from propcache import cached_property import voluptuous as vol from homeassistant import exceptions diff --git a/homeassistant/helpers/storage.py b/homeassistant/helpers/storage.py index 7e3c12cfc01781..080599f54d8ce5 100644 --- a/homeassistant/helpers/storage.py +++ b/homeassistant/helpers/storage.py @@ -6,7 +6,6 @@ from collections.abc import Callable, Iterable, Mapping, Sequence from contextlib import suppress from copy import deepcopy -from functools import cached_property import inspect from json import JSONDecodeError, JSONEncoder import logging @@ -14,6 +13,8 @@ from pathlib import Path from typing import Any +from propcache import cached_property + from homeassistant.const import ( EVENT_HOMEASSISTANT_FINAL_WRITE, EVENT_HOMEASSISTANT_STARTED, diff --git a/homeassistant/helpers/update_coordinator.py b/homeassistant/helpers/update_coordinator.py index 4fe4953d75247f..25cd4bc4d906ec 100644 --- a/homeassistant/helpers/update_coordinator.py +++ b/homeassistant/helpers/update_coordinator.py @@ -6,7 +6,6 @@ import asyncio from collections.abc import Awaitable, Callable, Coroutine, Generator from datetime import datetime, timedelta -from functools import cached_property import logging from random import randint from time import monotonic @@ -14,6 +13,7 @@ import urllib.error import aiohttp +from propcache import cached_property import requests from typing_extensions import TypeVar diff --git a/homeassistant/loader.py b/homeassistant/loader.py index ae42bfb369b3fc..dd38271070d9d1 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -11,7 +11,6 @@ from contextlib import suppress from dataclasses import dataclass import functools as ft -from functools import cached_property import importlib import logging import os @@ -26,6 +25,7 @@ AwesomeVersionException, AwesomeVersionStrategy, ) +from propcache import cached_property import voluptuous as vol from . import generated diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 7e9ba3154a67ae..bb1910f0877818 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -43,6 +43,7 @@ orjson==3.10.7 packaging>=23.1 paho-mqtt==1.6.1 Pillow==10.4.0 +propcache==0.0.0 psutil-home-assistant==0.0.1 PyJWT==2.9.0 pymicro-vad==1.0.1 diff --git a/homeassistant/util/yaml/loader.py b/homeassistant/util/yaml/loader.py index 31efced60f6419..39ac17d94f997f 100644 --- a/homeassistant/util/yaml/loader.py +++ b/homeassistant/util/yaml/loader.py @@ -22,7 +22,7 @@ SafeLoader as FastestAvailableSafeLoader, ) -from functools import cached_property +from propcache import cached_property from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.frame import report diff --git a/pyproject.toml b/pyproject.toml index 56ca531257105e..cbb146c85a8cb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,6 +54,7 @@ dependencies = [ # PyJWT has loose dependency. We want the latest one. "cryptography==43.0.1", "Pillow==10.4.0", + "propcache==0.0.0", "pyOpenSSL==24.2.1", "orjson==3.10.7", "packaging>=23.1", diff --git a/requirements.txt b/requirements.txt index 500af7a6793983..e91f84574dd603 100644 --- a/requirements.txt +++ b/requirements.txt @@ -27,6 +27,7 @@ lru-dict==1.3.0 PyJWT==2.9.0 cryptography==43.0.1 Pillow==10.4.0 +propcache==0.0.0 pyOpenSSL==24.2.1 orjson==3.10.7 packaging>=23.1 diff --git a/tests/helpers/test_entity.py b/tests/helpers/test_entity.py index 58554059fb4894..bada0869ffd27f 100644 --- a/tests/helpers/test_entity.py +++ b/tests/helpers/test_entity.py @@ -5,13 +5,13 @@ import dataclasses from datetime import timedelta from enum import IntFlag -from functools import cached_property import logging import threading from typing import Any from unittest.mock import MagicMock, PropertyMock, patch from freezegun.api import FrozenDateTimeFactory +from propcache import cached_property import pytest from syrupy.assertion import SnapshotAssertion import voluptuous as vol diff --git a/tests/test_backports.py b/tests/test_backports.py index 4df0a9e3f573f2..41dbabc0fdba34 100644 --- a/tests/test_backports.py +++ b/tests/test_backports.py @@ -3,10 +3,10 @@ from __future__ import annotations from enum import StrEnum -from functools import cached_property from types import ModuleType from typing import Any +from propcache import cached_property import pytest from homeassistant.backports import ( diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index b7666516644796..4efa5887a8f5ba 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -5,13 +5,13 @@ import asyncio from collections.abc import Generator from datetime import timedelta -from functools import cached_property import logging from typing import Any, Self from unittest.mock import ANY, AsyncMock, Mock, patch from freezegun import freeze_time from freezegun.api import FrozenDateTimeFactory +from propcache import cached_property import pytest from syrupy.assertion import SnapshotAssertion From 9adf718175eb321a45509c6edeb1fa030c96e419 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 2 Oct 2024 12:03:14 -0500 Subject: [PATCH 2/6] wheels --- .github/workflows/wheels.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 9423a220ac19b5..8c847e422eadbe 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -219,7 +219,7 @@ jobs: wheels-key: ${{ secrets.WHEELS_KEY }} env-file: true apk: "bluez-dev;libffi-dev;openssl-dev;glib-dev;eudev-dev;libxml2-dev;libxslt-dev;libpng-dev;libjpeg-turbo-dev;tiff-dev;cups-dev;gmp-dev;mpfr-dev;mpc1-dev;ffmpeg-dev;gammu-dev;yaml-dev;openblas-dev;fftw-dev;lapack-dev;gfortran;blas-dev;eigen-dev;freetype-dev;glew-dev;harfbuzz-dev;hdf5-dev;libdc1394-dev;libtbb-dev;mesa-dev;openexr-dev;openjpeg-dev;uchardet-dev" - skip-binary: aiohttp;charset-normalizer;grpcio;multidict;SQLAlchemy;protobuf;pydantic;pymicro-vad;yarl + skip-binary: aiohttp;charset-normalizer;grpcio;multidict;SQLAlchemy;propcache;protobuf;pydantic;pymicro-vad;yarl constraints: "homeassistant/package_constraints.txt" requirements-diff: "requirements_diff.txt" requirements: "requirements_old-cython.txt" @@ -234,7 +234,7 @@ jobs: wheels-key: ${{ secrets.WHEELS_KEY }} env-file: true apk: "bluez-dev;libffi-dev;openssl-dev;glib-dev;eudev-dev;libxml2-dev;libxslt-dev;libpng-dev;libjpeg-turbo-dev;tiff-dev;cups-dev;gmp-dev;mpfr-dev;mpc1-dev;ffmpeg-dev;gammu-dev;yaml-dev;openblas-dev;fftw-dev;lapack-dev;gfortran;blas-dev;eigen-dev;freetype-dev;glew-dev;harfbuzz-dev;hdf5-dev;libdc1394-dev;libtbb-dev;mesa-dev;openexr-dev;openjpeg-dev;uchardet-dev;nasm" - skip-binary: aiohttp;charset-normalizer;grpcio;multidict;SQLAlchemy;protobuf;pydantic;pymicro-vad;yarl + skip-binary: aiohttp;charset-normalizer;grpcio;multidict;SQLAlchemy;propcache;protobuf;pydantic;pymicro-vad;yarl constraints: "homeassistant/package_constraints.txt" requirements-diff: "requirements_diff.txt" requirements: "requirements_all.txtaa" @@ -248,7 +248,7 @@ jobs: wheels-key: ${{ secrets.WHEELS_KEY }} env-file: true apk: "bluez-dev;libffi-dev;openssl-dev;glib-dev;eudev-dev;libxml2-dev;libxslt-dev;libpng-dev;libjpeg-turbo-dev;tiff-dev;cups-dev;gmp-dev;mpfr-dev;mpc1-dev;ffmpeg-dev;gammu-dev;yaml-dev;openblas-dev;fftw-dev;lapack-dev;gfortran;blas-dev;eigen-dev;freetype-dev;glew-dev;harfbuzz-dev;hdf5-dev;libdc1394-dev;libtbb-dev;mesa-dev;openexr-dev;openjpeg-dev;uchardet-dev;nasm" - skip-binary: aiohttp;charset-normalizer;grpcio;multidict;SQLAlchemy;protobuf;pydantic;pymicro-vad;yarl + skip-binary: aiohttp;charset-normalizer;grpcio;multidict;SQLAlchemy;propcache;protobuf;pydantic;pymicro-vad;yarl constraints: "homeassistant/package_constraints.txt" requirements-diff: "requirements_diff.txt" requirements: "requirements_all.txtab" @@ -262,7 +262,7 @@ jobs: wheels-key: ${{ secrets.WHEELS_KEY }} env-file: true apk: "bluez-dev;libffi-dev;openssl-dev;glib-dev;eudev-dev;libxml2-dev;libxslt-dev;libpng-dev;libjpeg-turbo-dev;tiff-dev;cups-dev;gmp-dev;mpfr-dev;mpc1-dev;ffmpeg-dev;gammu-dev;yaml-dev;openblas-dev;fftw-dev;lapack-dev;gfortran;blas-dev;eigen-dev;freetype-dev;glew-dev;harfbuzz-dev;hdf5-dev;libdc1394-dev;libtbb-dev;mesa-dev;openexr-dev;openjpeg-dev;uchardet-dev;nasm" - skip-binary: aiohttp;charset-normalizer;grpcio;multidict;SQLAlchemy;protobuf;pydantic;pymicro-vad;yarl + skip-binary: aiohttp;charset-normalizer;grpcio;multidict;SQLAlchemy;propcache;protobuf;pydantic;pymicro-vad;yarl constraints: "homeassistant/package_constraints.txt" requirements-diff: "requirements_diff.txt" requirements: "requirements_all.txtac" From 64a3be5fe32f1de79cf10b716446b1583e0bfb9c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 2 Oct 2024 12:36:59 -0500 Subject: [PATCH 3/6] fixes --- homeassistant/backports/functools.py | 4 +--- tests/test_config_entries.py | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/homeassistant/backports/functools.py b/homeassistant/backports/functools.py index c838ca7f680c4e..bad4236f9c8fe2 100644 --- a/homeassistant/backports/functools.py +++ b/homeassistant/backports/functools.py @@ -9,9 +9,7 @@ from __future__ import annotations -from functools import partial - -from propcache import cached_property as _cached_property +from functools import cached_property as _cached_property, partial from homeassistant.helpers.deprecation import ( DeprecatedAlias, diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 4efa5887a8f5ba..0e3a01741763e5 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -11,7 +11,6 @@ from freezegun import freeze_time from freezegun.api import FrozenDateTimeFactory -from propcache import cached_property import pytest from syrupy.assertion import SnapshotAssertion @@ -966,7 +965,7 @@ async def test_as_dict(snapshot: SnapshotAssertion) -> None: if ( key.startswith("__") or callable(func) - or type(func) in (cached_property, property) + or type(func).__name__ in ("cached_property", "property") ): continue assert key in dict_repr or key in excluded_from_dict From 548866177a5f7c442f347b1d9a74165a5ce3c959 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 2 Oct 2024 13:01:53 -0500 Subject: [PATCH 4/6] avoid touching backports since its no longer used --- tests/test_backports.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_backports.py b/tests/test_backports.py index 41dbabc0fdba34..4df0a9e3f573f2 100644 --- a/tests/test_backports.py +++ b/tests/test_backports.py @@ -3,10 +3,10 @@ from __future__ import annotations from enum import StrEnum +from functools import cached_property from types import ModuleType from typing import Any -from propcache import cached_property import pytest from homeassistant.backports import ( From 5dad2f2a2ca272f3253f9d774d1be7fc7b9b6422 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 3 Oct 2024 08:32:10 -0500 Subject: [PATCH 5/6] ruff fixes --- homeassistant/components/date/__init__.py | 4 ++-- homeassistant/components/datetime/__init__.py | 4 ++-- homeassistant/components/time/__init__.py | 4 ++-- pyproject.toml | 4 ++++ 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/date/__init__.py b/homeassistant/components/date/__init__.py index 2f83de1233f50b..622ec574542bb1 100644 --- a/homeassistant/components/date/__init__.py +++ b/homeassistant/components/date/__init__.py @@ -80,13 +80,13 @@ class DateEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): @final def device_class(self) -> None: """Return the device class for the entity.""" - return + return None @cached_property @final def state_attributes(self) -> None: """Return the state attributes.""" - return + return None @property @final diff --git a/homeassistant/components/datetime/__init__.py b/homeassistant/components/datetime/__init__.py index 5dfd1cdc25d381..8aef34ddcbd9f4 100644 --- a/homeassistant/components/datetime/__init__.py +++ b/homeassistant/components/datetime/__init__.py @@ -89,13 +89,13 @@ class DateTimeEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): @final def device_class(self) -> None: """Return entity device class.""" - return + return None @cached_property @final def state_attributes(self) -> None: """Return the state attributes.""" - return + return None @property @final diff --git a/homeassistant/components/time/__init__.py b/homeassistant/components/time/__init__.py index cfd0626aeb4e36..473472356d4d63 100644 --- a/homeassistant/components/time/__init__.py +++ b/homeassistant/components/time/__init__.py @@ -80,13 +80,13 @@ class TimeEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): @final def device_class(self) -> None: """Return the device class for the entity.""" - return + return None @cached_property @final def state_attributes(self) -> None: """Return the state attributes.""" - return + return None @property @final diff --git a/pyproject.toml b/pyproject.toml index cbb146c85a8cb2..b5bda984c905ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -921,3 +921,7 @@ split-on-trailing-comma = false [tool.ruff.lint.mccabe] max-complexity = 25 + +[tool.ruff.lint.pydocstyle] +property-decorators = ["propcache.cached_property"] + From 01abc6b10a97f06bba5c48de4b08c9a6a1e53c79 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 3 Oct 2024 11:48:32 -0500 Subject: [PATCH 6/6] 0.1.0 --- homeassistant/package_constraints.txt | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index f60b398660c365..21c7d4a61f0973 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -44,7 +44,7 @@ orjson==3.10.7 packaging>=23.1 paho-mqtt==1.6.1 Pillow==10.4.0 -propcache==0.0.0 +propcache==0.1.0 psutil-home-assistant==0.0.1 PyJWT==2.9.0 pymicro-vad==1.0.1 diff --git a/pyproject.toml b/pyproject.toml index c5e78157976d52..52f3d2f7518222 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,7 +55,7 @@ dependencies = [ # PyJWT has loose dependency. We want the latest one. "cryptography==43.0.1", "Pillow==10.4.0", - "propcache==0.0.0", + "propcache==0.1.0", "pyOpenSSL==24.2.1", "orjson==3.10.7", "packaging>=23.1", diff --git a/requirements.txt b/requirements.txt index 217f479b786d46..b4a75682228555 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,7 +28,7 @@ mashumaro==3.13.1 PyJWT==2.9.0 cryptography==43.0.1 Pillow==10.4.0 -propcache==0.0.0 +propcache==0.1.0 pyOpenSSL==24.2.1 orjson==3.10.7 packaging>=23.1