smart_brain/function/__init__.py

75 lines
3.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
2023-01-31 19:17:10 +01:00
import config
2022-12-19 16:11:35 +01:00
import devices
2022-12-28 08:48:07 +01:00
from function.stairway import stairway
2023-01-31 19:17:10 +01:00
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
2023-02-10 14:34:49 +01:00
from function.videv import all_off, videv_warnings
2022-12-22 07:55:56 +01:00
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__)
2022-12-19 16:11:35 +01:00
2023-01-31 19:17:10 +01:00
class all_functions(room_collection):
def __init__(self, mqtt_client):
2023-01-31 19:17:10 +01:00
super().__init__(mqtt_client)
#
# Rooms
#
2022-12-28 08:48:07 +01:00
# stairway
2023-01-31 19:17:10 +01:00
self.stw = stairway(self.mqtt_client)
2022-12-21 17:04:55 +01:00
# ground floor west
2023-01-31 19:17:10 +01:00
self.gfw = ground_floor_west(self.mqtt_client)
2022-12-20 10:18:32 +01:00
# first floor west
2023-01-31 19:17:10 +01:00
self.ffw = first_floor_west(self.mqtt_client)
# first floor east
2023-01-31 19:17:10 +01:00
self.ffe = first_floor_east(self.mqtt_client)
2022-12-20 19:38:57 +01:00
#
2022-12-21 17:04:55 +01:00
# Interactions
#
2022-12-22 07:55:56 +01:00
# cross_room_interactions
self.init_cross_room_interactions()
# Off Buttons
self.init_off_functionality()
2023-02-10 14:34:49 +01:00
# 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)
2022-12-20 19:38:57 +01:00
def init_cross_room_interactions(self):
# shelly dirk input 1
self.last_gfw_dirk_input_1 = None
2023-01-31 19:17:10 +01:00
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
2023-01-31 19:17:10 +01:00
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)
2022-12-22 07:55:56 +01:00
def init_off_functionality(self):
2023-01-31 19:17:10 +01:00
# ALL OFF - Virtual device
self.videv_all_off = all_off(self.mqtt_client, config.TOPIC_ALL_OFF_VIDEV, self)
# ALL OFF - Long push stairway
2023-01-31 19:17:10 +01:00
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
2023-01-31 19:17:10 +01:00
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
2023-01-31 19:17:10 +01:00
self.ffe.sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe.all_off)
2022-12-22 07:55:56 +01:00
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:
2023-01-31 19:17:10 +01:00
self.gfw.floor.main_light_shelly.toggle_output_0_mcb(device, key, data)
self.last_gfw_dirk_input_1 = data