smart_brain/function/__init__.py

75 linhas
3.1 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import config
import devices
from function.stairway import stairway
from function.ground_floor_west import ground_floor_west
from function.first_floor_west import first_floor_west
from function.first_floor_east import first_floor_east
from function.rooms import room_collection
from function.videv import all_off, videv_warnings
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__)
class all_functions(room_collection):
def __init__(self, mqtt_client):
super().__init__(mqtt_client)
#
# Rooms
#
# stairway
self.stw = stairway(self.mqtt_client)
# ground floor west
self.gfw = ground_floor_west(self.mqtt_client)
# first floor west
self.ffw = first_floor_west(self.mqtt_client)
# first floor east
self.ffe = first_floor_east(self.mqtt_client)
#
# Interactions
#
# cross_room_interactions
self.init_cross_room_interactions()
# Off Buttons
self.init_off_functionality()
# Warnings
videv_warning = videv_warnings(self.mqtt_client, config.TOPIC_WARNINGS)
for device in self.all_devices():
device.add_callback(devices.base.KEY_WARNING, None, videv_warning.warningcollector)
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):
# ALL OFF - Virtual device
self.videv_all_off = all_off(self.mqtt_client, config.TOPIC_ALL_OFF_VIDEV, self)
# 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.all_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.all_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