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."""
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."""
if self._nad_receiver.main_power("?") == "Off":
self._state = STATE_OFF
else:
self._state = STATE_ON
power_state = self._nad_receiver.main_power("?")
if not power_state:
self._state = None
return
self._state = (
STATE_ON if self._nad_receiver.main_power("?") == "On" else STATE_OFF
)
if self._nad_receiver.main_mute("?") == "Off":
self._mute = False
else:
self._mute = True
volume = self._nad_receiver.main_volume("?")
# Some receivers cannot report the volume, e.g. C 356BEE,
# 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("?"))
if self._state == STATE_ON:
self._mute = self._nad_receiver.main_mute("?") == "On"
volume = self._nad_receiver.main_volume("?")
# Some receivers cannot report the volume, e.g. C 356BEE,
# 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):
"""