Add support for attribute caching to the lawn_mower platform (#106335)

This commit is contained in:
J. Nick Koston 2023-12-23 14:28:25 -10:00 committed by GitHub
parent 63f3c23968
commit 38e79bbf9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,7 @@ from __future__ import annotations
from datetime import timedelta
import logging
from typing import final
from typing import TYPE_CHECKING, final
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -24,6 +24,12 @@ from .const import (
LawnMowerEntityFeature,
)
if TYPE_CHECKING:
from functools import cached_property
else:
from homeassistant.backports.functools import cached_property
SCAN_INTERVAL = timedelta(seconds=60)
_LOGGER = logging.getLogger(__name__)
@ -68,7 +74,13 @@ class LawnMowerEntityEntityDescription(EntityDescription, frozen_or_thawed=True)
"""A class that describes lawn mower entities."""
class LawnMowerEntity(Entity):
CACHED_PROPERTIES_WITH_ATTR_ = {
"activity",
"supported_features",
}
class LawnMowerEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
"""Base class for lawn mower entities."""
entity_description: LawnMowerEntityEntityDescription
@ -83,12 +95,12 @@ class LawnMowerEntity(Entity):
return None
return str(activity)
@property
@cached_property
def activity(self) -> LawnMowerActivity | None:
"""Return the current lawn mower activity."""
return self._attr_activity
@property
@cached_property
def supported_features(self) -> LawnMowerEntityFeature:
"""Flag lawn mower features that are supported."""
return self._attr_supported_features