64 lines
2.5 KiB
Python
Raw Normal View History

2022-12-20 14:05:32 +01:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import logging
2022-12-21 17:04:55 +01:00
import task
2022-12-20 14:05:32 +01:00
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: all_off: getattr and identify switchable devices switch those off (default method of device)
# - all devices are as attributes in the room class
# - implement a all_off blacklist to be initialised while __init__
# TODO: implement all off and user feedback method (all off save)
2022-12-20 14:05:32 +01:00
class room(object):
def __init__(self, mqtt_client):
self.mqtt_client = mqtt_client
2022-12-21 17:04:55 +01:00
#
2022-12-22 07:55:56 +01:00
self.block_all_off = False
2022-12-21 17:04:55 +01:00
self.last_flash_data = None
try:
self.delayed_task = task.delayed(.25, self.main_light_shelly.toggle_output_0_mcb, None, None, None)
except AttributeError:
logger.exception("Device self.main_light does not exist!")
self.delayed_task = task.delayed(.25, self.__delayed_task_dummy__, None, None, None)
def __delayed_task_dummy__(self, device, key, data):
logger.exception("Device self.main_light does not exist!")
2022-12-20 14:05:32 +01:00
def all_off(self, device=None, key=None, data=None):
2022-12-22 07:55:56 +01:00
if not self.block_all_off:
logger.info("Switching all off \"%s\"", type(self).__name__)
try:
self.main_light_shelly.set_output_0(False)
self.main_light_shelly.set_output_1(False)
except AttributeError:
logger.exception("Device self.main_light does not exist!")
2022-12-22 07:55:56 +01:00
self.block_all_off = False
def all_off_feedback(self, device=None, key=None, data=None):
logger.info("Flashing \"%s\" main light", type(self).__name__)
if self.main_light_shelly.output_0 is False:
try:
self.main_light_shelly.set_output_0(True)
except AttributeError:
logger.exception("Device self.main_light does not exist!")
2022-12-22 07:55:56 +01:00
self.block_all_off = True
self.delayed_task.run()
2022-12-20 14:05:32 +01:00
2022-12-21 17:04:55 +01:00
def flash_main_light(self, device, key, data):
if self.last_flash_data != data and data is True:
logger.info("Flashing \"%s\" main light", type(self).__name__)
try:
self.main_light_shelly.toggle_output_0_mcb(device, key, data)
except AttributeError:
logger.exception("Device self.main_light does not exist!")
2022-12-21 17:04:55 +01:00
self.delayed_task.run()
self.last_flash_data = data