bug-fix for brightness_choose_n_action
This commit is contained in:
parent
d9963b13c0
commit
8ba63349fb
@ -215,12 +215,6 @@ class shelly(base):
|
|||||||
def __init__(self, mqtt_client, topic):
|
def __init__(self, mqtt_client, topic):
|
||||||
super().__init__(mqtt_client, topic)
|
super().__init__(mqtt_client, topic)
|
||||||
|
|
||||||
def add_on_off_callback_0(self, callback):
|
|
||||||
self.add_callback(self.KEY_OUTPUT_0, None, callback, True)
|
|
||||||
|
|
||||||
def add_on_off_callback_1(self, callback):
|
|
||||||
self.add_callback(self.KEY_OUTPUT_1, None, callback, True)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# WARNING CALL
|
# WARNING CALL
|
||||||
#
|
#
|
||||||
@ -313,9 +307,6 @@ class silvercrest_powerplug(base):
|
|||||||
def __init__(self, mqtt_client, topic):
|
def __init__(self, mqtt_client, topic):
|
||||||
super().__init__(mqtt_client, topic)
|
super().__init__(mqtt_client, topic)
|
||||||
|
|
||||||
def add_default_on_off_callback(self, callback):
|
|
||||||
self.add_callback(self.KEY_OUTPUT_0, None, callback, True)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# RX
|
# RX
|
||||||
#
|
#
|
||||||
@ -389,18 +380,6 @@ class my_powerplug(base):
|
|||||||
def __init__(self, mqtt_client, topic):
|
def __init__(self, mqtt_client, topic):
|
||||||
super().__init__(mqtt_client, topic)
|
super().__init__(mqtt_client, topic)
|
||||||
|
|
||||||
def add_on_off_callback_0(self, callback):
|
|
||||||
self.add_callback(self.KEY_OUTPUT_0, None, callback, True)
|
|
||||||
|
|
||||||
def add_on_off_callback_1(self, callback):
|
|
||||||
self.add_callback(self.KEY_OUTPUT_1, None, callback, True)
|
|
||||||
|
|
||||||
def add_on_off_callback_2(self, callback):
|
|
||||||
self.add_callback(self.KEY_OUTPUT_2, None, callback, True)
|
|
||||||
|
|
||||||
def add_on_off_callback_3(self, callback):
|
|
||||||
self.add_callback(self.KEY_OUTPUT_3, None, callback, True)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# RX
|
# RX
|
||||||
#
|
#
|
||||||
@ -511,9 +490,6 @@ class tradfri_light(base):
|
|||||||
def __init__(self, mqtt_client, topic):
|
def __init__(self, mqtt_client, topic):
|
||||||
super().__init__(mqtt_client, topic)
|
super().__init__(mqtt_client, topic)
|
||||||
|
|
||||||
def add_on_off_callback_0(self, callback):
|
|
||||||
self.add_callback(self.KEY_OUTPUT_0, None, callback, True)
|
|
||||||
|
|
||||||
def unpack_filter(self, key):
|
def unpack_filter(self, key):
|
||||||
if key == self.KEY_BRIGHTNESS:
|
if key == self.KEY_BRIGHTNESS:
|
||||||
self[key] = (self[key] - 1) * 100 / 254
|
self[key] = (self[key] - 1) * 100 / 254
|
||||||
|
@ -59,10 +59,10 @@ class all_functions(object):
|
|||||||
|
|
||||||
def init_off_functionality(self):
|
def init_off_functionality(self):
|
||||||
# Off Buttons
|
# Off Buttons
|
||||||
self.gui_button_all_off = devices.nodered_gui_button(self.mqtt_client, topic="gui/all/common/off/button")
|
self.gui_button_all_off = devices.nodered_gui_button(self.mqtt_client, "gui/all/common/off/button")
|
||||||
self.gui_button_gfw_off = devices.nodered_gui_button(self.mqtt_client, topic="gui/gfw/common/off/button")
|
self.gui_button_gfw_off = devices.nodered_gui_button(self.mqtt_client, "gui/gfw/common/off/button")
|
||||||
self.gui_button_ffw_off = devices.nodered_gui_button(self.mqtt_client, topic="gui/ffw/common/off/button")
|
self.gui_button_ffw_off = devices.nodered_gui_button(self.mqtt_client, "gui/ffw/common/off/button")
|
||||||
self.gui_button_ffe_off = devices.nodered_gui_button(self.mqtt_client, topic="gui/ffe/common/off/button")
|
self.gui_button_ffe_off = devices.nodered_gui_button(self.mqtt_client, "gui/ffe/common/off/button")
|
||||||
#
|
#
|
||||||
self.gui_button_all_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.all_off)
|
self.gui_button_all_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.all_off)
|
||||||
self.gui_button_gfw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.gfw_off)
|
self.gui_button_gfw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.gfw_off)
|
||||||
|
@ -63,8 +63,8 @@ class first_floor_east_sleep(room_shelly_tradfri_light):
|
|||||||
self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
|
self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
|
||||||
#
|
#
|
||||||
self.brightness_functions = brightness_choose_n_action(mqtt_client, self.button_tradfri, config.TOPIC_FFE_SLEEP_DEVICE_CHOOSER_LED)
|
self.brightness_functions = brightness_choose_n_action(mqtt_client, self.button_tradfri, config.TOPIC_FFE_SLEEP_DEVICE_CHOOSER_LED)
|
||||||
self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly.add_on_off_callback_0)
|
self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
|
||||||
self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri.add_on_off_callback_0)
|
self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0)
|
||||||
#
|
#
|
||||||
# Callback initialisation
|
# Callback initialisation
|
||||||
#
|
#
|
||||||
|
@ -77,9 +77,9 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
|
|||||||
self.remote_amplifier = devices.remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
|
self.remote_amplifier = devices.remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
|
||||||
#
|
#
|
||||||
self.brightness_functions = brightness_choose_n_action(mqtt_client, self.button_tradfri, config.TOPIC_GFW_DIRK_DEVICE_CHOOSER_LED)
|
self.brightness_functions = brightness_choose_n_action(mqtt_client, self.button_tradfri, config.TOPIC_GFW_DIRK_DEVICE_CHOOSER_LED)
|
||||||
self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly.add_on_off_callback_0)
|
self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
|
||||||
self.brightness_functions.add(self.desk_light_tradfri, self.powerplug_common.add_on_off_callback_1)
|
self.brightness_functions.add(self.desk_light_tradfri, self.powerplug_common, self.KEY_POWERPLUG_DESK_LIGHT)
|
||||||
self.brightness_functions.add(self.remote_amplifier, self.powerplug_common.add_on_off_callback_0)
|
self.brightness_functions.add(self.remote_amplifier, self.powerplug_common, self.KEY_POWERPLUG_AMPLIFIER)
|
||||||
#
|
#
|
||||||
self.spotify_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_SPOTIFY)
|
self.spotify_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_SPOTIFY)
|
||||||
self.mpd_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_MPD)
|
self.mpd_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_MPD)
|
||||||
|
@ -28,46 +28,46 @@ class brightness_choose_n_action(object):
|
|||||||
button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_UP, self.choose_next_device)
|
button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_UP, self.choose_next_device)
|
||||||
button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_DOWN, self.choose_prev_device)
|
button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_DOWN, self.choose_prev_device)
|
||||||
#
|
#
|
||||||
self.device_list = []
|
self.brightness_device_list = []
|
||||||
self.callback_device_list = []
|
self.callback_device_list = []
|
||||||
self.device_states = []
|
self.device_states = []
|
||||||
self.active_device_state = None
|
self.active_device_state = None
|
||||||
self.update_active_device_led()
|
self.update_active_device_led()
|
||||||
|
|
||||||
def add(self, device, add_callback):
|
def add(self, brightness_device, callback_device, callback_key):
|
||||||
"""
|
"""
|
||||||
device: A device for brightness function needs to have the following methods:
|
brightness_device: A device for brightness function needs to have the following methods:
|
||||||
* .default_inc()
|
* .default_inc()
|
||||||
* .default_dec()
|
* .default_dec()
|
||||||
* .default_stop()
|
* .default_stop()
|
||||||
add_callback: A on/off callback which tages the <function_to_be_executed> as argument and
|
callback_device: A device for installing callback which are executed, when the device is switched on or off. It needs the following method:
|
||||||
- which calls the callback only on changes
|
* .add_callback(key, data or None, callback, on_changes_only)
|
||||||
- which calls with the following arguments: device, key, data
|
|
||||||
"""
|
"""
|
||||||
if len(self.device_list) >= len(devices.nodered_gui_leds.RX_KEYS):
|
if len(self.brightness_device_list) >= len(devices.nodered_gui_leds.RX_KEYS):
|
||||||
raise ValueError("Number of devices is limited by number of leds in devices.nodered_gui_leds.")
|
raise ValueError("Number of devices is limited by number of leds in devices.nodered_gui_leds.")
|
||||||
self.device_list.append(device)
|
self.brightness_device_list.append(brightness_device)
|
||||||
self.callback_device_list.append(add_callback.__self__)
|
self.callback_device_list.append((callback_device, callback_key))
|
||||||
self.device_states.append(False)
|
self.device_states.append(False)
|
||||||
add_callback(self.device_state_action)
|
callback_device.add_callback(callback_key, True, self.device_state_action, True)
|
||||||
|
callback_device.add_callback(callback_key, False, self.device_state_action, True)
|
||||||
|
|
||||||
def device_state_action(self, device, key, data):
|
def device_state_action(self, device, key, data):
|
||||||
self.device_states[self.callback_device_list.index(device)] = data
|
self.device_states[self.callback_device_list.index((device, key))] = data
|
||||||
if data is True:
|
if data is True:
|
||||||
self.active_device_state = self.callback_device_list.index(device)
|
self.active_device_state = self.callback_device_list.index((device, key))
|
||||||
self.update_active_device_led()
|
self.update_active_device_led()
|
||||||
else:
|
else:
|
||||||
self.choose_next_device()
|
self.choose_next_device()
|
||||||
|
|
||||||
def update_active_device_led(self):
|
def update_active_device_led(self):
|
||||||
for i in range(0, len(self.device_list)):
|
for i in range(0, len(self.brightness_device_list)):
|
||||||
self.gui_led_active_device.set_led(devices.nodered_gui_leds.RX_KEYS[i], self.active_device_state == i)
|
self.gui_led_active_device.set_led(devices.nodered_gui_leds.RX_KEYS[i], self.active_device_state == i)
|
||||||
|
|
||||||
def choose_prev_device(self, device=None, key=None, data=None):
|
def choose_prev_device(self, device=None, key=None, data=None):
|
||||||
if self.active_device_state is not None:
|
if self.active_device_state is not None:
|
||||||
start_value = self.active_device_state
|
start_value = self.active_device_state
|
||||||
for i in range(0, len(self.device_list)):
|
for i in range(0, len(self.brightness_device_list)):
|
||||||
target_state = (start_value - i - 1) % (len(self.device_list))
|
target_state = (start_value - i - 1) % (len(self.brightness_device_list))
|
||||||
if self.device_states[target_state]:
|
if self.device_states[target_state]:
|
||||||
self.active_device_state = target_state
|
self.active_device_state = target_state
|
||||||
self.update_active_device_led()
|
self.update_active_device_led()
|
||||||
@ -78,8 +78,8 @@ class brightness_choose_n_action(object):
|
|||||||
def choose_next_device(self, device=None, key=None, data=None):
|
def choose_next_device(self, device=None, key=None, data=None):
|
||||||
if self.active_device_state is not None:
|
if self.active_device_state is not None:
|
||||||
start_value = self.active_device_state
|
start_value = self.active_device_state
|
||||||
for i in range(0, len(self.device_list)):
|
for i in range(0, len(self.brightness_device_list)):
|
||||||
target_state = (start_value + i + 1) % (len(self.device_list))
|
target_state = (start_value + i + 1) % (len(self.brightness_device_list))
|
||||||
if self.device_states[target_state]:
|
if self.device_states[target_state]:
|
||||||
self.active_device_state = target_state
|
self.active_device_state = target_state
|
||||||
self.update_active_device_led()
|
self.update_active_device_led()
|
||||||
@ -89,7 +89,7 @@ class brightness_choose_n_action(object):
|
|||||||
|
|
||||||
def brightness_action(self, device, key, data):
|
def brightness_action(self, device, key, data):
|
||||||
if self.active_device_state is not None:
|
if self.active_device_state is not None:
|
||||||
target = self.device_list[self.active_device_state]
|
target = self.brightness_device_list[self.active_device_state]
|
||||||
if data == devices.tradfri_button.ACTION_BRIGHTNESS_UP_LONG:
|
if data == devices.tradfri_button.ACTION_BRIGHTNESS_UP_LONG:
|
||||||
logger.info("Increasing \"%s\" - %s", type(self).__name__, target.topic)
|
logger.info("Increasing \"%s\" - %s", type(self).__name__, target.topic)
|
||||||
target.default_inc()
|
target.default_inc()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user