New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Yamaha MusicCast Select Entities #60645
Merged
emontnemery
merged 5 commits into
home-assistant:dev
from
micha91:musiccast-select-entities
Dec 6, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0c2abe1
Add select entity for Yamaha MusicCast Capabilities
micha91 bedcee2
Add musiccast select to .coveragerc
micha91 fa0a776
Move status strings to string.select.json and auto generate the engli…
micha91 fa76b09
Make all device classes lower case
micha91 db3f143
Use platform enum to add select
micha91 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
52 changes: 52 additions & 0 deletions
52
homeassistant/components/yamaha_musiccast/strings.select.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
homeassistant/components/yamaha_musiccast/translations/select.en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
micha91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"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" | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please define the valid device classes in a container here in the platform and validate the device class before returning it. The device class is a Home Assistant API so we need to be in control and make sure it is correct before returning it.