mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add support for attribute caching to the lawn_mower platform (#106335)
This commit is contained in:
parent
63f3c23968
commit
38e79bbf9d
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import final
|
from typing import TYPE_CHECKING, final
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -24,6 +24,12 @@ from .const import (
|
|||||||
LawnMowerEntityFeature,
|
LawnMowerEntityFeature,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from functools import cached_property
|
||||||
|
else:
|
||||||
|
from homeassistant.backports.functools import cached_property
|
||||||
|
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=60)
|
SCAN_INTERVAL = timedelta(seconds=60)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -68,7 +74,13 @@ class LawnMowerEntityEntityDescription(EntityDescription, frozen_or_thawed=True)
|
|||||||
"""A class that describes lawn mower entities."""
|
"""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."""
|
"""Base class for lawn mower entities."""
|
||||||
|
|
||||||
entity_description: LawnMowerEntityEntityDescription
|
entity_description: LawnMowerEntityEntityDescription
|
||||||
@ -83,12 +95,12 @@ class LawnMowerEntity(Entity):
|
|||||||
return None
|
return None
|
||||||
return str(activity)
|
return str(activity)
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def activity(self) -> LawnMowerActivity | None:
|
def activity(self) -> LawnMowerActivity | None:
|
||||||
"""Return the current lawn mower activity."""
|
"""Return the current lawn mower activity."""
|
||||||
return self._attr_activity
|
return self._attr_activity
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def supported_features(self) -> LawnMowerEntityFeature:
|
def supported_features(self) -> LawnMowerEntityFeature:
|
||||||
"""Flag lawn mower features that are supported."""
|
"""Flag lawn mower features that are supported."""
|
||||||
return self._attr_supported_features
|
return self._attr_supported_features
|
||||||
|
Loading…
x
Reference in New Issue
Block a user