169 lines
9.0 KiB
Python
169 lines
9.0 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
#
|
|
|
|
import devices
|
|
import logging
|
|
from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light
|
|
|
|
try:
|
|
from config import APP_NAME as ROOT_LOGGER_NAME
|
|
except ImportError:
|
|
ROOT_LOGGER_NAME = 'root'
|
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
|
|
|
|
|
class ground_floor_west_floor(room_shelly_silvercrest_light):
|
|
# https://shelly1l-84CCA8AD1148
|
|
def __init__(self, mqtt_client):
|
|
super().__init__(mqtt_client, "shellies/floor_eg_w", "gui/gfw_sw_floor",
|
|
"zigbee_eg_w/light/floor_eg_w/a", "gui/gfw_br_floor", "gui/gfw_ct_floor")
|
|
#
|
|
# Callback initialisation
|
|
#
|
|
self.main_light_tradfri_2 = devices.tradfri_light(mqtt_client, "zigbee_eg_w/light/floor_eg_w/b")
|
|
self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS,
|
|
None, self.sync_brightness_main_light)
|
|
self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP,
|
|
None, self.sync_color_temp_main_light)
|
|
|
|
def send_init_message_main_light(self):
|
|
return super().send_init_message_main_light()
|
|
self.main_light_tradfri_2.mqtt_client.send(self.main_light_tradfri_2.topic + "/get", '{"state": ""}')
|
|
|
|
def sync_brightness_main_light(self, device, key, data):
|
|
self.main_light_tradfri_2.set_brightness(data)
|
|
|
|
def sync_color_temp_main_light(self, device, key, data):
|
|
self.main_light_tradfri_2.set_color_temp(data)
|
|
|
|
|
|
class ground_floor_west_marion(room_shelly):
|
|
# https://shelly1l-E8DB84A1E067
|
|
def __init__(self, mqtt_client):
|
|
super().__init__(mqtt_client, "shellies/marion", "gui/gfw_sw_marion")
|
|
|
|
|
|
class ground_floor_west_dirk(room_shelly_tradfri_light):
|
|
# https://shelly1l-3C6105E44F27
|
|
def __init__(self, mqtt_client):
|
|
super().__init__(mqtt_client, "shellies/dirk", "gui/gfw_sw_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):
|
|
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)
|