Add activity properties to remote entity model (#47237)
parent
6019bcf9d1
commit
32fe4fa378
|
@ -6,9 +6,7 @@ PLATFORMS = ["remote", "switch"]
|
|||
UNIQUE_ID = "unique_id"
|
||||
ACTIVITY_POWER_OFF = "PowerOff"
|
||||
HARMONY_OPTIONS_UPDATE = "harmony_options_update"
|
||||
ATTR_ACTIVITY_LIST = "activity_list"
|
||||
ATTR_DEVICES_LIST = "devices_list"
|
||||
ATTR_LAST_ACTIVITY = "last_activity"
|
||||
ATTR_CURRENT_ACTIVITY = "current_activity"
|
||||
ATTR_ACTIVITY_STARTING = "activity_starting"
|
||||
PREVIOUS_ACTIVE_ACTIVITY = "Previous Active Activity"
|
||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.components.remote import (
|
|||
ATTR_HOLD_SECS,
|
||||
ATTR_NUM_REPEATS,
|
||||
DEFAULT_DELAY_SECS,
|
||||
SUPPORT_ACTIVITY,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
|
@ -24,9 +25,7 @@ from homeassistant.helpers.restore_state import RestoreEntity
|
|||
from .connection_state import ConnectionStateMixin
|
||||
from .const import (
|
||||
ACTIVITY_POWER_OFF,
|
||||
ATTR_ACTIVITY_LIST,
|
||||
ATTR_ACTIVITY_STARTING,
|
||||
ATTR_CURRENT_ACTIVITY,
|
||||
ATTR_DEVICES_LIST,
|
||||
ATTR_LAST_ACTIVITY,
|
||||
DOMAIN,
|
||||
|
@ -100,6 +99,11 @@ class HarmonyRemote(ConnectionStateMixin, remote.RemoteEntity, RestoreEntity):
|
|||
self._last_activity = None
|
||||
self._config_path = out_path
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Supported features for the remote."""
|
||||
return SUPPORT_ACTIVITY
|
||||
|
||||
async def _async_update_options(self, data):
|
||||
"""Change options when the options flow does."""
|
||||
if ATTR_DELAY_SECS in data:
|
||||
|
@ -178,13 +182,21 @@ class HarmonyRemote(ConnectionStateMixin, remote.RemoteEntity, RestoreEntity):
|
|||
"""Return the fact that we should not be polled."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def current_activity(self):
|
||||
"""Return the current activity."""
|
||||
return self._current_activity
|
||||
|
||||
@property
|
||||
def activity_list(self):
|
||||
"""Return the available activities."""
|
||||
return self._data.activity_names
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Add platform specific attributes."""
|
||||
return {
|
||||
ATTR_ACTIVITY_STARTING: self._activity_starting,
|
||||
ATTR_CURRENT_ACTIVITY: self._current_activity,
|
||||
ATTR_ACTIVITY_LIST: self._data.activity_names,
|
||||
ATTR_DEVICES_LIST: self._data.device_names,
|
||||
ATTR_LAST_ACTIVITY: self._last_activity,
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
from datetime import timedelta
|
||||
import functools as ft
|
||||
import logging
|
||||
from typing import Any, Iterable, cast
|
||||
from typing import Any, Dict, Iterable, List, Optional, cast
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -30,6 +30,8 @@ from homeassistant.loader import bind_hass
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_ACTIVITY = "activity"
|
||||
ATTR_ACTIVITY_LIST = "activity_list"
|
||||
ATTR_CURRENT_ACTIVITY = "current_activity"
|
||||
ATTR_COMMAND_TYPE = "command_type"
|
||||
ATTR_DEVICE = "device"
|
||||
ATTR_NUM_REPEATS = "num_repeats"
|
||||
|
@ -56,6 +58,7 @@ DEFAULT_HOLD_SECS = 0
|
|||
|
||||
SUPPORT_LEARN_COMMAND = 1
|
||||
SUPPORT_DELETE_COMMAND = 2
|
||||
SUPPORT_ACTIVITY = 4
|
||||
|
||||
REMOTE_SERVICE_ACTIVITY_SCHEMA = make_entity_service_schema(
|
||||
{vol.Optional(ATTR_ACTIVITY): cv.string}
|
||||
|
@ -143,6 +146,27 @@ class RemoteEntity(ToggleEntity):
|
|||
"""Flag supported features."""
|
||||
return 0
|
||||
|
||||
@property
|
||||
def current_activity(self) -> Optional[str]:
|
||||
"""Active activity."""
|
||||
return None
|
||||
|
||||
@property
|
||||
def activity_list(self) -> Optional[List[str]]:
|
||||
"""List of available activities."""
|
||||
return None
|
||||
|
||||
@property
|
||||
def state_attributes(self) -> Optional[Dict[str, Any]]:
|
||||
"""Return optional state attributes."""
|
||||
if not self.supported_features & SUPPORT_ACTIVITY:
|
||||
return None
|
||||
|
||||
return {
|
||||
ATTR_ACTIVITY_LIST: self.activity_list,
|
||||
ATTR_CURRENT_ACTIVITY: self.current_activity,
|
||||
}
|
||||
|
||||
def send_command(self, command: Iterable[str], **kwargs: Any) -> None:
|
||||
"""Send commands to a device."""
|
||||
raise NotImplementedError()
|
||||
|
|
Loading…
Reference in New Issue