Update NAD states only when the device is on (#34809)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Frederik Gladhorn 2020-06-03 18:43:44 +02:00 committed by GitHub
parent 98a056f7a9
commit 1510d5625a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -167,23 +167,28 @@ class NAD(MediaPlayerEntity):
"""List of available input sources.""" """List of available input sources."""
return sorted(list(self._reverse_mapping.keys())) return sorted(list(self._reverse_mapping.keys()))
def update(self): @property
def available(self):
"""Return if device is available."""
return self._state is not None
def update(self) -> None:
"""Retrieve latest state.""" """Retrieve latest state."""
if self._nad_receiver.main_power("?") == "Off": power_state = self._nad_receiver.main_power("?")
self._state = STATE_OFF if not power_state:
else: self._state = None
self._state = STATE_ON return
self._state = (
STATE_ON if self._nad_receiver.main_power("?") == "On" else STATE_OFF
)
if self._nad_receiver.main_mute("?") == "Off": if self._state == STATE_ON:
self._mute = False self._mute = self._nad_receiver.main_mute("?") == "On"
else: volume = self._nad_receiver.main_volume("?")
self._mute = True # Some receivers cannot report the volume, e.g. C 356BEE,
# instead they only support stepping the volume up or down
volume = self._nad_receiver.main_volume("?") self._volume = self.calc_volume(volume) if volume is not None else None
# Some receivers cannot report the volume, e.g. C 356BEE, self._source = self._source_dict.get(self._nad_receiver.main_source("?"))
# instead they only support stepping the volume up or down
self._volume = self.calc_volume(volume) if volume is not None else None
self._source = self._source_dict.get(self._nad_receiver.main_source("?"))
def calc_volume(self, decibel): def calc_volume(self, decibel):
""" """