User feedback (flash) implemented in new structure
This commit is contained in:
parent
52bb35c2c2
commit
43308d858e
@ -26,15 +26,13 @@ devices (DEVICES)
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO: Usage of mqtt_base for all devices
|
|
||||||
#
|
|
||||||
# TODO: brennenstuhl_heatingvalve: always send "{"preset": "manual", "system_mode": "heat"}" with any information
|
|
||||||
# TODO: usage of base.mqtt as parent for class base
|
# TODO: usage of base.mqtt as parent for class base
|
||||||
|
|
||||||
__DEPENDENCIES__ = []
|
__DEPENDENCIES__ = []
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import task
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from config import APP_NAME as ROOT_LOGGER_NAME
|
from config import APP_NAME as ROOT_LOGGER_NAME
|
||||||
@ -265,6 +263,26 @@ class shelly(base):
|
|||||||
|
|
||||||
def __init__(self, mqtt_client, topic):
|
def __init__(self, mqtt_client, topic):
|
||||||
super().__init__(mqtt_client, topic)
|
super().__init__(mqtt_client, topic)
|
||||||
|
#
|
||||||
|
self.output_key_delayed = None
|
||||||
|
self.delayed_flash_task = task.delayed(0.3, self.flash_task)
|
||||||
|
self.delayed_off_task = task.delayed(0.3, self.off_task)
|
||||||
|
#
|
||||||
|
self.all_off_requested = False
|
||||||
|
|
||||||
|
def flash_task(self, *args):
|
||||||
|
if self.flash_active:
|
||||||
|
self.pack(self.output_key_delayed, not self.get(self.output_key_delayed))
|
||||||
|
self.output_key_delayed = None
|
||||||
|
if self.all_off_requested:
|
||||||
|
self.delayed_off_task.run()
|
||||||
|
|
||||||
|
def off_task(self, *args):
|
||||||
|
self.all_off()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def flash_active(self):
|
||||||
|
return self.output_key_delayed is not None
|
||||||
|
|
||||||
#
|
#
|
||||||
# WARNING CALL
|
# WARNING CALL
|
||||||
@ -344,6 +362,23 @@ class shelly(base):
|
|||||||
self.logger.info("Toggeling output 1")
|
self.logger.info("Toggeling output 1")
|
||||||
self.set_output_1('toggle')
|
self.set_output_1('toggle')
|
||||||
|
|
||||||
|
def flash_0_mcb(self, device, key, data):
|
||||||
|
self.output_key_delayed = self.KEY_OUTPUT_0
|
||||||
|
self.toggle_output_0_mcb(device, key, data)
|
||||||
|
self.delayed_flash_task.run()
|
||||||
|
|
||||||
|
def flash_1_mcb(self, device, key, data):
|
||||||
|
self.output_key_delayed = self.KEY_OUTPUT_1
|
||||||
|
self.toggle_output_1_mcb(device, key, data)
|
||||||
|
self.delayed_flash_task.run()
|
||||||
|
|
||||||
|
def all_off(self):
|
||||||
|
if self.flash_active:
|
||||||
|
self.all_off_requested = True
|
||||||
|
else:
|
||||||
|
self.set_output_0(False)
|
||||||
|
self.set_output_1(False)
|
||||||
|
|
||||||
|
|
||||||
class silvercrest_powerplug(base):
|
class silvercrest_powerplug(base):
|
||||||
KEY_LINKQUALITY = "linkquality"
|
KEY_LINKQUALITY = "linkquality"
|
||||||
@ -386,6 +421,9 @@ class silvercrest_powerplug(base):
|
|||||||
self.logger.info("Toggeling output 0")
|
self.logger.info("Toggeling output 0")
|
||||||
self.set_output_0('toggle')
|
self.set_output_0('toggle')
|
||||||
|
|
||||||
|
def all_off(self):
|
||||||
|
self.set_output_0(False)
|
||||||
|
|
||||||
|
|
||||||
class silvercrest_motion_sensor(base):
|
class silvercrest_motion_sensor(base):
|
||||||
KEY_BATTERY = "battery"
|
KEY_BATTERY = "battery"
|
||||||
@ -523,6 +561,9 @@ class my_powerplug(base):
|
|||||||
self.logger.info("Toggeling all outputs")
|
self.logger.info("Toggeling all outputs")
|
||||||
self.set_output_0('toggle')
|
self.set_output_0('toggle')
|
||||||
|
|
||||||
|
def all_off(self):
|
||||||
|
self.set_output_all(False)
|
||||||
|
|
||||||
|
|
||||||
class tradfri_light(base):
|
class tradfri_light(base):
|
||||||
KEY_LINKQUALITY = "linkquality"
|
KEY_LINKQUALITY = "linkquality"
|
||||||
@ -623,6 +664,9 @@ class tradfri_light(base):
|
|||||||
self.logger.log(logging.INFO if data != self.color_temp else logging.DEBUG, "Changing color temperature to %s", str(data))
|
self.logger.log(logging.INFO if data != self.color_temp else logging.DEBUG, "Changing color temperature to %s", str(data))
|
||||||
self.set_color_temp(data)
|
self.set_color_temp(data)
|
||||||
|
|
||||||
|
def all_off(self):
|
||||||
|
self.set_output_0(False)
|
||||||
|
|
||||||
|
|
||||||
class tradfri_button(base):
|
class tradfri_button(base):
|
||||||
ACTION_TOGGLE = "toggle"
|
ACTION_TOGGLE = "toggle"
|
||||||
|
@ -24,6 +24,9 @@ class all_functions(object):
|
|||||||
self.mqtt_client = mqtt_client
|
self.mqtt_client = mqtt_client
|
||||||
#
|
#
|
||||||
self.__devices__ = None
|
self.__devices__ = None
|
||||||
|
#
|
||||||
|
# Rooms
|
||||||
|
#
|
||||||
# stairway
|
# stairway
|
||||||
self.stw_stairway = stairway(self.mqtt_client)
|
self.stw_stairway = stairway(self.mqtt_client)
|
||||||
# ground floor west
|
# ground floor west
|
||||||
@ -49,7 +52,16 @@ class all_functions(object):
|
|||||||
# Off Buttons
|
# Off Buttons
|
||||||
self.init_off_functionality()
|
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):
|
def init_off_functionality(self):
|
||||||
|
##### TEMPORARY ###################################################################################################################
|
||||||
# Off Buttons
|
# Off Buttons
|
||||||
self.gui_button_all_off = devices.nodered_gui_button(self.mqtt_client, "gui/all/common/off/button")
|
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_gfw_off = devices.nodered_gui_button(self.mqtt_client, "gui/gfw/common/off/button")
|
||||||
@ -60,15 +72,25 @@ class all_functions(object):
|
|||||||
self.gui_button_gfw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.gfw_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_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)
|
self.gui_button_ffe_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffe_off)
|
||||||
# Long push ffe_floor
|
##### TEMPORARY ###################################################################################################################
|
||||||
self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_floor.all_off_feedback)
|
|
||||||
self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_off)
|
# ALL OFF - Long push stairway
|
||||||
# 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.stw_stairway.all_off_feedback)
|
|
||||||
self.stw_stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.all_off)
|
self.stw_stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.all_off)
|
||||||
# Long push input device
|
|
||||||
|
# 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)
|
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):
|
def getmembers(self, prefix):
|
||||||
rv = []
|
rv = []
|
||||||
for name, obj in inspect.getmembers(self):
|
for name, obj in inspect.getmembers(self):
|
||||||
@ -96,25 +118,17 @@ class all_functions(object):
|
|||||||
for ffe in self.getmembers('ffe'):
|
for ffe in self.getmembers('ffe'):
|
||||||
ffe.all_off()
|
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):
|
def all_off(self, device=None, key=None, data=None):
|
||||||
self.common_off(device, key, data)
|
self.common_off(device, key, data)
|
||||||
self.gfw_off(device, key, data)
|
self.gfw_off(device, key, data)
|
||||||
self.ffw_off(device, key, data)
|
self.ffw_off(device, key, data)
|
||||||
self.ffe_off(device, key, data)
|
self.ffe_off(device, key, data)
|
||||||
|
self.stw_off(device, key, data)
|
||||||
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 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 devicelist(self):
|
def devicelist(self):
|
||||||
if self.__devices__ is None:
|
if self.__devices__ is None:
|
||||||
|
@ -55,6 +55,7 @@ class first_floor_east_kitchen(room):
|
|||||||
# Functionality initialisation
|
# Functionality initialisation
|
||||||
#
|
#
|
||||||
self.circulation_pump = timer_on_activation(self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0, 10*60)
|
self.circulation_pump = timer_on_activation(self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0, 10*60)
|
||||||
|
self.circulation_pump_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.main_light_shelly.flash_0_mcb, True)
|
||||||
|
|
||||||
##### TEMPORARY ###################################################################################################################
|
##### TEMPORARY ###################################################################################################################
|
||||||
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI)
|
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI)
|
||||||
|
@ -20,44 +20,10 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
|||||||
class room(object):
|
class room(object):
|
||||||
def __init__(self, mqtt_client):
|
def __init__(self, mqtt_client):
|
||||||
self.mqtt_client = mqtt_client
|
self.mqtt_client = mqtt_client
|
||||||
#
|
|
||||||
self.block_all_off = False
|
|
||||||
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!")
|
|
||||||
|
|
||||||
def all_off(self, device=None, key=None, data=None):
|
def all_off(self, device=None, key=None, data=None):
|
||||||
if not self.block_all_off:
|
logger.info("Switching all off \"%s\"", type(self).__name__)
|
||||||
logger.info("Switching all off \"%s\"", type(self).__name__)
|
try:
|
||||||
try:
|
self.main_light_shelly.all_off()
|
||||||
self.main_light_shelly.set_output_0(False)
|
except AttributeError:
|
||||||
self.main_light_shelly.set_output_1(False)
|
logger.exception("Device self.main_light does not exist!")
|
||||||
except AttributeError:
|
|
||||||
logger.exception("Device self.main_light does not exist!")
|
|
||||||
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!")
|
|
||||||
self.block_all_off = True
|
|
||||||
self.delayed_task.run()
|
|
||||||
|
|
||||||
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!")
|
|
||||||
self.delayed_task.run()
|
|
||||||
self.last_flash_data = data
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user