minor changes - esthetic

This commit is contained in:
Dirk Alders 2022-12-23 11:45:00 +01:00
parent 31b76307bf
commit 3ebfe2f3a5
3 changed files with 41 additions and 25 deletions

View File

@ -78,6 +78,8 @@ class base(dict):
# #
self.callback_list = [] self.callback_list = []
self.warning_callback = None self.warning_callback = None
#
self.__previous__ = {}
def receive_callback(self, client, userdata, message): def receive_callback(self, client, userdata, message):
self.unpack(message) self.unpack(message)
@ -93,6 +95,7 @@ class base(dict):
prev_value = self.get(key) prev_value = self.get(key)
if key in self.RX_KEYS: if key in self.RX_KEYS:
self[key] = data self[key] = data
self.__previous__[key] = prev_value
# Filter, if needed # Filter, if needed
self.unpack_filter(key) self.unpack_filter(key)
if prev_value != self.get(key): if prev_value != self.get(key):
@ -186,6 +189,9 @@ class base(dict):
def warning_text(self, data): def warning_text(self, data):
return "default warning text - replace parent warning_text function" return "default warning text - replace parent warning_text function"
def previous_value(self, key):
self.__previous__.get(key)
class shelly(base): class shelly(base):
KEY_OUTPUT_0 = "relay/0" KEY_OUTPUT_0 = "relay/0"
@ -317,6 +323,7 @@ class my_powerplug(base):
KEY_OUTPUT_2 = "output/3" KEY_OUTPUT_2 = "output/3"
KEY_OUTPUT_3 = "output/4" KEY_OUTPUT_3 = "output/4"
KEY_OUTPUT_ALL = "output/all" KEY_OUTPUT_ALL = "output/all"
KEY_OUTPUT_LIST = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_OUTPUT_3]
# #
TX_TOPIC = 'set' TX_TOPIC = 'set'
TX_TYPE = base.TX_VALUE TX_TYPE = base.TX_VALUE
@ -352,6 +359,12 @@ class my_powerplug(base):
# #
# TX # TX
# #
def set_output(self, key, state):
if key in self.KEY_OUTPUT_LIST:
self.pack(key, state)
else:
logging.error("Unknown key to set the output!")
def set_output_0(self, state): def set_output_0(self, state):
"""state: [True, False, 'toggle']""" """state: [True, False, 'toggle']"""
self.pack(self.KEY_OUTPUT_0, state) self.pack(self.KEY_OUTPUT_0, state)

View File

@ -52,8 +52,8 @@ class first_floor_east_dining(room_shelly):
self.floorlamp_powerplug.set_output_0(False) self.floorlamp_powerplug.set_output_0(False)
def floorlamp_synchronisation(self, device, key, data): def floorlamp_synchronisation(self, device, key, data):
if self.cvi.changed_here(device.topic, key, data): if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data)) logger.info("Syncing \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
self.floorlamp_powerplug.set_output_0(data) self.floorlamp_powerplug.set_output_0(data)
def gui_switch_command_floorlamp(self, device, key, data): def gui_switch_command_floorlamp(self, device, key, data):
@ -218,8 +218,8 @@ class first_floor_east_living(room_shelly_tradfri_light):
return rv return rv
def floorlamp_synchronisation(self, device, key, data): def floorlamp_synchronisation(self, device, key, data):
if self.cvi.changed_here(device.topic, key, data): if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data)) logger.info("Syncing \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
for device in self.__floorlamp_devices__(): for device in self.__floorlamp_devices__():
device.set_output_0(data) device.set_output_0(data)

View File

@ -161,23 +161,23 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
self.gui_switch_pc_dock.set_feedback(data) self.gui_switch_pc_dock.set_feedback(data)
def cd_amplifier_synchronisation(self, device, key, data): def cd_amplifier_synchronisation(self, device, key, data):
if device == self.powerplug_common: if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
if self.cvi.changed_here(device.topic, key, data): logger.info("Syncing \"%s\" amplifier with cd player: %s", type(self).__name__, data)
logger.info("Setting \"%s\" amplifier: %s", type(self).__name__, data) self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
self.powerplug_common.set_output_0(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): if self.cvi.changed_here(device.topic, key, data) and device.previous_value(key) is not None:
logger.info("Setting \"%s\" amplifier: %s", type(self).__name__, data) logger.info("Syncing \"%s\" amplifier with raspi player: %s", type(self).__name__, data)
self.powerplug_common.set_output_0(data) self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
def desk_light_switch_action(self, device, key, data): def desk_light_switch_action(self, device, key, data):
if device == self.button_tradfri: if device == self.button_tradfri:
logger.info("Toggeling \"%s\" desk light to %s", type(self).__name__, not self.powerplug_common.output_1) logger.info("Toggeling \"%s\" desk light to %s", type(
self.powerplug_common.set_output_1("toggle") self).__name__, not self.get(self.KEY_POWERPLUG_AMPLIFIER))
self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, "toggle")
else: else:
logger.info("Setting \"%s\" desk light: %s", type(self).__name__, data) logger.info("Setting \"%s\" desk light: %s", type(self).__name__, data)
self.powerplug_common.set_output_1(data) self.powerplug_common.set_output(self.KEY_POWERPLUG_DESK_LIGHT, data)
def desk_light_set_gui_params_action(self, device, key, data): def desk_light_set_gui_params_action(self, device, key, data):
if key == devices.nodered_gui.KEY_BRIGHTNESS: if key == devices.nodered_gui.KEY_BRIGHTNESS:
@ -195,27 +195,30 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
def amplifier_switch_action(self, device, key, data): def amplifier_switch_action(self, device, key, data):
if device == self.button_tradfri: if device == self.button_tradfri:
logger.info("Toggeling \"%s\" amplifier to %s", type(self).__name__, not self.powerplug_common.output_0) logger.info("Toggeling \"%s\" amplifier to %s", type(self).__name__,
self.powerplug_common.set_output_0("toggle") not self.powerplug_common.get(self.KEY_POWERPLUG_AMPLIFIER))
self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, "toggle")
else: else:
logger.info("Setting \"%s\" amplifier: %s", type(self).__name__, data) logger.info("Setting \"%s\" amplifier: %s", type(self).__name__, data)
self.powerplug_common.set_output_0(data) self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
def cd_player_switch_action(self, device, key, data): def cd_player_switch_action(self, device, key, data):
if device == self.button_tradfri: if device == self.button_tradfri:
logger.info("Toggeling \"%s\" cd_player to %s", type(self).__name__, not self.powerplug_common.output_2) logger.info("Toggeling \"%s\" cd_player to %s", type(self).__name__,
self.powerplug_common.set_output_2("toggle") not self.powerplug_common.get(self.KEY_POWERPLUG_CD_PLAYER))
self.powerplug_common.set_output(self.KEY_POWERPLUG_CD_PLAYER, "toggle")
else: else:
logger.info("Setting \"%s\" cd_player: %s", type(self).__name__, data) logger.info("Setting \"%s\" cd_player: %s", type(self).__name__, data)
self.powerplug_common.set_output_2(data) self.powerplug_common.set_output(self.KEY_POWERPLUG_CD_PLAYER, data)
def pc_dock_switch_action(self, device, key, data): def pc_dock_switch_action(self, device, key, data):
if device == self.button_tradfri: if device == self.button_tradfri:
logger.info("Toggeling \"%s\" pc_dock to %s", type(self).__name__, not self.powerplug_common.output_3) logger.info("Toggeling \"%s\" pc_dock to %s", type(self).__name__,
self.powerplug_common.set_output_3("toggle") not self.powerplug_common.get(self.KEY_POWERPLUG_PC_DOCK))
self.powerplug_common.set_output(self.KEY_POWERPLUG_PC_DOCK, "toggle")
else: else:
logger.info("Setting \"%s\" pc_dock: %s", type(self).__name__, data) logger.info("Setting \"%s\" pc_dock: %s", type(self).__name__, data)
self.powerplug_common.set_output_3(data) self.powerplug_common.set_output(self.KEY_POWERPLUG_PC_DOCK, 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:
@ -243,9 +246,9 @@ class ground_floor_west_dirk(room_shelly_tradfri_light):
if state == self.STATE_ACTIVE_DEVICE_MAIN_LIGHT: if state == self.STATE_ACTIVE_DEVICE_MAIN_LIGHT:
return self.main_light_shelly.output_0 return self.main_light_shelly.output_0
elif state == self.STATE_ACTIVE_DEVICE_DESK_LIGHT: elif state == self.STATE_ACTIVE_DEVICE_DESK_LIGHT:
return self.powerplug_common.output_1 return self.powerplug_common.get(self.KEY_POWERPLUG_DESK_LIGHT)
elif state == self.STATE_ACTIVE_DEVICE_AMPLIFIER: elif state == self.STATE_ACTIVE_DEVICE_AMPLIFIER:
return self.powerplug_common.output_0 return self.powerplug_common.get(self.KEY_POWERPLUG_AMPLIFIER)
def choose_next_device(self, device=None, key=None, data=None): def choose_next_device(self, device=None, key=None, data=None):
if self.active_device_state is not None: if self.active_device_state is not None: