This commit is contained in:
Dirk Alders 2022-12-26 16:54:26 +01:00
parent 7d516a9016
commit 2f673aa283
5 changed files with 38 additions and 67 deletions

View File

@ -5,7 +5,6 @@
import devices
from function.rooms import room_shelly
from function.modules import heating_function_brennenstuhl
from function.helpers import changed_value_indicator
import logging
import task
@ -21,22 +20,21 @@ class common_circulation_pump(room_shelly):
# http://shelly1-E89F6D85A466
super().__init__(mqtt_client, "shellies/ffe/kitchen/circulation_pump", "gui/none/common/circulation_pump/switch")
#
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.circ_pump_actions)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.circ_pump_actions, True)
#
self.gui_timer_view = devices.nodered_gui_heatvalve(mqtt_client, "gui/ffe_circ_pump_timer")
self.gui_timer_view.set_feedback('-')
#
self.cvi = changed_value_indicator()
self.ct = task.periodic(6, self.cyclic_task)
self.pump_timer = None
#
self.ct.run()
def circ_pump_actions(self, device, key, data):
if self.cvi.changed_here(device.topic, key, data) and data is True:
if data is True:
self.pump_timer = 10
self.gui_timer_view.set_feedback(self.pump_timer)
elif data is False:
else:
self.pump_timer = None
self.gui_timer_view.set_feedback('-')

View File

@ -7,7 +7,6 @@ import devices
import json
import logging
from function.rooms import room_shelly, room_shelly_motion_sensor, room_shelly_tradfri_light
from function.helpers import changed_value_indicator
try:
from config import APP_NAME as ROOT_LOGGER_NAME
except ImportError:
@ -163,8 +162,6 @@ class first_floor_east_living(room_shelly_tradfri_light):
self.gui_switch_xmas_tree.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_xmas_tree.set_output_0_mcb)
#
self.powerplug_xmas_tree.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.powerplug_xmas_star.set_output_0_mcb)
#
self.cvi = changed_value_indicator()
def all_off(self, device=None, key=None, data=None):
super().all_off(device, key, data)

View File

@ -3,7 +3,7 @@
#
import logging
from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light
from function.rooms import room_shelly, room_shelly_tradfri_light
try:
from config import APP_NAME as ROOT_LOGGER_NAME

View File

@ -5,7 +5,6 @@
import devices
import logging
from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light
from function.helpers import changed_value_indicator
import task
try:
@ -80,8 +79,6 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
#
self.delayed_task = task.delayed(1.0, self.send_audio_source)
#
self.cvi = changed_value_indicator()
#
# Callback initialisation
#
@ -110,14 +107,14 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
self.gui_switch_amplifier.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_0_mcb)
self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.gui_switch_amplifier.set_state_mcb)
# amplifier auto on
self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.cd_amplifier_synchronisation)
self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation)
self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation)
self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.cd_amplifier_synchronisation, True)
self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation, True)
self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation, True)
# audio source
self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.audio_source_selector)
self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.audio_source_selector)
self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.audio_source_selector)
self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.audio_source_selector)
self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, True, self.audio_source_selector, True)
self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, True, self.audio_source_selector, True)
self.spotify_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
self.mpd_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
self.audio_source = self.AUDIO_SOURCE_PC
# cd player
@ -134,8 +131,8 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
# brightness
self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, None, self.brightness_action)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.device_chooser_action)
self.powerplug_common.add_callback(None, None, self.device_chooser_action)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.device_chooser_action, True)
self.powerplug_common.add_callback(None, None, self.device_chooser_action, True)
self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_UP, self.choose_next_device)
self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_DOWN, self.choose_prev_device)
self.active_device_state = None
@ -146,32 +143,27 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
self.powerplug_common.set_output_all(False)
def cd_amplifier_synchronisation(self, device, key, data):
if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
logger.info("Syncing \"%s\" amplifier with cd player: %s", type(self).__name__, data)
self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
def raspi_amplifier_synchronisation(self, device, key, data):
if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
logger.info("Syncing \"%s\" amplifier with raspi player: %s", type(self).__name__, data)
self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
def device_chooser_action(self, device, key, data):
if device == self.main_light_shelly:
if self.cvi.changed_here(device.topic, key, data):
if data is True:
self.active_device_state = self.STATE_ACTIVE_DEVICE_MAIN_LIGHT
self.update_active_device_led()
else:
self.choose_next_device()
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_DESK_LIGHT:
if self.cvi.changed_here(device.topic, key, data):
if data is True:
self.active_device_state = self.STATE_ACTIVE_DEVICE_DESK_LIGHT
self.update_active_device_led()
else:
self.choose_next_device()
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
if self.cvi.changed_here(device.topic, key, data):
if data is True:
self.active_device_state = self.STATE_ACTIVE_DEVICE_AMPLIFIER
self.update_active_device_led()
@ -237,15 +229,12 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
def audio_source_selector(self, device, key, data):
if device == self.powerplug_common and key == self.KEY_POWERPLUG_CD_PLAYER:
if self.cvi.changed_here(device.topic, key, data) and data is True:
# switch on of cd player
self.audio_source = self.AUDIO_SOURCE_CD
elif device in [self.spotify_state, self.mpd_state]:
if self.cvi.changed_here(device.topic, key, data) and data is True:
# switch on raspi-source
self.audio_source = self.AUDIO_SOURCE_RASPI
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
if self.cvi.changed_here(device.topic, key, data) and data is True:
# switch on of amplifier -> select source and reset stored source value
self.delayed_task.run()

View File

@ -7,19 +7,6 @@ import inspect
import time
class changed_value_indicator(dict):
def __init__(self):
super().__init__(self)
def changed_here(self, topic, key, value):
caller_name = inspect.getmodule(inspect.stack()[1][0]).__name__ + '.' + inspect.stack()[1][3]
key = '::'.join([caller_name, topic, key])
#
rv = self.get(key) != value
self[key] = value
return rv
def now():
return time.mktime(time.localtime())