Selaa lähdekoodia

videv audio_player implemented

tags/v1.0.0
Dirk Alders 1 vuosi sitten
vanhempi
commit
c9165da525
2 muutettua tiedostoa jossa 35 lisäystä ja 11 poistoa
  1. 7
    4
      function/ground_floor_west.py
  2. 28
    7
      function/videv.py

+ 7
- 4
function/ground_floor_west.py Näytä tiedosto

@@ -7,7 +7,7 @@ import devices
7 7
 from function.modules import brightness_choose_n_action, heating_function
8 8
 import logging
9 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 11
 import task
12 12
 
13 13
 try:
@@ -152,6 +152,8 @@ class ground_floor_west_dirk(room):
152 152
         self.desk_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE)
153 153
         self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
154 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 157
         self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)
156 158
         super().__init__(mqtt_client)
157 159
         #
@@ -178,9 +180,6 @@ class ground_floor_west_dirk(room):
178 180
         self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
179 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 183
         # Mediaplayer - Amplifier auto on
185 184
         self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.powerplug_common.set_output_0_mcb, True)
186 185
         self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True)
@@ -295,6 +294,10 @@ class ground_floor_west_dirk(room):
295 294
             mqtt_client, config.TOPIC_GFW_DIRK_ACTIVE_BRIGHTNESS_DEVICE_VIDEV,
296 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 302
         # Other stuff
300 303
         #

+ 28
- 7
function/videv.py Näytä tiedosto

@@ -16,9 +16,7 @@ Targets:
16 16
 
17 17
 from base import mqtt_base
18 18
 import devices
19
-import inspect
20 19
 import json
21
-import logging
22 20
 
23 21
 BASETOPIC = "videv"
24 22
 
@@ -99,10 +97,10 @@ class base_routing(base):
99 97
         l1 = []
100 98
         for k, v in self.__device_list__.items():
101 99
             if v.__class__.__name__ == "group":
102
-                if device in v:
100
+                if id(device) in [id(d) for d in v]:
103 101
                     l1.append(k)
104 102
             else:
105
-                if v == device:
103
+                if id(v) == id(device):
106 104
                     l1.append(k)
107 105
         l2 = [k for k, v in self.__device_key__.items() if v == key]
108 106
         try:
@@ -234,15 +232,38 @@ class videv_heating(base_routing):
234 232
 
235 233
 
236 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 236
         dv = dict.fromkeys(["state_%d" % i for i in range(0, num_states)])
239 237
         for key in dv:
240 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 243
     def __index_rx__(self, device, key, data):
246 244
         for index, key in enumerate(self):
247 245
             self.set(key, index == data)
248 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…
Peruuta
Tallenna