clean up
This commit is contained in:
parent
7d516a9016
commit
2f673aa283
@ -5,7 +5,6 @@
|
|||||||
import devices
|
import devices
|
||||||
from function.rooms import room_shelly
|
from function.rooms import room_shelly
|
||||||
from function.modules import heating_function_brennenstuhl
|
from function.modules import heating_function_brennenstuhl
|
||||||
from function.helpers import changed_value_indicator
|
|
||||||
import logging
|
import logging
|
||||||
import task
|
import task
|
||||||
|
|
||||||
@ -21,22 +20,21 @@ class common_circulation_pump(room_shelly):
|
|||||||
# http://shelly1-E89F6D85A466
|
# http://shelly1-E89F6D85A466
|
||||||
super().__init__(mqtt_client, "shellies/ffe/kitchen/circulation_pump", "gui/none/common/circulation_pump/switch")
|
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 = devices.nodered_gui_heatvalve(mqtt_client, "gui/ffe_circ_pump_timer")
|
||||||
self.gui_timer_view.set_feedback('-')
|
self.gui_timer_view.set_feedback('-')
|
||||||
#
|
#
|
||||||
self.cvi = changed_value_indicator()
|
|
||||||
self.ct = task.periodic(6, self.cyclic_task)
|
self.ct = task.periodic(6, self.cyclic_task)
|
||||||
self.pump_timer = None
|
self.pump_timer = None
|
||||||
#
|
#
|
||||||
self.ct.run()
|
self.ct.run()
|
||||||
|
|
||||||
def circ_pump_actions(self, device, key, data):
|
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.pump_timer = 10
|
||||||
self.gui_timer_view.set_feedback(self.pump_timer)
|
self.gui_timer_view.set_feedback(self.pump_timer)
|
||||||
elif data is False:
|
else:
|
||||||
self.pump_timer = None
|
self.pump_timer = None
|
||||||
self.gui_timer_view.set_feedback('-')
|
self.gui_timer_view.set_feedback('-')
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import devices
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from function.rooms import room_shelly, room_shelly_motion_sensor, room_shelly_tradfri_light
|
from function.rooms import room_shelly, room_shelly_motion_sensor, room_shelly_tradfri_light
|
||||||
from function.helpers import changed_value_indicator
|
|
||||||
try:
|
try:
|
||||||
from config import APP_NAME as ROOT_LOGGER_NAME
|
from config import APP_NAME as ROOT_LOGGER_NAME
|
||||||
except ImportError:
|
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.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.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):
|
def all_off(self, device=None, key=None, data=None):
|
||||||
super().all_off(device, key, data)
|
super().all_off(device, key, data)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import logging
|
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:
|
try:
|
||||||
from config import APP_NAME as ROOT_LOGGER_NAME
|
from config import APP_NAME as ROOT_LOGGER_NAME
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
import devices
|
import devices
|
||||||
import logging
|
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, room_shelly_silvercrest_light
|
||||||
from function.helpers import changed_value_indicator
|
|
||||||
import task
|
import task
|
||||||
|
|
||||||
try:
|
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.delayed_task = task.delayed(1.0, self.send_audio_source)
|
||||||
#
|
#
|
||||||
self.cvi = changed_value_indicator()
|
|
||||||
#
|
|
||||||
# Callback initialisation
|
# 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.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)
|
self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.gui_switch_amplifier.set_state_mcb)
|
||||||
# amplifier auto on
|
# amplifier auto on
|
||||||
self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.cd_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)
|
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)
|
self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation, True)
|
||||||
# audio source
|
# audio source
|
||||||
self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, 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, None, self.audio_source_selector)
|
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, None, self.audio_source_selector)
|
self.spotify_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
|
||||||
self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.audio_source_selector)
|
self.mpd_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
|
||||||
self.audio_source = self.AUDIO_SOURCE_PC
|
self.audio_source = self.AUDIO_SOURCE_PC
|
||||||
|
|
||||||
# cd player
|
# cd player
|
||||||
@ -134,8 +131,8 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
|
|||||||
|
|
||||||
# brightness
|
# brightness
|
||||||
self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, None, self.brightness_action)
|
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.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)
|
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_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.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_BRIGHTNESS_DOWN, self.choose_prev_device)
|
||||||
self.active_device_state = None
|
self.active_device_state = None
|
||||||
@ -146,37 +143,32 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
|
|||||||
self.powerplug_common.set_output_all(False)
|
self.powerplug_common.set_output_all(False)
|
||||||
|
|
||||||
def cd_amplifier_synchronisation(self, device, key, data):
|
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)
|
||||||
logger.info("Syncing \"%s\" amplifier with cd player: %s", type(self).__name__, data)
|
self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
|
||||||
self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
|
|
||||||
|
|
||||||
def raspi_amplifier_synchronisation(self, device, key, 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)
|
||||||
logger.info("Syncing \"%s\" amplifier with raspi player: %s", type(self).__name__, data)
|
self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
|
||||||
self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
|
|
||||||
|
|
||||||
def device_chooser_action(self, device, key, data):
|
def device_chooser_action(self, device, key, data):
|
||||||
if device == self.main_light_shelly:
|
if device == self.main_light_shelly:
|
||||||
if self.cvi.changed_here(device.topic, key, data):
|
if data is True:
|
||||||
if data is True:
|
self.active_device_state = self.STATE_ACTIVE_DEVICE_MAIN_LIGHT
|
||||||
self.active_device_state = self.STATE_ACTIVE_DEVICE_MAIN_LIGHT
|
self.update_active_device_led()
|
||||||
self.update_active_device_led()
|
else:
|
||||||
else:
|
self.choose_next_device()
|
||||||
self.choose_next_device()
|
|
||||||
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_DESK_LIGHT:
|
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:
|
||||||
if data is True:
|
self.active_device_state = self.STATE_ACTIVE_DEVICE_DESK_LIGHT
|
||||||
self.active_device_state = self.STATE_ACTIVE_DEVICE_DESK_LIGHT
|
self.update_active_device_led()
|
||||||
self.update_active_device_led()
|
else:
|
||||||
else:
|
self.choose_next_device()
|
||||||
self.choose_next_device()
|
|
||||||
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
|
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
|
||||||
if self.cvi.changed_here(device.topic, key, data):
|
if data is True:
|
||||||
if data is True:
|
self.active_device_state = self.STATE_ACTIVE_DEVICE_AMPLIFIER
|
||||||
self.active_device_state = self.STATE_ACTIVE_DEVICE_AMPLIFIER
|
self.update_active_device_led()
|
||||||
self.update_active_device_led()
|
else:
|
||||||
else:
|
self.choose_next_device()
|
||||||
self.choose_next_device()
|
|
||||||
|
|
||||||
def get_activity_state(self, state):
|
def get_activity_state(self, state):
|
||||||
if state == self.STATE_ACTIVE_DEVICE_MAIN_LIGHT:
|
if state == self.STATE_ACTIVE_DEVICE_MAIN_LIGHT:
|
||||||
@ -237,17 +229,14 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
|
|||||||
|
|
||||||
def audio_source_selector(self, device, key, data):
|
def audio_source_selector(self, device, key, data):
|
||||||
if device == self.powerplug_common and key == self.KEY_POWERPLUG_CD_PLAYER:
|
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
|
||||||
# switch on of cd player
|
self.audio_source = self.AUDIO_SOURCE_CD
|
||||||
self.audio_source = self.AUDIO_SOURCE_CD
|
|
||||||
elif device in [self.spotify_state, self.mpd_state]:
|
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
|
||||||
# switch on raspi-source
|
self.audio_source = self.AUDIO_SOURCE_RASPI
|
||||||
self.audio_source = self.AUDIO_SOURCE_RASPI
|
|
||||||
elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
|
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
|
||||||
# switch on of amplifier -> select source and reset stored source value
|
self.delayed_task.run()
|
||||||
self.delayed_task.run()
|
|
||||||
|
|
||||||
def send_audio_source(self):
|
def send_audio_source(self):
|
||||||
if self.audio_source == self.AUDIO_SOURCE_PC:
|
if self.audio_source == self.AUDIO_SOURCE_PC:
|
||||||
|
@ -7,19 +7,6 @@ import inspect
|
|||||||
import time
|
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():
|
def now():
|
||||||
return time.mktime(time.localtime())
|
return time.mktime(time.localtime())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user