|
@@ -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
|