minidsp-lcd-monitor: simplify lookup of changed attributes
authorClinton Ebadi <clinton@unknownlamer.org>
Sat, 19 Feb 2022 20:56:25 +0000 (15:56 -0500)
committerClinton Ebadi <clinton@unknownlamer.org>
Sat, 19 Feb 2022 20:56:25 +0000 (15:56 -0500)
Use the "|" operator to merge the attribute changed data into the
current attributes.

minidsp-lcd-monitor/minidsp-lcd-monitor.py

index 43a73dc..0a9541b 100755 (executable)
@@ -180,23 +180,21 @@ class DSPMonitor:
         print (message);
         parsed = json.loads(message)
         pprint.pp (parsed['master'])
-        self.update_screen(parsed['master'], force=force_redisplay)
+        self.update_screen(self.dspattrs | parsed['master'], force=force_redisplay)
 
     def update_screen(self, attrs=None, force=False):
         if attrs == None:
             attrs = self.dspattrs
-        if attrs.get('source', self.dspattrs['source']) != self.dspattrs['source'] or force:
+        if attrs['source'] != self.dspattrs['source'] or force:
             self.draw_source(attrs['source'])
-            self.dspattrs['source'] = attrs['source']
-        if attrs.get('preset', self.dspattrs['preset'])  != self.dspattrs['preset'] or force:
+        if attrs['preset'] != self.dspattrs['preset'] or force:
             self.draw_preset(attrs['preset'])
-            self.dspattrs['preset'] = attrs['preset']
-        if attrs.get('volume', self.dspattrs['volume']) != self.dspattrs['volume'] or attrs.get('mute', self.dspattrs['mute']) != self.dspattrs['mute'] or force:
+        if attrs['volume'] != self.dspattrs['volume'] or attrs['mute'] != self.dspattrs['mute'] or force:
             pct = int(abs((self.minidsp_min_volume_db - attrs['volume']) / abs(self.minidsp_min_volume_db)) * 100)
             print('pct {}, min {}, vol {}'.format(pct, self.minidsp_min_volume_db, attrs['volume']))
             self.draw_volume_bar (pct, attrs['mute'])
-            self.dspattrs['volume'] = attrs['volume']
-            self.dspattrs['mute'] = attrs['mute']
+
+        self.dspattrs = attrs
 
     def draw_source(self, source_name):
         self.lcd.cmd_cursor_set_position(1,1)