Browse Source

implemented audio functionality in gfw_dirk

tags/v1.0.0
Dirk Alders 2 years ago
parent
commit
a7bff4b78c
6 changed files with 115 additions and 61 deletions
  1. 13
    26
      devices/__init__.py
  2. 0
    1
      function/__init__.py
  3. 3
    3
      function/common.py
  4. 5
    7
      function/first_floor_east.py
  5. 76
    24
      function/ground_floor_west.py
  6. 18
    0
      function/helpers.py

+ 13
- 26
devices/__init__.py View File

@@ -107,7 +107,7 @@ class base(dict):
107 107
 
108 108
     def unpack(self, message):
109 109
         content_key = message.topic[len(self.topic) + 1:]
110
-        if content_key not in self.RX_IGNORE_TOPICS:
110
+        if content_key not in self.RX_IGNORE_TOPICS and (not message.topic.endswith(self.TX_TOPIC) or len(self.TX_TOPIC) == 0):
111 111
             logger.debug("Unpacking content_key \"%s\" from message.", content_key)
112 112
             if is_json(message.payload):
113 113
                 data = json.loads(message.payload)
@@ -204,8 +204,7 @@ class shelly(base):
204 204
     RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1,
205 205
                KEY_INPUT_0, KEY_INPUT_1, KEY_LONGPUSH_0, KEY_LONGPUSH_1,
206 206
                KEY_OVERTEMPERATURE, KEY_TEMPERATURE]
207
-    RX_IGNORE_TOPICS = [KEY_OUTPUT_0 + '/' + TX_TOPIC, KEY_OUTPUT_1 + '/' + TX_TOPIC,
208
-                        KEY_OUTPUT_0 + '/' + "energy", KEY_OUTPUT_1 + '/' + "energy",
207
+    RX_IGNORE_TOPICS = [KEY_OUTPUT_0 + '/' + "energy", KEY_OUTPUT_1 + '/' + "energy",
209 208
                         'input_event/0', 'input_event/1']
210 209
     RX_IGNORE_KEYS = ['temperature_f']
211 210
     RX_FILTER_DATA_KEYS = [KEY_INPUT_0, KEY_INPUT_1, KEY_LONGPUSH_0, KEY_LONGPUSH_1,
@@ -286,8 +285,6 @@ class silvercrest_powerplug(base):
286 285
     TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0]
287 286
     #
288 287
     RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0]
289
-    RX_IGNORE_TOPICS = [TX_TOPIC]
290
-    RX_IGNORE_KEYS = []
291 288
     RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0]
292 289
 
293 290
     def __init__(self, mqtt_client, topic):
@@ -325,10 +322,6 @@ class my_powerplug(base):
325 322
     TX_TYPE = base.TX_VALUE
326 323
     #
327 324
     RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_OUTPUT_3]
328
-    RX_IGNORE_TOPICS = [KEY_OUTPUT_0 + "/" + TX_TOPIC, KEY_OUTPUT_1 + "/" + TX_TOPIC,
329
-                        KEY_OUTPUT_2 + "/" + TX_TOPIC, KEY_OUTPUT_3 + "/" + TX_TOPIC]
330
-    RX_IGNORE_KEYS = []
331
-    RX_FILTER_DATA_KEYS = []
332 325
 
333 326
     def __init__(self, mqtt_client, topic):
334 327
         super().__init__(mqtt_client, topic)
@@ -392,7 +385,6 @@ class tradfri_light(base):
392 385
     TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP, KEY_BRIGHTNESS_FADE]
393 386
     #
394 387
     RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
395
-    RX_IGNORE_TOPICS = [TX_TOPIC]
396 388
     RX_IGNORE_KEYS = ['update', 'color_mode']
397 389
     RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
398 390
 
@@ -484,9 +476,7 @@ class tradfri_button(base):
484 476
     KEY_ACTION_DURATION = "action_duration"
485 477
     #
486 478
     RX_KEYS = [KEY_LINKQUALITY, KEY_BATTERY, KEY_ACTION]
487
-    RX_IGNORE_TOPICS = []
488 479
     RX_IGNORE_KEYS = ['update', KEY_ACTION_DURATION]
489
-    RX_FILTER_DATA_KEYS = []
490 480
 
491 481
     def __init__(self, mqtt_client, topic):
492 482
         super().__init__(mqtt_client, topic)
@@ -521,11 +511,8 @@ class nodered_gui(base):
521 511
     #
522 512
     TX_TOPIC = 'set'
523 513
     TX_TYPE = base.TX_VALUE
524
-    TX_FILTER_DATA_KEYS = []
525 514
     #
526 515
     RX_KEYS = [KEY_STATE, KEY_BRIGHTNESS, KEY_COLOR_TEMP, KEY_HEATING_BOOST, KEY_HEATING_SETPOINT, KEY_OFF_BUTTON]
527
-    RX_IGNORE_TOPICS = [KEY_FEEDBACK + '/' + TX_TOPIC, KEY_ENABLE + '/' + TX_TOPIC]
528
-    RX_FILTER_DATA_KEYS = []
529 516
 
530 517
     def __init__(self, mqtt_client, topic):
531 518
         super().__init__(mqtt_client, topic)
@@ -589,13 +576,10 @@ class brennenstuhl_heatingvalve(base):
589 576
     #
590 577
     TX_TOPIC = 'set'
591 578
     TX_TYPE = base.TX_DICT
592
-    TX_FILTER_DATA_KEYS = []
593 579
     #
594 580
     RX_KEYS = [KEY_LINKQUALITY, KEY_BATTERY, KEY_HEATING_SETPOINT, KEY_TEMPERATURE]
595
-    RX_IGNORE_TOPICS = [TX_TOPIC]
596 581
     RX_IGNORE_KEYS = [KEY_AWAY_MODE, KEY_CHILD_LOCK, KEY_PRESET,
597 582
                       KEY_SYSTEM_MODE, KEY_VALVE_DETECTION, KEY_WINDOW_DETECTION]
598
-    RX_FILTER_DATA_KEYS = []
599 583
 
600 584
     def __init__(self, mqtt_client, topic):
601 585
         super().__init__(mqtt_client, topic)
@@ -641,26 +625,22 @@ class remote(base):
641 625
     #
642 626
     TX_TOPIC = ''
643 627
     TX_TYPE = base.TX_VALUE
644
-    TX_FILTER_DATA_KEYS = []
628
+    #
629
+    RX_IGNORE_TOPICS = [KEY_CD, KEY_LINE1, KEY_LINE3, KEY_MUTE, KEY_POWER, KEY_VOLUP, KEY_VOLDOWN]
645 630
 
646 631
     def set_cd(self):
647
-        """data: [True, False]"""
648 632
         self.pack(self.KEY_CD, None)
649 633
 
650 634
     def set_line1(self):
651
-        """data: [True, False]"""
652 635
         self.pack(self.KEY_LINE1, None)
653 636
 
654 637
     def set_line3(self):
655
-        """data: [True, False]"""
656 638
         self.pack(self.KEY_LINE3, None)
657 639
 
658 640
     def set_mute(self):
659
-        """data: [True, False]"""
660 641
         self.pack(self.KEY_MUTE, None)
661 642
 
662 643
     def set_power(self):
663
-        """data: [True, False]"""
664 644
         self.pack(self.KEY_POWER, None)
665 645
 
666 646
     def set_volume_up(self, data=False):
@@ -684,10 +664,17 @@ class remote(base):
684 664
 class status(base):
685 665
     KEY_STATE = "state"
686 666
     #
687
-    TX_TOPIC = ''
667
+    TX_TOPIC = 'set'
688 668
     TX_TYPE = base.TX_VALUE
689
-    TX_FILTER_DATA_KEYS = []
669
+    #
670
+    RX_KEYS = [KEY_STATE]
690 671
 
691 672
     def set_state(self, num, data):
692 673
         """data: [True, False]"""
693 674
         self.pack(self.KEY_STATE + "/" + str(num), data)
675
+
676
+
677
+class audio_status(status):
678
+    KEY_TITLE = "title"
679
+    #
680
+    RX_KEYS = [status.KEY_STATE, KEY_TITLE]

+ 0
- 1
function/__init__.py View File

@@ -15,7 +15,6 @@ except ImportError:
15 15
     ROOT_LOGGER_NAME = 'root'
16 16
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
17 17
 
18
-# TODO: implement existing nodered functionality "dirk" (ground floor west)
19 18
 # TODO: implement garland (incl. day events like sunset, sunrise, ...)
20 19
 # TODO: implement warning message
21 20
 

+ 3
- 3
function/common.py View File

@@ -5,6 +5,7 @@
5 5
 import devices
6 6
 from function.rooms import room_shelly
7 7
 from function.modules import heating_function_brennenstuhl
8
+from function.helpers import changed_value_indicator
8 9
 import logging
9 10
 import task
10 11
 
@@ -25,20 +26,19 @@ class common_circulation_pump(room_shelly):
25 26
         self.gui_timer_view = devices.nodered_gui(mqtt_client, "gui/ffe_circ_pump_timer")
26 27
         self.gui_timer_view.set_feedback('-')
27 28
         #
28
-        self.last_pump_value = None
29
+        self.cvi = changed_value_indicator()
29 30
         self.ct = task.periodic(6, self.cyclic_task)
30 31
         self.pump_timer = None
31 32
         #
32 33
         self.ct.run()
33 34
 
34 35
     def circ_pump_actions(self, device, key, data):
35
-        if self.last_pump_value != data and data is True:
36
+        if self.cvi.changed_here(device.topic, key, data) and data is True:
36 37
             self.pump_timer = 10
37 38
             self.gui_timer_view.set_feedback(self.pump_timer)
38 39
         elif data is False:
39 40
             self.pump_timer = None
40 41
             self.gui_timer_view.set_feedback('-')
41
-        self.last_pump_value = data
42 42
 
43 43
     def cyclic_task(self, rt):
44 44
         if self.pump_timer is not None:

+ 5
- 7
function/first_floor_east.py View File

@@ -7,7 +7,7 @@ import devices
7 7
 import json
8 8
 import logging
9 9
 from function.rooms import room_shelly, room_shelly_tradfri_light
10
-
10
+from function.helpers import changed_value_indicator
11 11
 try:
12 12
     from config import APP_NAME as ROOT_LOGGER_NAME
13 13
 except ImportError:
@@ -45,17 +45,16 @@ class first_floor_east_dining(room_shelly):
45 45
         self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0,
46 46
                                               None, self.gui_switch_feedback_floorlamp)
47 47
         #
48
-        self.main_light_shelly_last = None
48
+        self.cvi = changed_value_indicator()
49 49
 
50 50
     def all_off(self, device=None, key=None, data=None):
51 51
         super().all_off(device, key, data)
52 52
         self.floorlamp_powerplug.set_output_0(False)
53 53
 
54 54
     def floorlamp_synchronisation(self, device, key, data):
55
-        if data != self.main_light_shelly_last:
55
+        if self.cvi.changed_here(device.topic, key, data):
56 56
             logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
57 57
             self.floorlamp_powerplug.set_output_0(data)
58
-        self.main_light_shelly_last = data
59 58
 
60 59
     def gui_switch_command_floorlamp(self, device, key, data):
61 60
         logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data))
@@ -205,7 +204,7 @@ class first_floor_east_living(room_shelly_tradfri_light):
205 204
         self.gui_color_temp_floorlamp.add_callback(
206 205
             devices.nodered_gui.KEY_COLOR_TEMP, None, self.set_color_temp_floorlamp)
207 206
         #
208
-        self.main_light_shelly_last = None
207
+        self.cvi = changed_value_indicator()
209 208
 
210 209
     def all_off(self, device=None, key=None, data=None):
211 210
         super().all_off(device, key, data)
@@ -219,11 +218,10 @@ class first_floor_east_living(room_shelly_tradfri_light):
219 218
         return rv
220 219
 
221 220
     def floorlamp_synchronisation(self, device, key, data):
222
-        if data != self.main_light_shelly_last:
221
+        if self.cvi.changed_here(device.topic, key, data):
223 222
             logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
224 223
             for device in self.__floorlamp_devices__():
225 224
                 device.set_output_0(data)
226
-        self.main_light_shelly_last = data
227 225
 
228 226
     def gui_switch_command_floorlamp(self, device, key, data):
229 227
         logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data))

+ 76
- 24
function/ground_floor_west.py View File

@@ -5,6 +5,8 @@
5 5
 import devices
6 6
 import logging
7 7
 from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light
8
+from function.helpers import changed_value_indicator
9
+import task
8 10
 
9 11
 try:
10 12
     from config import APP_NAME as ROOT_LOGGER_NAME
@@ -49,6 +51,18 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
49 51
     STATE_ACTIVE_DEVICE_DESK_LIGHT = 1
50 52
     STATE_ACTIVE_DEVICE_AMPLIFIER = 2
51 53
     STATE_ACTIVE_DEVICE_MAX_VALUE = STATE_ACTIVE_DEVICE_AMPLIFIER
54
+    #
55
+    KEY_POWERPLUG_AMPLIFIER = devices.my_powerplug.KEY_OUTPUT_0
56
+    KEY_POWERPLUG_CD_PLAYER = devices.my_powerplug.KEY_OUTPUT_2
57
+    KEY_POWERPLUG_DESK_LIGHT = devices.my_powerplug.KEY_OUTPUT_1
58
+    KEY_POWERPLUG_PC_DOCK = devices.my_powerplug.KEY_OUTPUT_3
59
+    #
60
+    AUDIO_SOURCE_PC = 0
61
+    AUDIO_SOURCE_CD = 1
62
+    AUDIO_SOURCE_RASPI = 2
63
+    #
64
+    KEY_SPOTIFY = "hifi/spotify/state"
65
+    KEY_MPD = "hifi/mpd/state"
52 66
 
53 67
     # https://shelly1l-3C6105E44F27
54 68
     def __init__(self, mqtt_client):
@@ -59,10 +73,6 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
59 73
         self.desk_light_tradfri = devices.tradfri_light(mqtt_client, "zigbee_eg_w/light/dirk_desk")
60 74
         self.button_tradfri = devices.tradfri_button(mqtt_client, "zigbee_eg_w/input_device/dirk")
61 75
         #
62
-        self.powerplug_common.add_callback(None, None, self.powerplug_gui_feedback_actions)
63
-        self.powerplug_common.add_callback(devices.my_powerplug.KEY_OUTPUT_2, None,
64
-                                           self.powerplug_amplifier_synchronisation)
65
-        #
66 76
         self.gui_switch_desk_light = devices.nodered_gui(mqtt_client, "gui/gfw_sw_desk_light")
67 77
         self.gui_brightness_desk_light = devices.nodered_gui(mqtt_client, "gui/gfw_br_desk_light")
68 78
         self.gui_brightness_desk_light.enable(False)
@@ -76,7 +86,19 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
76 86
         self.gui_switch_pc_dock = devices.nodered_gui(mqtt_client, "gui/gfw_sw_pc_dock")
77 87
         #
78 88
         self.remote_amplifier = devices.remote(mqtt_client, "hifi/remote/RAS5")
79
-        self.active_device_state_led = devices.status(mqtt_client, "gui/gfw_avtive_device_state")
89
+        self.active_device_state_led = devices.status(mqtt_client, "gui/gfw_active_device_state")
90
+        #
91
+        self.spotify_state = devices.audio_status(mqtt_client, "hifi/spotify")
92
+        self.mpd_state = devices.audio_status(mqtt_client, "hifi/mpd")
93
+        #
94
+        self.delayed_task = task.delayed(1.0, self.send_audio_source)
95
+        #
96
+        self.cvi = changed_value_indicator()
97
+        #
98
+        self.powerplug_common.add_callback(None, None, self.powerplug_gui_feedback_actions)
99
+        self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.cd_amplifier_synchronisation)
100
+        self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation)
101
+        self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation)
80 102
         #
81 103
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
82 104
                                          devices.tradfri_button.ACTION_TOGGLE, self.toggle_main_light)
@@ -107,20 +129,23 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
107 129
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.device_chooser_action)
108 130
         self.powerplug_common.add_callback(None, None, self.device_chooser_action)
109 131
         #
110
-        self.last_cd_player_powerplug_state = None
111
-        self.last_main_light_state = None
112
-        self.last_desk_light_state = None
113
-        self.last_amplifier_state = None
132
+        self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.audio_source_selector)
133
+        self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.audio_source_selector)
134
+        self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.audio_source_selector)
135
+        self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.audio_source_selector)
136
+        #
114 137
         self.active_device_state = None
138
+        #
139
+        self.audio_source = self.AUDIO_SOURCE_PC
115 140
 
116 141
     def all_off(self, device=None, key=None, data=None):
117 142
         super().all_off(device, key, data)
118 143
         self.powerplug_common.set_output_all(False)
119 144
 
120 145
     def powerplug_gui_feedback_actions(self, device, key, data):
121
-        if key == devices.my_powerplug.KEY_OUTPUT_0:
146
+        if key == self.KEY_POWERPLUG_AMPLIFIER:
122 147
             self.gui_switch_amplifier.set_feedback(data)
123
-        elif key == devices.my_powerplug.KEY_OUTPUT_1:
148
+        elif key == self.KEY_POWERPLUG_DESK_LIGHT:
124 149
             self.gui_switch_desk_light.set_feedback(data)
125 150
             self.gui_brightness_desk_light.enable(data)
126 151
             self.gui_color_temp_desk_light.enable(data)
@@ -130,17 +155,21 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
130 155
             else:
131 156
                 self.gui_brightness_desk_light.set_feedback(self.desk_light_tradfri.brightness)
132 157
                 self.gui_color_temp_desk_light.set_feedback(self.desk_light_tradfri.color_temp / 10)
133
-        elif key == devices.my_powerplug.KEY_OUTPUT_2:
158
+        elif key == self.KEY_POWERPLUG_CD_PLAYER:
134 159
             self.gui_switch_cd_player.set_feedback(data)
135
-        elif key == devices.my_powerplug.KEY_OUTPUT_3:
160
+        elif key == self.KEY_POWERPLUG_PC_DOCK:
136 161
             self.gui_switch_pc_dock.set_feedback(data)
137 162
 
138
-    def powerplug_amplifier_synchronisation(self, device, key, data):
163
+    def cd_amplifier_synchronisation(self, device, key, data):
139 164
         if device == self.powerplug_common:
140
-            if data != self.last_cd_player_powerplug_state:
165
+            if self.cvi.changed_here(device.topic, key, data):
141 166
                 logger.info("Setting \"%s\" amplifier: %s", type(self).__name__, data)
142 167
                 self.powerplug_common.set_output_0(data)
143
-            self.last_cd_player_powerplug_state = data
168
+
169
+    def raspi_amplifier_synchronisation(self, device, key, data):
170
+        if self.cvi.changed_here(device.topic, key, data):
171
+            logger.info("Setting \"%s\" amplifier: %s", type(self).__name__, data)
172
+            self.powerplug_common.set_output_0(data)
144 173
 
145 174
     def desk_light_switch_action(self, device, key, data):
146 175
         if device == self.button_tradfri:
@@ -190,26 +219,23 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
190 219
 
191 220
     def device_chooser_action(self, device, key, data):
192 221
         if device == self.main_light_shelly:
193
-            if self.last_main_light_state != data:
222
+            if self.cvi.changed_here(device.topic, key, data):
194 223
                 if data is True:
195 224
                     self.active_device_state = self.STATE_ACTIVE_DEVICE_MAIN_LIGHT
196 225
                 else:
197 226
                     self.choose_next_device()
198
-            self.last_main_light_state = data
199
-        elif device == self.powerplug_common and key == devices.my_powerplug.KEY_OUTPUT_1:
200
-            if self.last_desk_light_state != data:
227
+        elif device == self.powerplug_common and key == self.KEY_POWERPLUG_DESK_LIGHT:
228
+            if self.cvi.changed_here(device.topic, key, data):
201 229
                 if data is True:
202 230
                     self.active_device_state = self.STATE_ACTIVE_DEVICE_DESK_LIGHT
203 231
                 else:
204 232
                     self.choose_next_device()
205
-                self.last_desk_light_state = data
206
-        elif device == self.powerplug_common and key == devices.my_powerplug.KEY_OUTPUT_0:
207
-            if self.last_amplifier_state != data:
233
+        elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
234
+            if self.cvi.changed_here(device.topic, key, data):
208 235
                 if data is True:
209 236
                     self.active_device_state = self.STATE_ACTIVE_DEVICE_AMPLIFIER
210 237
                 else:
211 238
                     self.choose_next_device()
212
-            self.last_amplifier_state = data
213 239
         for num in range(0, self.STATE_ACTIVE_DEVICE_MAX_VALUE + 1):
214 240
             self.active_device_state_led.set_state(num, self.active_device_state == num)
215 241
 
@@ -260,3 +286,29 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
260 286
                 target.default_dec()
261 287
             elif data in [devices.tradfri_button.ACTION_BRIGHTNESS_UP_RELEASE, devices.tradfri_button.ACTION_BRIGHTNESS_DOWN_RELEASE]:
262 288
                 target.default_stop()
289
+
290
+    def audio_source_selector(self, device, key, data):
291
+        if device == self.powerplug_common and key == self.KEY_POWERPLUG_CD_PLAYER:
292
+            if self.cvi.changed_here(device.topic, key, data) and data is True:
293
+                # switch on of cd player
294
+                self.audio_source = self.AUDIO_SOURCE_CD
295
+        elif device in [self.spotify_state, self.mpd_state]:
296
+            if self.cvi.changed_here(device.topic, key, data) and data is True:
297
+                # switch on raspi-source
298
+                self.audio_source = self.AUDIO_SOURCE_RASPI
299
+        elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
300
+            if self.cvi.changed_here(device.topic, key, data) and data is True:
301
+                # switch on of amplifier -> select source and reset stored source value
302
+                self.delayed_task.run()
303
+
304
+    def send_audio_source(self):
305
+        if self.audio_source == self.AUDIO_SOURCE_PC:
306
+            logger.info("Sending IR command to change audio source to pc")
307
+            self.remote_amplifier.set_line3()
308
+        elif self.audio_source == self.AUDIO_SOURCE_CD:
309
+            logger.info("Sending IR command to change audio source to cd")
310
+            self.remote_amplifier.set_cd()
311
+        elif self.audio_source == self.AUDIO_SOURCE_RASPI:
312
+            logger.info("Sending IR command to change audio source to raspi")
313
+            self.remote_amplifier.set_line1()
314
+        self.audio_source = self.AUDIO_SOURCE_PC

+ 18
- 0
function/helpers.py View File

@@ -0,0 +1,18 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+
5
+import inspect
6
+
7
+
8
+class changed_value_indicator(dict):
9
+    def __init__(self):
10
+        super().__init__(self)
11
+
12
+    def changed_here(self, topic, key, value):
13
+        caller_name = inspect.getmodule(inspect.stack()[1][0]).__name__ + '.' + inspect.stack()[1][3]
14
+        key = '::'.join([caller_name, topic, key])
15
+        #
16
+        rv = self.get(key) != value
17
+        self[key] = value
18
+        return rv

Loading…
Cancel
Save