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,18 +167,23 @@ 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 = (
if self._nad_receiver.main_mute("?") == "Off": STATE_ON if self._nad_receiver.main_power("?") == "On" else STATE_OFF
self._mute = False )
else:
self._mute = True
if self._state == STATE_ON:
self._mute = self._nad_receiver.main_mute("?") == "On"
volume = self._nad_receiver.main_volume("?") volume = self._nad_receiver.main_volume("?")
# Some receivers cannot report the volume, e.g. C 356BEE, # Some receivers cannot report the volume, e.g. C 356BEE,
# instead they only support stepping the volume up or down # instead they only support stepping the volume up or down