diff --git a/homeassistant/components/harmony/select.py b/homeassistant/components/harmony/select.py index 3728c4b17a4..a3f059d2c00 100644 --- a/homeassistant/components/harmony/select.py +++ b/homeassistant/components/harmony/select.py @@ -16,6 +16,8 @@ from .subscriber import HarmonyCallback _LOGGER = logging.getLogger(__name__) +TRANSLATABLE_POWER_OFF = "power_off" + async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback @@ -31,6 +33,8 @@ async def async_setup_entry( class HarmonyActivitySelect(HarmonyEntity, SelectEntity): """Select representation of a Harmony activities.""" + _attr_device_class = f"{DOMAIN}__activities" + def __init__(self, name: str, data: HarmonyData) -> None: """Initialize HarmonyActivitySelect class.""" super().__init__(data=data) @@ -42,23 +46,27 @@ class HarmonyActivitySelect(HarmonyEntity, SelectEntity): @property def icon(self) -> str: """Return a representative icon.""" - if not self.available or self.current_option == ACTIVITY_POWER_OFF: + if not self.available or self.current_option == TRANSLATABLE_POWER_OFF: return "mdi:remote-tv-off" return "mdi:remote-tv" @property def options(self) -> list[str]: """Return a set of selectable options.""" - return [ACTIVITY_POWER_OFF] + sorted(self._data.activity_names) + return [TRANSLATABLE_POWER_OFF] + sorted(self._data.activity_names) @property def current_option(self) -> str | None: """Return the current activity.""" _, activity_name = self._data.current_activity + if activity_name == ACTIVITY_POWER_OFF: + return TRANSLATABLE_POWER_OFF return activity_name async def async_select_option(self, option: str) -> None: """Change the current activity.""" + if option == TRANSLATABLE_POWER_OFF: + await self._data.async_start_activity(ACTIVITY_POWER_OFF) await self._data.async_start_activity(option) async def async_added_to_hass(self) -> None: diff --git a/homeassistant/components/harmony/strings.select.json b/homeassistant/components/harmony/strings.select.json new file mode 100644 index 00000000000..5dbdf1a1c3d --- /dev/null +++ b/homeassistant/components/harmony/strings.select.json @@ -0,0 +1,7 @@ +{ + "state": { + "harmony__activities": { + "power_off": "Power Off" + } + } +} diff --git a/homeassistant/components/harmony/translations/select.en.json b/homeassistant/components/harmony/translations/select.en.json new file mode 100644 index 00000000000..5dbdf1a1c3d --- /dev/null +++ b/homeassistant/components/harmony/translations/select.en.json @@ -0,0 +1,7 @@ +{ + "state": { + "harmony__activities": { + "power_off": "Power Off" + } + } +} diff --git a/tests/components/harmony/test_select.py b/tests/components/harmony/test_select.py index 4607f035893..60bb85ed0c3 100644 --- a/tests/components/harmony/test_select.py +++ b/tests/components/harmony/test_select.py @@ -9,6 +9,7 @@ from homeassistant.components.select import ( SERVICE_SELECT_OPTION, ) from homeassistant.const import ( + ATTR_DEVICE_CLASS, ATTR_ENTITY_ID, CONF_HOST, CONF_NAME, @@ -68,11 +69,12 @@ async def test_options(mock_hc, hass, mock_write_config): # assert we have all options state = hass.states.get(ENTITY_SELECT) assert state.attributes.get("options") == [ - "PowerOff", + "power_off", "Nile-TV", "Play Music", "Watch TV", ] + assert state.attributes.get(ATTR_DEVICE_CLASS) == "harmony__activities" async def test_select_option(mock_hc, hass, mock_write_config): @@ -94,10 +96,10 @@ async def test_select_option(mock_hc, hass, mock_write_config): assert hass.states.is_state(ENTITY_REMOTE, STATE_ON) assert hass.states.is_state(ENTITY_SELECT, "Play Music") - # turn off harmony by selecting PowerOff activity - await _select_option_and_wait(hass, ENTITY_SELECT, "PowerOff") + # turn off harmony by selecting power_off activity + await _select_option_and_wait(hass, ENTITY_SELECT, "power_off") assert hass.states.is_state(ENTITY_REMOTE, STATE_OFF) - assert hass.states.is_state(ENTITY_SELECT, "PowerOff") + assert hass.states.is_state(ENTITY_SELECT, "power_off") async def _select_option_and_wait(hass, entity, option):