Browse Source

videv audio_player implemented

tags/v1.0.0
Dirk Alders 1 year ago
parent
commit
c9165da525
2 changed files with 35 additions and 11 deletions
  1. 7
    4
      function/ground_floor_west.py
  2. 28
    7
      function/videv.py

+ 7
- 4
function/ground_floor_west.py View File

7
 from function.modules import brightness_choose_n_action, heating_function
7
 from function.modules import brightness_choose_n_action, heating_function
8
 import logging
8
 import logging
9
 from function.rooms import room
9
 from function.rooms import room
10
-from function.videv import videv_switching, videv_switch_brightness_color_temp, videv_heating, videv_multistate
10
+from function.videv import videv_switching, videv_switch_brightness_color_temp, videv_heating, videv_multistate, videv_audio_player
11
 import task
11
 import task
12
 
12
 
13
 try:
13
 try:
152
         self.desk_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE)
152
         self.desk_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE)
153
         self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
153
         self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
154
         self.remote_amplifier = devices.remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
154
         self.remote_amplifier = devices.remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
155
+        self.spotify_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_SPOTIFY)
156
+        self.mpd_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_MPD)
155
         self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)
157
         self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)
156
         super().__init__(mqtt_client)
158
         super().__init__(mqtt_client)
157
         #
159
         #
178
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
180
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
179
                                          self.powerplug_common.toggle_output_3_mcb)
181
                                          self.powerplug_common.toggle_output_3_mcb)
180
 
182
 
181
-        # Mediaplayer - Spotify / MPD state
182
-        self.spotify_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_SPOTIFY)
183
-        self.mpd_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_MPD)
184
         # Mediaplayer - Amplifier auto on
183
         # Mediaplayer - Amplifier auto on
185
         self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.powerplug_common.set_output_0_mcb, True)
184
         self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.powerplug_common.set_output_0_mcb, True)
186
         self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True)
185
         self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True)
295
             mqtt_client, config.TOPIC_GFW_DIRK_ACTIVE_BRIGHTNESS_DEVICE_VIDEV,
294
             mqtt_client, config.TOPIC_GFW_DIRK_ACTIVE_BRIGHTNESS_DEVICE_VIDEV,
296
             brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 3
295
             brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 3
297
         )
296
         )
297
+        self.audio_player_videv = videv_audio_player(
298
+            mqtt_client, config.TOPIC_GFW_DIRK_AUDIO_PLAYER_VIDEV,
299
+            self.spotify_state, self.mpd_state
300
+        )
298
         #
301
         #
299
         # Other stuff
302
         # Other stuff
300
         #
303
         #

+ 28
- 7
function/videv.py View File

16
 
16
 
17
 from base import mqtt_base
17
 from base import mqtt_base
18
 import devices
18
 import devices
19
-import inspect
20
 import json
19
 import json
21
-import logging
22
 
20
 
23
 BASETOPIC = "videv"
21
 BASETOPIC = "videv"
24
 
22
 
99
         l1 = []
97
         l1 = []
100
         for k, v in self.__device_list__.items():
98
         for k, v in self.__device_list__.items():
101
             if v.__class__.__name__ == "group":
99
             if v.__class__.__name__ == "group":
102
-                if device in v:
100
+                if id(device) in [id(d) for d in v]:
103
                     l1.append(k)
101
                     l1.append(k)
104
             else:
102
             else:
105
-                if v == device:
103
+                if id(v) == id(device):
106
                     l1.append(k)
104
                     l1.append(k)
107
         l2 = [k for k, v in self.__device_key__.items() if v == key]
105
         l2 = [k for k, v in self.__device_key__.items() if v == key]
108
         try:
106
         try:
234
 
232
 
235
 
233
 
236
 class videv_multistate(base):
234
 class videv_multistate(base):
237
-    def __init__(self, mqtt_client, topic, key_for_topic, device, num_states, default_values=None):
235
+    def __init__(self, mqtt_client, topic, key_for_device, device, num_states, default_values=None):
238
         dv = dict.fromkeys(["state_%d" % i for i in range(0, num_states)])
236
         dv = dict.fromkeys(["state_%d" % i for i in range(0, num_states)])
239
         for key in dv:
237
         for key in dv:
240
             dv[key] = False
238
             dv[key] = False
241
-        super().__init__(mqtt_client, topic, (key_for_topic, device), default_values=dv)
239
+        super().__init__(mqtt_client, topic, (key_for_device, device), default_values=dv)
242
         #
240
         #
243
-        device.add_callback(key_for_topic, None, self.__index_rx__, True)
241
+        device.add_callback(key_for_device, None, self.__index_rx__, True)
244
 
242
 
245
     def __index_rx__(self, device, key, data):
243
     def __index_rx__(self, device, key, data):
246
         for index, key in enumerate(self):
244
         for index, key in enumerate(self):
247
             self.set(key, index == data)
245
             self.set(key, index == data)
248
             self.__tx__(key, self[key])
246
             self.__tx__(key, self[key])
247
+
248
+
249
+class videv_audio_player(base_routing):
250
+    KEY_ACTIVE_PLAYER = 'player_%d'
251
+    KEY_TITLE = 'title'
252
+    NO_TITLE = '---'
253
+
254
+    def __init__(self, mqtt_client, topic, *args):
255
+        dv = dict.fromkeys([self.KEY_ACTIVE_PLAYER % i for i in range(0, len(args))])
256
+        for key in dv:
257
+            dv[key] = False
258
+        dv[self.KEY_TITLE] = self.NO_TITLE
259
+        super().__init__(
260
+            mqtt_client, topic,
261
+            *[[self.KEY_ACTIVE_PLAYER % i, device, devices.audio_status.KEY_STATE] for i, device in enumerate(args)],
262
+            default_values=dv
263
+        )
264
+        for audio_device in args:
265
+            audio_device.add_callback(audio_device.KEY_TITLE, None, self.__title_rx__, True)
266
+
267
+    def __title_rx__(self, device, key, data):
268
+        self.set(self.KEY_TITLE, data or self.NO_TITLE)
269
+        self.__tx__(self.KEY_TITLE, self[self.KEY_TITLE])

Loading…
Cancel
Save