Skip to content

Commit

Permalink
Add support for attribute caching to the remote platform
Browse files Browse the repository at this point in the history
Builds on #100601
  • Loading branch information
bdraco committed Dec 22, 2023
1 parent 3a744d3 commit 7eed8e7
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions homeassistant/components/remote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from enum import IntFlag
import functools as ft
import logging
from typing import Any, final
from typing import TYPE_CHECKING, Any, final

import voluptuous as vol

Expand Down Expand Up @@ -35,6 +35,12 @@
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import bind_hass

if TYPE_CHECKING:
from functools import cached_property
else:
from homeassistant.backports.functools import cached_property


_LOGGER = logging.getLogger(__name__)

ATTR_ACTIVITY = "activity"
Expand Down Expand Up @@ -174,25 +180,32 @@ class RemoteEntityDescription(ToggleEntityDescription, frozen_or_thawed=True):
"""A class that describes remote entities."""


class RemoteEntity(ToggleEntity):
CACHED_PROPERTIES_WITH_ATTR_ = {
"supported_features",
"current_activity",
"activity_list",
}


class RemoteEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
"""Base class for remote entities."""

entity_description: RemoteEntityDescription
_attr_activity_list: list[str] | None = None
_attr_current_activity: str | None = None
_attr_supported_features: RemoteEntityFeature = RemoteEntityFeature(0)

@property
@cached_property
def supported_features(self) -> RemoteEntityFeature:
"""Flag supported features."""
return self._attr_supported_features

@property
@cached_property
def current_activity(self) -> str | None:
"""Active activity."""
return self._attr_current_activity

@property
@cached_property
def activity_list(self) -> list[str] | None:
"""List of available activities."""
return self._attr_activity_list
Expand Down

0 comments on commit 7eed8e7

Please sign in to comment.