mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use _attr_state in russound met media player (#82839)
This commit is contained in:
parent
7a1907e540
commit
622466b3d3
@ -82,15 +82,11 @@ class RussoundRNETDevice(MediaPlayerEntity):
|
|||||||
|
|
||||||
def __init__(self, hass, russ, sources, zone_id, extra):
|
def __init__(self, hass, russ, sources, zone_id, extra):
|
||||||
"""Initialise the Russound RNET device."""
|
"""Initialise the Russound RNET device."""
|
||||||
self._name = extra["name"]
|
self._attr_name = extra["name"]
|
||||||
self._russ = russ
|
self._russ = russ
|
||||||
self._sources = sources
|
self._attr_source_list = sources
|
||||||
self._zone_id = zone_id
|
self._zone_id = zone_id
|
||||||
|
|
||||||
self._state = None
|
|
||||||
self._volume = None
|
|
||||||
self._source = None
|
|
||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
# Updated this function to make a single call to get_zone_info, so that
|
# 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:
|
if ret is not None:
|
||||||
_LOGGER.debug("Updating status for zone %s", self._zone_id)
|
_LOGGER.debug("Updating status for zone %s", self._zone_id)
|
||||||
if ret[0] == 0:
|
if ret[0] == 0:
|
||||||
self._state = MediaPlayerState.OFF
|
self._attr_state = MediaPlayerState.OFF
|
||||||
else:
|
else:
|
||||||
self._state = MediaPlayerState.ON
|
self._attr_state = MediaPlayerState.ON
|
||||||
self._volume = ret[2] * 2 / 100.0
|
self._attr_volume_level = ret[2] * 2 / 100.0
|
||||||
# Returns 0 based index for source.
|
# Returns 0 based index for source.
|
||||||
index = ret[1]
|
index = ret[1]
|
||||||
# Possibility exists that user has defined list of all sources.
|
# Possibility exists that user has defined list of all sources.
|
||||||
# If a source is set externally that is beyond the defined list then
|
# If a source is set externally that is beyond the defined list then
|
||||||
# an exception will be thrown.
|
# an exception will be thrown.
|
||||||
# In this case return and unknown source (None)
|
# In this case return and unknown source (None)
|
||||||
try:
|
if self.source_list and 0 <= index < len(self.source_list):
|
||||||
self._source = self._sources[index]
|
self._attr_source = self.source_list[index]
|
||||||
except IndexError:
|
|
||||||
self._source = None
|
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Could not update status for zone %s", self._zone_id)
|
_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:
|
def set_volume_level(self, volume: float) -> None:
|
||||||
"""Set volume level. Volume has a range (0..1).
|
"""Set volume level. Volume has a range (0..1).
|
||||||
|
|
||||||
@ -164,12 +134,7 @@ class RussoundRNETDevice(MediaPlayerEntity):
|
|||||||
|
|
||||||
def select_source(self, source: str) -> None:
|
def select_source(self, source: str) -> None:
|
||||||
"""Set the input source."""
|
"""Set the input source."""
|
||||||
if source in self._sources:
|
if self.source_list and source in self.source_list:
|
||||||
index = self._sources.index(source)
|
index = self.source_list.index(source)
|
||||||
# 0 based value for source
|
# 0 based value for source
|
||||||
self._russ.set_source("1", self._zone_id, index)
|
self._russ.set_source("1", self._zone_id, index)
|
||||||
|
|
||||||
@property
|
|
||||||
def source_list(self):
|
|
||||||
"""Return a list of available input sources."""
|
|
||||||
return self._sources
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user