|
@@ -5,7 +5,6 @@
|
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
|
8
|
import task
|
10
|
9
|
|
11
|
10
|
try:
|
|
@@ -80,8 +79,6 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
|
80
|
79
|
#
|
81
|
80
|
self.delayed_task = task.delayed(1.0, self.send_audio_source)
|
82
|
81
|
#
|
83
|
|
- self.cvi = changed_value_indicator()
|
84
|
|
- #
|
85
|
82
|
# Callback initialisation
|
86
|
83
|
#
|
87
|
84
|
|
|
@@ -110,14 +107,14 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
|
110
|
107
|
self.gui_switch_amplifier.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_0_mcb)
|
111
|
108
|
self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.gui_switch_amplifier.set_state_mcb)
|
112
|
109
|
# amplifier auto on
|
113
|
|
- self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.cd_amplifier_synchronisation)
|
114
|
|
- self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation)
|
115
|
|
- self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation)
|
|
110
|
+ self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.cd_amplifier_synchronisation, True)
|
|
111
|
+ self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation, True)
|
|
112
|
+ self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation, True)
|
116
|
113
|
# audio source
|
117
|
|
- self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.audio_source_selector)
|
118
|
|
- self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.audio_source_selector)
|
119
|
|
- self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.audio_source_selector)
|
120
|
|
- self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.audio_source_selector)
|
|
114
|
+ self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, True, self.audio_source_selector, True)
|
|
115
|
+ self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, True, self.audio_source_selector, True)
|
|
116
|
+ self.spotify_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
|
|
117
|
+ self.mpd_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
|
121
|
118
|
self.audio_source = self.AUDIO_SOURCE_PC
|
122
|
119
|
|
123
|
120
|
# cd player
|
|
@@ -134,8 +131,8 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
|
134
|
131
|
|
135
|
132
|
# brightness
|
136
|
133
|
self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, None, self.brightness_action)
|
137
|
|
- self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.device_chooser_action)
|
138
|
|
- self.powerplug_common.add_callback(None, None, self.device_chooser_action)
|
|
134
|
+ self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.device_chooser_action, True)
|
|
135
|
+ self.powerplug_common.add_callback(None, None, self.device_chooser_action, True)
|
139
|
136
|
self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_UP, self.choose_next_device)
|
140
|
137
|
self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_DOWN, self.choose_prev_device)
|
141
|
138
|
self.active_device_state = None
|
|
@@ -146,37 +143,32 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
|
146
|
143
|
self.powerplug_common.set_output_all(False)
|
147
|
144
|
|
148
|
145
|
def cd_amplifier_synchronisation(self, device, key, data):
|
149
|
|
- if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
|
150
|
|
- logger.info("Syncing \"%s\" amplifier with cd player: %s", type(self).__name__, data)
|
151
|
|
- self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
|
|
146
|
+ logger.info("Syncing \"%s\" amplifier with cd player: %s", type(self).__name__, data)
|
|
147
|
+ self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
|
152
|
148
|
|
153
|
149
|
def raspi_amplifier_synchronisation(self, device, key, data):
|
154
|
|
- if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
|
155
|
|
- logger.info("Syncing \"%s\" amplifier with raspi player: %s", type(self).__name__, data)
|
156
|
|
- self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
|
|
150
|
+ logger.info("Syncing \"%s\" amplifier with raspi player: %s", type(self).__name__, data)
|
|
151
|
+ self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
|
157
|
152
|
|
158
|
153
|
def device_chooser_action(self, device, key, data):
|
159
|
154
|
if device == self.main_light_shelly:
|
160
|
|
- if self.cvi.changed_here(device.topic, key, data):
|
161
|
|
- if data is True:
|
162
|
|
- self.active_device_state = self.STATE_ACTIVE_DEVICE_MAIN_LIGHT
|
163
|
|
- self.update_active_device_led()
|
164
|
|
- else:
|
165
|
|
- self.choose_next_device()
|
|
155
|
+ if data is True:
|
|
156
|
+ self.active_device_state = self.STATE_ACTIVE_DEVICE_MAIN_LIGHT
|
|
157
|
+ self.update_active_device_led()
|
|
158
|
+ else:
|
|
159
|
+ self.choose_next_device()
|
166
|
160
|
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_DESK_LIGHT:
|
167
|
|
- if self.cvi.changed_here(device.topic, key, data):
|
168
|
|
- if data is True:
|
169
|
|
- self.active_device_state = self.STATE_ACTIVE_DEVICE_DESK_LIGHT
|
170
|
|
- self.update_active_device_led()
|
171
|
|
- else:
|
172
|
|
- self.choose_next_device()
|
|
161
|
+ if data is True:
|
|
162
|
+ self.active_device_state = self.STATE_ACTIVE_DEVICE_DESK_LIGHT
|
|
163
|
+ self.update_active_device_led()
|
|
164
|
+ else:
|
|
165
|
+ self.choose_next_device()
|
173
|
166
|
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
|
174
|
|
- if self.cvi.changed_here(device.topic, key, data):
|
175
|
|
- if data is True:
|
176
|
|
- self.active_device_state = self.STATE_ACTIVE_DEVICE_AMPLIFIER
|
177
|
|
- self.update_active_device_led()
|
178
|
|
- else:
|
179
|
|
- self.choose_next_device()
|
|
167
|
+ if data is True:
|
|
168
|
+ self.active_device_state = self.STATE_ACTIVE_DEVICE_AMPLIFIER
|
|
169
|
+ self.update_active_device_led()
|
|
170
|
+ else:
|
|
171
|
+ self.choose_next_device()
|
180
|
172
|
|
181
|
173
|
def get_activity_state(self, state):
|
182
|
174
|
if state == self.STATE_ACTIVE_DEVICE_MAIN_LIGHT:
|
|
@@ -237,17 +229,14 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
|
237
|
229
|
|
238
|
230
|
def audio_source_selector(self, device, key, data):
|
239
|
231
|
if device == self.powerplug_common and key == self.KEY_POWERPLUG_CD_PLAYER:
|
240
|
|
- if self.cvi.changed_here(device.topic, key, data) and data is True:
|
241
|
|
- # switch on of cd player
|
242
|
|
- self.audio_source = self.AUDIO_SOURCE_CD
|
|
232
|
+ # switch on of cd player
|
|
233
|
+ self.audio_source = self.AUDIO_SOURCE_CD
|
243
|
234
|
elif device in [self.spotify_state, self.mpd_state]:
|
244
|
|
- if self.cvi.changed_here(device.topic, key, data) and data is True:
|
245
|
|
- # switch on raspi-source
|
246
|
|
- self.audio_source = self.AUDIO_SOURCE_RASPI
|
|
235
|
+ # switch on raspi-source
|
|
236
|
+ self.audio_source = self.AUDIO_SOURCE_RASPI
|
247
|
237
|
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
|
248
|
|
- if self.cvi.changed_here(device.topic, key, data) and data is True:
|
249
|
|
- # switch on of amplifier -> select source and reset stored source value
|
250
|
|
- self.delayed_task.run()
|
|
238
|
+ # switch on of amplifier -> select source and reset stored source value
|
|
239
|
+ self.delayed_task.run()
|
251
|
240
|
|
252
|
241
|
def send_audio_source(self):
|
253
|
242
|
if self.audio_source == self.AUDIO_SOURCE_PC:
|