main functionality for gfw_dirk added
This commit is contained in:
parent
713bf4d017
commit
6ed355a44b
@ -49,6 +49,120 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
|
|||||||
def __init__(self, mqtt_client):
|
def __init__(self, mqtt_client):
|
||||||
super().__init__(mqtt_client, "shellies/dirk", "gui/gfw_sw_dirk",
|
super().__init__(mqtt_client, "shellies/dirk", "gui/gfw_sw_dirk",
|
||||||
"zigbee_eg_w/light/dirk", "gui/gfw_br_dirk", "gui/gfw_ct_dirk")
|
"zigbee_eg_w/light/dirk", "gui/gfw_br_dirk", "gui/gfw_ct_dirk")
|
||||||
|
#
|
||||||
|
self.powerplug_common = devices.my_powerplug(mqtt_client, "powerplug/dirk")
|
||||||
|
self.desk_light_tradfri = devices.tradfri_light(mqtt_client, "zigbee_eg_w/light/dirk_desk")
|
||||||
|
self.button_tradfri = devices.tradfri_button(mqtt_client, "zigbee_eg_w/input_device/dirk")
|
||||||
|
#
|
||||||
|
self.powerplug_common.add_callback(None, None, self.powerplug_common_actions)
|
||||||
|
#
|
||||||
|
self.gui_switch_desk_light = devices.nodered_gui(mqtt_client, "gui/gfw_sw_desk_light")
|
||||||
|
self.gui_brightness_desk_light = devices.nodered_gui(mqtt_client, "gui/gfw_br_desk_light")
|
||||||
|
self.gui_brightness_desk_light.enable(False)
|
||||||
|
self.gui_brightness_desk_light.set_feedback(0)
|
||||||
|
self.gui_color_temp_desk_light = devices.nodered_gui(mqtt_client, "gui/gfw_ct_desk_light")
|
||||||
|
self.gui_color_temp_desk_light.enable(False)
|
||||||
|
self.gui_color_temp_desk_light.set_feedback(0)
|
||||||
|
#
|
||||||
|
self.gui_switch_amplifier = devices.nodered_gui(mqtt_client, "gui/gfw_sw_amplifier")
|
||||||
|
self.gui_switch_cd_player = devices.nodered_gui(mqtt_client, "gui/gfw_sw_cd_player")
|
||||||
|
self.gui_switch_pc_dock = devices.nodered_gui(mqtt_client, "gui/gfw_sw_pc_dock")
|
||||||
|
#
|
||||||
|
self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
|
||||||
|
devices.tradfri_button.ACTION_TOGGLE, self.toggle_main_light)
|
||||||
|
self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
|
||||||
|
devices.tradfri_button.ACTION_RIGHT, self.desk_light_switch_action)
|
||||||
|
self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
|
||||||
|
devices.tradfri_button.ACTION_LEFT_LONG, self.amplifier_switch_action)
|
||||||
|
self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
|
||||||
|
devices.tradfri_button.ACTION_RIGHT_LONG, self.cd_player_switch_action)
|
||||||
|
self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
|
||||||
|
devices.tradfri_button.ACTION_LEFT, self.pc_dock_switch_action)
|
||||||
|
#
|
||||||
|
self.gui_switch_desk_light.add_callback(devices.nodered_gui.KEY_STATE, None, self.desk_light_switch_action)
|
||||||
|
self.gui_brightness_desk_light.add_callback(
|
||||||
|
devices.nodered_gui.KEY_BRIGHTNESS, None, self.desk_light_set_params_action)
|
||||||
|
self.gui_color_temp_desk_light.add_callback(
|
||||||
|
devices.nodered_gui.KEY_COLOR_TEMP, None, self.desk_light_set_params_action)
|
||||||
|
self.desk_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS,
|
||||||
|
None, self.desk_light_set_gui_params_action)
|
||||||
|
self.desk_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP,
|
||||||
|
None, self.desk_light_set_gui_params_action)
|
||||||
|
#
|
||||||
|
self.gui_switch_amplifier.add_callback(devices.nodered_gui.KEY_STATE, None, self.amplifier_switch_action)
|
||||||
|
self.gui_switch_cd_player.add_callback(devices.nodered_gui.KEY_STATE, None, self.cd_player_switch_action)
|
||||||
|
self.gui_switch_pc_dock.add_callback(devices.nodered_gui.KEY_STATE, None, self.pc_dock_switch_action)
|
||||||
|
#
|
||||||
|
self.last_cd_player_powerplug_state = None
|
||||||
|
|
||||||
def all_off(self, device=None, key=None, data=None):
|
def all_off(self, device=None, key=None, data=None):
|
||||||
super().all_off(device, key, data)
|
super().all_off(device, key, data)
|
||||||
|
self.powerplug_common.set_output_all(False)
|
||||||
|
|
||||||
|
def powerplug_common_actions(self, device, key, data):
|
||||||
|
if key == devices.my_powerplug.KEY_OUTPUT_0:
|
||||||
|
self.gui_switch_amplifier.set_feedback(data)
|
||||||
|
elif key == devices.my_powerplug.KEY_OUTPUT_1:
|
||||||
|
self.gui_switch_desk_light.set_feedback(data)
|
||||||
|
self.gui_brightness_desk_light.enable(data)
|
||||||
|
self.gui_color_temp_desk_light.enable(data)
|
||||||
|
if not data:
|
||||||
|
self.gui_brightness_desk_light.set_feedback(0)
|
||||||
|
self.gui_color_temp_desk_light.set_feedback(0)
|
||||||
|
else:
|
||||||
|
self.gui_brightness_desk_light.set_feedback(self.desk_light_tradfri.brightness)
|
||||||
|
self.gui_color_temp_desk_light.set_feedback(self.desk_light_tradfri.color_temp / 10)
|
||||||
|
elif key == devices.my_powerplug.KEY_OUTPUT_2:
|
||||||
|
self.gui_switch_cd_player.set_feedback(data)
|
||||||
|
if data != self.last_cd_player_powerplug_state:
|
||||||
|
logger.info("Setting \"%s\" amplifier: %s", type(self).__name__, data)
|
||||||
|
self.powerplug_common.set_output_0(data)
|
||||||
|
self.last_cd_player_powerplug_state = data
|
||||||
|
elif key == devices.my_powerplug.KEY_OUTPUT_3:
|
||||||
|
self.gui_switch_pc_dock.set_feedback(data)
|
||||||
|
|
||||||
|
def desk_light_switch_action(self, device, key, data):
|
||||||
|
if device == self.button_tradfri:
|
||||||
|
logger.info("Toggeling \"%s\" desk_light to %s", type(self).__name__, not self.powerplug_common.output_1)
|
||||||
|
self.powerplug_common.set_output_1("toggle")
|
||||||
|
else:
|
||||||
|
logger.info("Setting \"%s\" desk light: %s", type(self).__name__, data)
|
||||||
|
self.powerplug_common.set_output_1(data)
|
||||||
|
|
||||||
|
def desk_light_set_gui_params_action(self, device, key, data):
|
||||||
|
if key == devices.nodered_gui.KEY_BRIGHTNESS:
|
||||||
|
self.gui_brightness_desk_light.set_feedback(data)
|
||||||
|
elif key == devices.nodered_gui.KEY_COLOR_TEMP:
|
||||||
|
self.gui_color_temp_desk_light.set_feedback(data / 10)
|
||||||
|
|
||||||
|
def desk_light_set_params_action(self, device, key, data):
|
||||||
|
if key == devices.nodered_gui.KEY_BRIGHTNESS:
|
||||||
|
logger.info("Setting brightness \"%s\" desk light: %s", type(self).__name__, data)
|
||||||
|
self.desk_light_tradfri.set_brightness(data)
|
||||||
|
elif key == devices.nodered_gui.KEY_COLOR_TEMP:
|
||||||
|
logger.info("Setting color_temp \"%s\" desk light: %s", type(self).__name__, data)
|
||||||
|
self.desk_light_tradfri.set_color_temp(data * 10)
|
||||||
|
|
||||||
|
def amplifier_switch_action(self, device, key, data):
|
||||||
|
if device == self.button_tradfri:
|
||||||
|
logger.info("Toggeling \"%s\" amplifier to %s", type(self).__name__, not self.powerplug_common.output_0)
|
||||||
|
self.powerplug_common.set_output_0("toggle")
|
||||||
|
else:
|
||||||
|
logger.info("Setting \"%s\" amplifier: %s", type(self).__name__, data)
|
||||||
|
self.powerplug_common.set_output_0(data)
|
||||||
|
|
||||||
|
def cd_player_switch_action(self, device, key, data):
|
||||||
|
if device == self.button_tradfri:
|
||||||
|
logger.info("Toggeling \"%s\" cd_player to %s", type(self).__name__, not self.powerplug_common.output_2)
|
||||||
|
self.powerplug_common.set_output_2("toggle")
|
||||||
|
else:
|
||||||
|
logger.info("Setting \"%s\" cd_player: %s", type(self).__name__, data)
|
||||||
|
self.powerplug_common.set_output_2(data)
|
||||||
|
|
||||||
|
def pc_dock_switch_action(self, device, key, data):
|
||||||
|
if device == self.button_tradfri:
|
||||||
|
logger.info("Toggeling \"%s\" pc_dock to %s", type(self).__name__, not self.powerplug_common.output_3)
|
||||||
|
self.powerplug_common.set_output_3("toggle")
|
||||||
|
else:
|
||||||
|
logger.info("Setting \"%s\" pc_dock: %s", type(self).__name__, data)
|
||||||
|
self.powerplug_common.set_output_3(data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user