Skip to content

Commit

Permalink
Implement sound mode support for songpal
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed May 31, 2018
1 parent 29659cb commit bacb6b0
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions homeassistant/components/media_player/songpal.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from homeassistant.components.media_player import (
PLATFORM_SCHEMA, SUPPORT_SELECT_SOURCE, SUPPORT_TURN_OFF,
SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_STEP, SUPPORT_VOLUME_SET,
SUPPORT_TURN_ON, MediaPlayerDevice, DOMAIN)
SUPPORT_TURN_ON, SUPPORT_SELECT_SOUND_MODE, MediaPlayerDevice, DOMAIN)
from homeassistant.const import (
CONF_NAME, STATE_ON, STATE_OFF, ATTR_ENTITY_ID)
from homeassistant.exceptions import PlatformNotReady
Expand All @@ -21,7 +21,8 @@

SUPPORT_SONGPAL = SUPPORT_VOLUME_SET | SUPPORT_VOLUME_STEP | \
SUPPORT_VOLUME_MUTE | SUPPORT_SELECT_SOURCE | \
SUPPORT_TURN_ON | SUPPORT_TURN_OFF
SUPPORT_TURN_ON | SUPPORT_TURN_OFF | \
SUPPORT_SELECT_SOUND_MODE

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -171,6 +172,15 @@ async def async_update(self):
_LOGGER.debug("Got ins: %s", inputs)
self._sources = inputs


try:
soundfields = await self.dev.get_soundfield()
self._soundmodes = {x.value:x.title for x in soundfields.candidate}
self._active_soundmode = self._soundmodes[soundfields.currentValue]
except SongpalException:
self._soundmodes = None
self._active_soundmode = None

self._available = True
except SongpalException as ex:
# if we were available, print out the exception
Expand All @@ -192,6 +202,22 @@ def source_list(self):
"""Return list of available sources."""
return [x.title for x in self._sources]

async def async_select_sound_mode(self, sound_mode):
"""Select sound mode."""
reversed = {v: k for k, v in self._soundmodes.items()}
return await self.dev.set_soundfield(reversed[sound_mode])

@property
def sound_mode(self):
"""Return currently active sound mode."""
return self._active_soundmode

@property
def sound_mode_list(self):
"""Return supported sound modes."""
if self._soundmodes is not None:
return list(self._soundmodes.keys())

@property
def state(self):
"""Return current state."""
Expand Down Expand Up @@ -249,4 +275,7 @@ def is_volume_muted(self):
@property
def supported_features(self):
"""Return supported features."""
return SUPPORT_SONGPAL
supported = SUPPORT_SONGPAL
supported |= (self._soundmodes is not None and
SUPPORT_SELECT_SOUND_MODE)
return supported

0 comments on commit bacb6b0

Please sign in to comment.