Add Yamaha MusicCast Select Entities (#60645)
* Add select entity for Yamaha MusicCast Capabilities * Add musiccast select to .coveragerc * Move status strings to string.select.json and auto generate the english translations from it. Let the device class start with yamaha_musiccast__. * Make all device classes lower case * Use platform enum to add select
This commit is contained in:
parent
da5374614f
commit
f94085c83e
5 changed files with 169 additions and 1 deletions
|
@ -1293,6 +1293,7 @@ omit =
|
|||
homeassistant/components/yamaha_musiccast/__init__.py
|
||||
homeassistant/components/yamaha_musiccast/media_player.py
|
||||
homeassistant/components/yamaha_musiccast/number.py
|
||||
homeassistant/components/yamaha_musiccast/select.py
|
||||
homeassistant/components/yandex_transport/*
|
||||
homeassistant/components/yeelightsunflower/light.py
|
||||
homeassistant/components/yi/camera.py
|
||||
|
|
|
@ -30,7 +30,7 @@ from .const import (
|
|||
ENTITY_CATEGORY_MAPPING,
|
||||
)
|
||||
|
||||
PLATFORMS = [Platform.MEDIA_PLAYER, Platform.NUMBER]
|
||||
PLATFORMS = [Platform.MEDIA_PLAYER, Platform.NUMBER, Platform.SELECT]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
SCAN_INTERVAL = timedelta(seconds=60)
|
||||
|
|
63
homeassistant/components/yamaha_musiccast/select.py
Normal file
63
homeassistant/components/yamaha_musiccast/select.py
Normal file
|
@ -0,0 +1,63 @@
|
|||
"""The select entities for musiccast."""
|
||||
|
||||
from aiomusiccast.capabilities import OptionSetter
|
||||
|
||||
from homeassistant.components.select import SelectEntity
|
||||
from homeassistant.components.yamaha_musiccast import (
|
||||
DOMAIN,
|
||||
MusicCastCapabilityEntity,
|
||||
MusicCastDataUpdateCoordinator,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MusicCast select entities based on a config entry."""
|
||||
coordinator: MusicCastDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
select_entities = []
|
||||
|
||||
for capability in coordinator.data.capabilities:
|
||||
if isinstance(capability, OptionSetter):
|
||||
select_entities.append(SelectableCapapility(coordinator, capability))
|
||||
|
||||
for zone, data in coordinator.data.zones.items():
|
||||
for capability in data.capabilities:
|
||||
if isinstance(capability, OptionSetter):
|
||||
select_entities.append(
|
||||
SelectableCapapility(coordinator, capability, zone)
|
||||
)
|
||||
|
||||
async_add_entities(select_entities)
|
||||
|
||||
|
||||
class SelectableCapapility(MusicCastCapabilityEntity, SelectEntity):
|
||||
"""Representation of a MusicCast Select entity."""
|
||||
|
||||
capability: OptionSetter
|
||||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
"""Select the given option."""
|
||||
value = {val: key for key, val in self.capability.options.items()}[option]
|
||||
await self.capability.set(value)
|
||||
|
||||
@property
|
||||
def device_class(self) -> str:
|
||||
"""Return the ID of the capability, to identify the entity for translations."""
|
||||
return f"{DOMAIN}__{self.capability.id.lower()}"
|
||||
|
||||
@property
|
||||
def options(self):
|
||||
"""Return the list possible options."""
|
||||
return list(self.capability.options.values())
|
||||
|
||||
@property
|
||||
def current_option(self):
|
||||
"""Return the currently selected option."""
|
||||
return self.capability.options[self.capability.current]
|
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"state": {
|
||||
"yamaha_musiccast__dimmer": {
|
||||
"auto": "Auto"
|
||||
},
|
||||
"yamaha_musiccast__zone_sleep": {
|
||||
"off": "Off",
|
||||
"30 min": "30 Minutes",
|
||||
"60 min": "60 Minutes",
|
||||
"90 min": "90 Minutes",
|
||||
"120 min": "120 Minutes"
|
||||
},
|
||||
"yamaha_musiccast__zone_tone_control_mode": {
|
||||
"manual": "Manual",
|
||||
"auto": "Auto",
|
||||
"bypass": "Bypass"
|
||||
},
|
||||
"yamaha_musiccast__zone_surr_decoder_type": {
|
||||
"toggle": "Toggle",
|
||||
"auto": "Auto",
|
||||
"dolby_pl": "Dolby ProLogic",
|
||||
"dolby_pl2x_movie": "Dolby ProLogic 2x Movie",
|
||||
"dolby_pl2x_music": "Dolby ProLogic 2x Music",
|
||||
"dolby_pl2x_game": "Dolby ProLogic 2x Game",
|
||||
"dolby_surround": "Dolby Surround",
|
||||
"dts_neural_x": "DTS Neural:X",
|
||||
"dts_neo6_cinema": "DTS Neo:6 Cinema",
|
||||
"dts_neo6_music": "DTS Neo:6 Music"
|
||||
},
|
||||
"yamaha_musiccast__zone_equalizer_mode": {
|
||||
"manual": "Manual",
|
||||
"auto": "Auto",
|
||||
"bypass": "Bypass"
|
||||
},
|
||||
"yamaha_musiccast__zone_link_audio_quality": {
|
||||
"compressed": "Compressed",
|
||||
"uncompressed": "Uncompressed"
|
||||
},
|
||||
"yamaha_musiccast__zone_link_control": {
|
||||
"standard": "Standard",
|
||||
"speed": "Speed",
|
||||
"stability": "Stability"
|
||||
},
|
||||
"yamaha_musiccast__zone_link_audio_delay": {
|
||||
"audio_sync_on": "Audio Synchronization On",
|
||||
"audio_sync_off": "Audio Synchronization Off",
|
||||
"balanced": "Balanced",
|
||||
"lip_sync": "Lip Synchronization",
|
||||
"audio_sync": "Audio Synchronization"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"state": {
|
||||
"yamaha_musiccast__dimmer": {
|
||||
"auto": "Auto"
|
||||
},
|
||||
"yamaha_musiccast__zone_equalizer_mode": {
|
||||
"auto": "Auto",
|
||||
"bypass": "Bypass",
|
||||
"manual": "Manual"
|
||||
},
|
||||
"yamaha_musiccast__zone_link_audio_delay": {
|
||||
"audio_sync": "Audio Synchronization",
|
||||
"audio_sync_off": "Audio Synchronization Off",
|
||||
"audio_sync_on": "Audio Synchronization On",
|
||||
"balanced": "Balanced",
|
||||
"lip_sync": "Lip Synchronization"
|
||||
},
|
||||
"yamaha_musiccast__zone_link_audio_quality": {
|
||||
"compressed": "Compressed",
|
||||
"uncompressed": "Uncompressed"
|
||||
},
|
||||
"yamaha_musiccast__zone_link_control": {
|
||||
"speed": "Speed",
|
||||
"stability": "Stability",
|
||||
"standard": "Standard"
|
||||
},
|
||||
"yamaha_musiccast__zone_sleep": {
|
||||
"120 min": "120 Minutes",
|
||||
"30 min": "30 Minutes",
|
||||
"60 min": "60 Minutes",
|
||||
"90 min": "90 Minutes",
|
||||
"off": "Off"
|
||||
},
|
||||
"yamaha_musiccast__zone_surr_decoder_type": {
|
||||
"auto": "Auto",
|
||||
"dolby_pl": "Dolby ProLogic",
|
||||
"dolby_pl2x_game": "Dolby ProLogic 2x Game",
|
||||
"dolby_pl2x_movie": "Dolby ProLogic 2x Movie",
|
||||
"dolby_pl2x_music": "Dolby ProLogic 2x Music",
|
||||
"dolby_surround": "Dolby Surround",
|
||||
"dts_neo6_cinema": "DTS Neo:6 Cinema",
|
||||
"dts_neo6_music": "DTS Neo:6 Music",
|
||||
"dts_neural_x": "DTS Neural:X",
|
||||
"toggle": "Toggle"
|
||||
},
|
||||
"yamaha_musiccast__zone_tone_control_mode": {
|
||||
"auto": "Auto",
|
||||
"bypass": "Bypass",
|
||||
"manual": "Manual"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue