Skip to content

Commit

Permalink
Fix Yamaha MusicCast zone sleep select entity (#87041)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored Jan 31, 2023
1 parent ee30f5a commit 5b728a4
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 33 deletions.
9 changes: 0 additions & 9 deletions homeassistant/components/yamaha_musiccast/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,3 @@
"zone_LINK_CONTROL": "zone_link_control",
"zone_LINK_AUDIO_DELAY": "zone_link_audio_delay",
}

ZONE_SLEEP_STATE_MAPPING = {
"off": "off",
"30 min": "30_min",
"60 min": "60_min",
"90 min": "90_min",
"120 min": "120_min",
}
STATE_ZONE_SLEEP_MAPPING = {val: key for key, val in ZONE_SLEEP_STATE_MAPPING.items()}
2 changes: 1 addition & 1 deletion homeassistant/components/yamaha_musiccast/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "MusicCast",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/yamaha_musiccast",
"requirements": ["aiomusiccast==0.14.4"],
"requirements": ["aiomusiccast==0.14.7"],
"ssdp": [
{
"manufacturer": "Yamaha Corporation"
Expand Down
23 changes: 2 additions & 21 deletions homeassistant/components/yamaha_musiccast/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import DOMAIN, MusicCastCapabilityEntity, MusicCastDataUpdateCoordinator
from .const import (
STATE_ZONE_SLEEP_MAPPING,
TRANSLATION_KEY_MAPPING,
ZONE_SLEEP_STATE_MAPPING,
)
from .const import TRANSLATION_KEY_MAPPING


async def async_setup_entry(
Expand Down Expand Up @@ -48,10 +44,6 @@ class SelectableCapapility(MusicCastCapabilityEntity, SelectEntity):
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]
# If the translation key is "zone_sleep", we need to translate
# Home Assistant state back to the MusicCast value
if self.translation_key == "zone_sleep":
value = STATE_ZONE_SLEEP_MAPPING[value]
await self.capability.set(value)

@property
Expand All @@ -62,20 +54,9 @@ def translation_key(self) -> str | None:
@property
def options(self) -> list[str]:
"""Return the list possible options."""
# If the translation key is "zone_sleep", we need to translate
# the options to make them compatible with Home Assistant
if self.translation_key == "zone_sleep":
return list(STATE_ZONE_SLEEP_MAPPING)
return list(self.capability.options.values())

@property
def current_option(self) -> str | None:
"""Return the currently selected option."""
# If the translation key is "zone_sleep", we need to translate
# the value to make it compatible with Home Assistant
if (
value := self.capability.current
) is not None and self.translation_key == "zone_sleep":
return ZONE_SLEEP_STATE_MAPPING[value]

return value
return self.capability.options.get(self.capability.current)
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ aiolyric==1.0.9
aiomodernforms==0.1.8

# homeassistant.components.yamaha_musiccast
aiomusiccast==0.14.4
aiomusiccast==0.14.7

# homeassistant.components.nanoleaf
aionanoleaf==0.2.1
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ aiolyric==1.0.9
aiomodernforms==0.1.8

# homeassistant.components.yamaha_musiccast
aiomusiccast==0.14.4
aiomusiccast==0.14.7

# homeassistant.components.nanoleaf
aionanoleaf==0.2.1
Expand Down

0 comments on commit 5b728a4

Please sign in to comment.