smart_brain/function/first_floor_east.py

197 lines
9.3 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import config
import devices
import logging
from function.rooms import room_shelly, room_shelly_tradfri_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 first_floor_east_floor(room_shelly):
def __init__(self, mqtt_client):
# http://shelly1l-3C6105E4E629
super().__init__(mqtt_client, "shellies/floor_madi", "gui/ffe_sw_floor")
def toggle_main_light(self, device, key, data):
logger.info("Toggeling \"%s\" main light", type(self).__name__)
self.main_light_shelly.set_output_0("toggle")
class first_floor_east_kitchen(room_shelly):
# TODO: add circulation pump (switch, time)
def __init__(self, mqtt_client):
# http://shelly1l-8CAAB5616C01
super().__init__(mqtt_client, "shellies/kitchen", "gui/ffe_sw_kitchen")
class first_floor_east_dining(room_shelly):
def __init__(self, mqtt_client):
# http://shelly1l-84CCA8ADD055
super().__init__(mqtt_client, "shellies/diningroom", "gui/ffe_sw_diningroom")
self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, "zigbee_og_e/powerplug/dining_floorlamp")
if config.CHRISTMAS:
self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, topic="zigbee_og_e/powerplug/aux")
#
self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_sw_dining_floorlamp")
#
# Callback initialisation
#
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation)
self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp)
self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0,
None, self.gui_switch_feedback_floorlamp)
#
self.main_light_shelly_last = None
def floorlamp_synchronisation(self, device, key, data):
if data != self.main_light_shelly_last:
logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
self.floorlamp_powerplug.set_output_0(data)
self.main_light_shelly_last = data
def gui_switch_command_floorlamp(self, device, key, data):
logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data))
self.floorlamp_powerplug.set_output_0(data)
def gui_switch_feedback_floorlamp(self, device, key, data):
self.gui_switch_floorlamp.set_feedback(data)
class first_floor_east_sleep_madi(room_shelly_tradfri_light):
def __init__(self, mqtt_client):
# http://shelly1l-E8DB84A254C7
super().__init__(mqtt_client, "shellies/sleep_madi", "gui/ffe_sw_sleep_madi",
"zigbee_og_e/light/sleep_madi", "gui/ffe_br_sleep_madi", "gui/ffe_ct_sleep_madi")
#
self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/sleep_bed_di")
#
self.gui_switch_bed_light_di = devices.nodered_gui(mqtt_client, "gui/ffe_sw_bed_light_di")
self.gui_brightness_bed_light_di = devices.nodered_gui(mqtt_client, "gui/ffe_br_bed_light_di")
self.gui_brightness_bed_light_di.enable(False)
self.gui_brightness_bed_light_di.set_feedback(0)
#
# Callback initialisation
#
self.gui_switch_bed_light_di.add_callback(
devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_bed_light_di)
self.bed_light_di_tradfri.add_callback(
devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_feedback_bed_light_di)
self.bed_light_di_tradfri.add_callback(
devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
self.gui_brightness_bed_light_di.add_callback(
devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_bed_light_di)
def toggle_main_light(self, device, key, data):
logger.info("Toggeling \"%s\" main light", type(self).__name__)
self.main_light_shelly.set_output_0("toggle")
def gui_switch_command_bed_light_di(self, device, key, data):
logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))
self.bed_light_di_tradfri.set_output_0(data)
def gui_switch_feedback_bed_light_di(self, device, key, data):
self.gui_switch_bed_light_di.set_feedback(data)
self.gui_brightness_bed_light_di.enable(data)
if data is False:
self.gui_brightness_bed_light_di.set_feedback(0)
else:
self.gui_brightness_bed_light_di.set_feedback(self.bed_light_di_tradfri.brightness)
def set_gui_brightness_bed_light_di(self, device, key, data):
self.gui_brightness_bed_light_di.set_feedback(data)
def set_brightness_bed_light_di(self, device, key, data):
logger.info("Setting brightness \"%s\" bed light dirk: %.1f", type(self).__name__, data)
self.bed_light_di_tradfri.set_brightness(data)
def toggle_bed_light_di(self, device, key, data):
logger.info("Toggeling \"%s\" bed light dirk", type(self).__name__)
self.bed_light_di_tradfri.set_output_0("toggle")
class first_floor_east_living(room_shelly_tradfri_light):
def __init__(self, mqtt_client):
# http://shelly1l-3C6105E3F910
super().__init__(mqtt_client, "shellies/livingroom", "gui/ffe_sw_livingroom",
"zigbee_og_e/light/livingroom", "gui/ffe_br_livingroom", "gui/ffe_ct_livingroom")
for i in range(1, 7):
setattr(self, 'floorlamp_tradfri_%d' % i,
devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/living_floorlamp_%d" % i))
#
self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_sw_living_floorlamp")
self.gui_brightness_floorlamp = devices.nodered_gui(mqtt_client, "gui/ffe_br_livingroom_floorlamp")
self.gui_brightness_floorlamp.enable(False)
self.gui_brightness_floorlamp.set_feedback(0)
self.gui_color_temp_floorlamp = devices.nodered_gui(mqtt_client, "gui/ffe_ct_livingroom_floorlamp")
self.gui_color_temp_floorlamp.enable(False)
self.gui_color_temp_floorlamp.set_feedback(0)
#
# Callback initialisation
#
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation)
self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp)
self.floorlamp_tradfri_1.add_callback(
devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_feedback_floorlamp)
self.floorlamp_tradfri_1.add_callback(
devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_floorlamp)
self.floorlamp_tradfri_1.add_callback(
devices.tradfri_light.KEY_COLOR_TEMP, None, self.set_gui_color_temp_floorlamp)
self.gui_brightness_floorlamp.add_callback(
devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_floorlamp)
self.gui_color_temp_floorlamp.add_callback(
devices.nodered_gui.KEY_COLOR_TEMP, None, self.set_color_temp_floorlamp)
#
self.main_light_shelly_last = None
def __floorlamp_devices__(self):
rv = []
for i in range(1, 7):
rv.append(getattr(self, 'floorlamp_tradfri_%d' % i))
return rv
def floorlamp_synchronisation(self, device, key, data):
if data != self.main_light_shelly_last:
logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
for device in self.__floorlamp_devices__():
device.set_output_0(data)
self.main_light_shelly_last = data
def gui_switch_command_floorlamp(self, device, key, data):
logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data))
for device in self.__floorlamp_devices__():
device.set_output_0(data)
def gui_switch_feedback_floorlamp(self, device, key, data):
self.gui_switch_floorlamp.set_feedback(data)
self.gui_brightness_floorlamp.enable(data)
self.gui_color_temp_floorlamp.enable(data)
if data is False:
self.gui_brightness_floorlamp.set_feedback(0)
self.gui_color_temp_floorlamp.set_feedback(0)
else:
self.gui_brightness_floorlamp.set_feedback(self.floorlamp_tradfri_1.brightness)
self.gui_color_temp_floorlamp.set_feedback(self.floorlamp_tradfri_1.color_temp / 10)
def set_gui_brightness_floorlamp(self, device, key, data):
self.gui_brightness_floorlamp.set_feedback(data)
def set_gui_color_temp_floorlamp(self, device, key, data):
self.gui_color_temp_floorlamp.set_feedback(data / 10)
def set_brightness_floorlamp(self, device, key, data):
logger.info("Setting brightness \"%s\" floorlamp: %.1f", type(self).__name__, data)
for device in self.__floorlamp_devices__():
device.set_brightness(data)
def set_color_temp_floorlamp(self, device, key, data):
logger.info("Setting color_temp \"%s\" floorlamp: %.1f", type(self).__name__, data)
for device in self.__floorlamp_devices__():
device.set_color_temp(data * 10)