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