diff --git a/pymusiccast/__init__.py b/pymusiccast/__init__.py index 1658331..3078670 100644 --- a/pymusiccast/__init__.py +++ b/pymusiccast/__init__.py @@ -73,14 +73,12 @@ def name(self, name): def healthy_update_timer(self): """Check state of update timer.""" state = None - if self.update_status_timer and self.update_status_timer.is_alive(): _LOGGER.debug("%s: Timer: healthy", self._ip_address) state = True else: _LOGGER.debug("%s: Timer: not healthy", self._ip_address) state = False - return state def initialize(self): @@ -176,14 +174,12 @@ def handle_netusb(self, message): """Handle 'netusb' in message.""" # _LOGGER.debug("message: {}".format(message)) needs_update = 0 - if self._yamaha: if "play_info_updated" in message: play_info = self.get_play_info() # _LOGGER.debug(play_info) if play_info: new_media_status = MediaStatus(play_info, self._ip_address) - if self._yamaha.media_status != new_media_status: # we need to send an update upwards self._yamaha.new_media_status(new_media_status) @@ -199,12 +195,10 @@ def handle_netusb(self, message): new_status = STATE_PAUSED else: new_status = STATE_UNKNOWN - if self._yamaha.status is not new_status: _LOGGER.debug("%s: playback: %s", self._ip_address, new_status) self._yamaha.status = new_status needs_update += 1 - return needs_update def handle_features(self, device_features): @@ -219,6 +213,9 @@ def handle_features(self, device_features): input_list = zone.get("input_list", []) input_list.sort() self.zones[zone_id].source_list = input_list + sound_program_list = zone.get("sound_program_list", []) + sound_program_list.sort() + self.zones[zone_id].sound_mode_list = sound_program_list def handle_event(self, message): """Dispatch all event messages.""" diff --git a/pymusiccast/const.py b/pymusiccast/const.py index 3faf16e..f593a5a 100644 --- a/pymusiccast/const.py +++ b/pymusiccast/const.py @@ -21,6 +21,10 @@ "setVolume": "http://{}/YamahaExtendedControl/v1/{}/setVolume", "startDistribution": "http://{}/YamahaExtendedControl/v1/dist/startDistribution", "stopDistribution": "http://{}/YamahaExtendedControl/v1/dist/stopDistribution", + "getSoundPrograms": ( + "http://{}/YamahaExtendedControl" "/v1/{}/getSoundProgramList" + ), + "setSoundProgram": "http://{}/YamahaExtendedControl/v1/{}/setSoundProgram", } STATE_UNKNOWN = "unknown" diff --git a/pymusiccast/zone.py b/pymusiccast/zone.py index 55c4465..d729f53 100644 --- a/pymusiccast/zone.py +++ b/pymusiccast/zone.py @@ -203,3 +203,22 @@ def update_dist_info(self, new_dist=None): group_members = new_dist.get("group_members") self._yamaha.group_members = group_members self._status_sent = self.update_hass() + + @property + def sound_mode_list(self): + """Return sound_mode_list.""" + return self._yamaha.sound_mode_list + + @sound_mode_list.setter + def sound_mode_list(self, sound_mode_list): + """Sets sound_mode_list.""" + self._yamaha.sound_mode_list = sound_mode_list + + def set_sound_program(self, sound_program): + """Send sound program command.""" + req_url = ENDPOINTS["setSoundProgram"].format( + self.ip_address, self.zone_id, sound_program + ) + self._yamaha._sound_mode = sound_program + params = {"program": sound_program} + return request(req_url, params=params)