|
@@ -28,46 +28,46 @@ class brightness_choose_n_action(object):
|
28
|
28
|
button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_UP, self.choose_next_device)
|
29
|
29
|
button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_DOWN, self.choose_prev_device)
|
30
|
30
|
#
|
31
|
|
- self.device_list = []
|
|
31
|
+ self.brightness_device_list = []
|
32
|
32
|
self.callback_device_list = []
|
33
|
33
|
self.device_states = []
|
34
|
34
|
self.active_device_state = None
|
35
|
35
|
self.update_active_device_led()
|
36
|
36
|
|
37
|
|
- def add(self, device, add_callback):
|
|
37
|
+ def add(self, brightness_device, callback_device, callback_key):
|
38
|
38
|
"""
|
39
|
|
- device: A device for brightness function needs to have the following methods:
|
|
39
|
+ brightness_device: A device for brightness function needs to have the following methods:
|
40
|
40
|
* .default_inc()
|
41
|
41
|
* .default_dec()
|
42
|
42
|
* .default_stop()
|
43
|
|
- add_callback: A on/off callback which tages the <function_to_be_executed> as argument and
|
44
|
|
- - which calls the callback only on changes
|
45
|
|
- - which calls with the following arguments: device, key, data
|
|
43
|
+ callback_device: A device for installing callback which are executed, when the device is switched on or off. It needs the following method:
|
|
44
|
+ * .add_callback(key, data or None, callback, on_changes_only)
|
46
|
45
|
"""
|
47
|
|
- if len(self.device_list) >= len(devices.nodered_gui_leds.RX_KEYS):
|
|
46
|
+ if len(self.brightness_device_list) >= len(devices.nodered_gui_leds.RX_KEYS):
|
48
|
47
|
raise ValueError("Number of devices is limited by number of leds in devices.nodered_gui_leds.")
|
49
|
|
- self.device_list.append(device)
|
50
|
|
- self.callback_device_list.append(add_callback.__self__)
|
|
48
|
+ self.brightness_device_list.append(brightness_device)
|
|
49
|
+ self.callback_device_list.append((callback_device, callback_key))
|
51
|
50
|
self.device_states.append(False)
|
52
|
|
- add_callback(self.device_state_action)
|
|
51
|
+ callback_device.add_callback(callback_key, True, self.device_state_action, True)
|
|
52
|
+ callback_device.add_callback(callback_key, False, self.device_state_action, True)
|
53
|
53
|
|
54
|
54
|
def device_state_action(self, device, key, data):
|
55
|
|
- self.device_states[self.callback_device_list.index(device)] = data
|
|
55
|
+ self.device_states[self.callback_device_list.index((device, key))] = data
|
56
|
56
|
if data is True:
|
57
|
|
- self.active_device_state = self.callback_device_list.index(device)
|
|
57
|
+ self.active_device_state = self.callback_device_list.index((device, key))
|
58
|
58
|
self.update_active_device_led()
|
59
|
59
|
else:
|
60
|
60
|
self.choose_next_device()
|
61
|
61
|
|
62
|
62
|
def update_active_device_led(self):
|
63
|
|
- for i in range(0, len(self.device_list)):
|
|
63
|
+ for i in range(0, len(self.brightness_device_list)):
|
64
|
64
|
self.gui_led_active_device.set_led(devices.nodered_gui_leds.RX_KEYS[i], self.active_device_state == i)
|
65
|
65
|
|
66
|
66
|
def choose_prev_device(self, device=None, key=None, data=None):
|
67
|
67
|
if self.active_device_state is not None:
|
68
|
68
|
start_value = self.active_device_state
|
69
|
|
- for i in range(0, len(self.device_list)):
|
70
|
|
- target_state = (start_value - i - 1) % (len(self.device_list))
|
|
69
|
+ for i in range(0, len(self.brightness_device_list)):
|
|
70
|
+ target_state = (start_value - i - 1) % (len(self.brightness_device_list))
|
71
|
71
|
if self.device_states[target_state]:
|
72
|
72
|
self.active_device_state = target_state
|
73
|
73
|
self.update_active_device_led()
|
|
@@ -78,8 +78,8 @@ class brightness_choose_n_action(object):
|
78
|
78
|
def choose_next_device(self, device=None, key=None, data=None):
|
79
|
79
|
if self.active_device_state is not None:
|
80
|
80
|
start_value = self.active_device_state
|
81
|
|
- for i in range(0, len(self.device_list)):
|
82
|
|
- target_state = (start_value + i + 1) % (len(self.device_list))
|
|
81
|
+ for i in range(0, len(self.brightness_device_list)):
|
|
82
|
+ target_state = (start_value + i + 1) % (len(self.brightness_device_list))
|
83
|
83
|
if self.device_states[target_state]:
|
84
|
84
|
self.active_device_state = target_state
|
85
|
85
|
self.update_active_device_led()
|
|
@@ -89,7 +89,7 @@ class brightness_choose_n_action(object):
|
89
|
89
|
|
90
|
90
|
def brightness_action(self, device, key, data):
|
91
|
91
|
if self.active_device_state is not None:
|
92
|
|
- target = self.device_list[self.active_device_state]
|
|
92
|
+ target = self.brightness_device_list[self.active_device_state]
|
93
|
93
|
if data == devices.tradfri_button.ACTION_BRIGHTNESS_UP_LONG:
|
94
|
94
|
logger.info("Increasing \"%s\" - %s", type(self).__name__, target.topic)
|
95
|
95
|
target.default_inc()
|