diff --git a/homeassistant/components/russound_rnet/media_player.py b/homeassistant/components/russound_rnet/media_player.py index 6782d783a83..7a384656b66 100644 --- a/homeassistant/components/russound_rnet/media_player.py +++ b/homeassistant/components/russound_rnet/media_player.py @@ -82,15 +82,11 @@ class RussoundRNETDevice(MediaPlayerEntity): def __init__(self, hass, russ, sources, zone_id, extra): """Initialise the Russound RNET device.""" - self._name = extra["name"] + self._attr_name = extra["name"] self._russ = russ - self._sources = sources + self._attr_source_list = sources self._zone_id = zone_id - self._state = None - self._volume = None - self._source = None - def update(self) -> None: """Retrieve latest state.""" # Updated this function to make a single call to get_zone_info, so that @@ -101,47 +97,21 @@ class RussoundRNETDevice(MediaPlayerEntity): if ret is not None: _LOGGER.debug("Updating status for zone %s", self._zone_id) if ret[0] == 0: - self._state = MediaPlayerState.OFF + self._attr_state = MediaPlayerState.OFF else: - self._state = MediaPlayerState.ON - self._volume = ret[2] * 2 / 100.0 + self._attr_state = MediaPlayerState.ON + self._attr_volume_level = ret[2] * 2 / 100.0 # Returns 0 based index for source. index = ret[1] # Possibility exists that user has defined list of all sources. # If a source is set externally that is beyond the defined list then # an exception will be thrown. # In this case return and unknown source (None) - try: - self._source = self._sources[index] - except IndexError: - self._source = None + if self.source_list and 0 <= index < len(self.source_list): + self._attr_source = self.source_list[index] else: _LOGGER.error("Could not update status for zone %s", self._zone_id) - @property - def name(self): - """Return the name of the zone.""" - return self._name - - @property - def state(self): - """Return the state of the device.""" - return self._state - - @property - def source(self): - """Get the currently selected source.""" - return self._source - - @property - def volume_level(self): - """Volume level of the media player (0..1). - - Value is returned based on a range (0..100). - Therefore float divide by 100 to get to the required range. - """ - return self._volume - def set_volume_level(self, volume: float) -> None: """Set volume level. Volume has a range (0..1). @@ -164,12 +134,7 @@ class RussoundRNETDevice(MediaPlayerEntity): def select_source(self, source: str) -> None: """Set the input source.""" - if source in self._sources: - index = self._sources.index(source) + if self.source_list and source in self.source_list: + index = self.source_list.index(source) # 0 based value for source self._russ.set_source("1", self._zone_id, index) - - @property - def source_list(self): - """Return a list of available input sources.""" - return self._sources