From e2398e5bf0af9af16ded67610df3ecb939df445e Mon Sep 17 00:00:00 2001 From: robhuls Date: Wed, 3 Jan 2018 20:52:00 +0100 Subject: [PATCH 1/2] Fix NAD7050 hangs with identical settings Fix NAD7050 hangs when setting source or power to the value it already has, as well as a hang when setting the source while the power is off. This normally only occurs in automations, because normally only commands are send when the status changes, but in an automation people can choose to just set things without first checking the current status. --- nad_receiver/__init__.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/nad_receiver/__init__.py b/nad_receiver/__init__.py index cf76177..c957eb5 100644 --- a/nad_receiver/__init__.py +++ b/nad_receiver/__init__.py @@ -222,11 +222,16 @@ def status(self): def power_off(self): """Power the device off.""" - self._send(self.CMD_POWERSAVE + self.CMD_OFF) + status = self.status() + if status['power']: # Setting power off when it is already off can cause hangs + self._send(self.CMD_POWERSAVE + self.CMD_OFF) def power_on(self): """Power the device on.""" - self._send(self.CMD_ON, read_reply=True) + status = self.status() + if not status['power']: + self._send(self.CMD_ON, read_reply=True) + sleep(0.5) # Give NAD7050 some time before next command def set_volume(self, volume): """Set volume level of the device. Accepts integer values 0-200.""" @@ -241,11 +246,14 @@ def mute(self): def unmute(self): """Unmute the device.""" self._send(self.CMD_UNMUTE) - + def select_source(self, source): """Select a source from the list of sources.""" - if source in self.SOURCES: - self._send(self.CMD_SOURCE + self.SOURCES[source], read_reply=True) + status = self.status() + if status['power']: # Changing source when off may hang NAD7050 + if status['source'] not in source: # Setting the source to the current source will hang the NAD7050 + if source in self.SOURCES: + self._send(self.CMD_SOURCE + self.SOURCES[source], read_reply=True) def available_sources(self): """Return a list of available sources.""" From 25d640d733a9a3be96c403004c64d7418e089e40 Mon Sep 17 00:00:00 2001 From: robhuls Date: Thu, 4 Jan 2018 09:45:54 +0100 Subject: [PATCH 2/2] Fix string comparison for source --- nad_receiver/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nad_receiver/__init__.py b/nad_receiver/__init__.py index c957eb5..b29c74a 100644 --- a/nad_receiver/__init__.py +++ b/nad_receiver/__init__.py @@ -251,7 +251,7 @@ def select_source(self, source): """Select a source from the list of sources.""" status = self.status() if status['power']: # Changing source when off may hang NAD7050 - if status['source'] not in source: # Setting the source to the current source will hang the NAD7050 + if status['source'] != source: # Setting the source to the current source will hang the NAD7050 if source in self.SOURCES: self._send(self.CMD_SOURCE + self.SOURCES[source], read_reply=True)