123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- import devices
- from function.stairway import stairway
- from function.ground_floor_west import ground_floor_west_floor, ground_floor_west_marion, ground_floor_west_dirk
- from function.first_floor_west import first_floor_west_julian, first_floor_west_living, first_floor_west_bath, first_floor_west_sleep
- from function.first_floor_east import first_floor_east_floor, first_floor_east_kitchen, first_floor_east_dining, first_floor_east_sleep, first_floor_east_living
- import inspect
- import logging
-
- try:
- from config import APP_NAME as ROOT_LOGGER_NAME
- except ImportError:
- ROOT_LOGGER_NAME = 'root'
- logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
-
- # TODO: implement garland (incl. day events like sunset, sunrise, ...)
- # TODO: implement warning message
-
-
- class all_functions(object):
- def __init__(self, mqtt_client):
- self.mqtt_client = mqtt_client
- #
- self.__devices__ = None
- #
- # Rooms
- #
- # stairway
- self.stw_stairway = stairway(self.mqtt_client)
- # ground floor west
- self.gfw_floor = ground_floor_west_floor(self.mqtt_client)
- self.gfw_marion = ground_floor_west_marion(self.mqtt_client)
- self.gfw_dirk = ground_floor_west_dirk(self.mqtt_client)
- # first floor west
- self.ffw_julian = first_floor_west_julian(self.mqtt_client)
- self.ffw_bath = first_floor_west_bath(self.mqtt_client)
- self.ffw_living = first_floor_west_living(self.mqtt_client)
- self.ffw_sleep = first_floor_west_sleep(self.mqtt_client)
- # first floor east
- self.ffe_floor = first_floor_east_floor(self.mqtt_client)
- self.ffe_kitchen = first_floor_east_kitchen(self.mqtt_client)
- self.ffe_dining = first_floor_east_dining(self.mqtt_client)
- self.ffe_sleep = first_floor_east_sleep(self.mqtt_client)
- self.ffe_living = first_floor_east_living(self.mqtt_client)
- #
- # Interactions
- #
- # cross_room_interactions
- self.init_cross_room_interactions()
- # Off Buttons
- self.init_off_functionality()
-
- def init_cross_room_interactions(self):
- # shelly dirk input 1
- self.last_gfw_dirk_input_1 = None
- self.gfw_dirk.main_light_shelly.add_callback(devices.shelly.KEY_INPUT_1, None, self.gfw_dirk_input_1)
- # tradfri button ffe_sleep right click
- self.ffe_sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
- devices.tradfri_button.ACTION_RIGHT, self.ffe_floor.main_light_shelly.toggle_output_0_mcb)
-
- def init_off_functionality(self):
- ##### TEMPORARY ###################################################################################################################
- # Off Buttons
- 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, "gui/gfw/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, "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_gfw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.gfw_off)
- self.gui_button_ffw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffw_off)
- self.gui_button_ffe_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffe_off)
- ##### TEMPORARY ###################################################################################################################
-
- # ALL OFF - Long push stairway
- self.stw_stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.stw_stairway.main_light_shelly.flash_0_mcb)
- self.stw_stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.all_off)
-
- # FFE ALL OFF - Long push ffe_floor
- self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_floor.main_light_shelly.flash_0_mcb)
- self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_off)
-
- # FFE ALL OFF - Long push input device
- self.ffe_sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe_off)
-
- def gfw_dirk_input_1(self, device, key, data):
- if self.last_gfw_dirk_input_1 is not None:
- if self.last_gfw_dirk_input_1 != data:
- self.gfw_floor.main_light_shelly.toggle_output_0_mcb(device, key, data)
- self.last_gfw_dirk_input_1 = data
-
- def getmembers(self, prefix):
- rv = []
- for name, obj in inspect.getmembers(self):
- if name.startswith(prefix) and obj.__module__.split('.')[0] == 'function' and len(obj.__module__.split('.')) == 2:
- rv.append(obj)
- return rv
-
- def common_off(self, device=None, key=None, data=None):
- logger.info("Switching \"common\" off.")
- for common in self.getmembers('common'):
- common.all_off()
-
- def gfw_off(self, device=None, key=None, data=None):
- logger.info("Switching \"ground floor west\" off.")
- for gfw in self.getmembers('gfw'):
- gfw.all_off()
-
- def ffw_off(self, device=None, key=None, data=None):
- logger.info("Switching \"first floor west\" off.")
- for ffw in self.getmembers('ffw'):
- ffw.all_off()
-
- def ffe_off(self, device=None, key=None, data=None):
- logger.info("Switching \"first floor east\" off.")
- for ffe in self.getmembers('ffe'):
- ffe.all_off()
-
- def stw_off(self, device=None, key=None, data=None):
- logger.info("Switching \"stairway\" off.")
- for stw in self.getmembers('stw'):
- stw.all_off()
-
- def all_off(self, device=None, key=None, data=None):
- self.common_off(device, key, data)
- self.gfw_off(device, key, data)
- self.ffw_off(device, key, data)
- self.ffe_off(device, key, data)
- self.stw_off(device, key, data)
-
- def devicelist(self):
- if self.__devices__ is None:
- self.__devices__ = []
- for name, obj in inspect.getmembers(self):
- if obj.__class__.__module__ == "devices":
- self.__devices__.append(obj)
- elif obj.__class__.__module__.split('.')[0] == 'function':
- for devicename, device in inspect.getmembers(obj):
- if device.__class__.__module__ == "devices":
- self.__devices__.append(device)
- return self.__devices__
|