Compare commits

..

No commits in common. "0365b5de4ab36abbd83ba6e766999168efe6380f" and "3a4d43c0c4d080d2235b4b055854fff1f3c74824" have entirely different histories.

12 changed files with 1185 additions and 714 deletions

View File

@ -1,5 +1,4 @@
import colored import colored
import copy
import json import json
import task import task
import time import time
@ -108,15 +107,6 @@ class base(object):
if self.AUTOSEND and len(keys_changed) > 0: if self.AUTOSEND and len(keys_changed) > 0:
self.__tx__(keys_changed) self.__tx__(keys_changed)
def get_data(self, key, default=None):
rv = self.data.get(key, default)
try:
rv = True if rv.lower() == 'on' else rv
rv = False if rv.lower() == 'off' else rv
except AttributeError:
pass
return rv
def __tx__(self, keys_changed): def __tx__(self, keys_changed):
self.mqtt_client.send(self.topic, json.dumps(self.data)) self.mqtt_client.send(self.topic, json.dumps(self.data))
@ -148,7 +138,7 @@ class shelly(base):
def __init__(self, mqtt_client, topic, input_0_func=None, input_1_func=None, output_0_auto_off=None): def __init__(self, mqtt_client, topic, input_0_func=None, input_1_func=None, output_0_auto_off=None):
super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
# #
self.store_data(**{self.KEY_OUTPUT_0: False, self.KEY_OUTPUT_1: False, self.KEY_INPUT_0: False, self.KEY_INPUT_1: False}) self.store_data(**{self.KEY_OUTPUT_0: "off", self.KEY_OUTPUT_1: "off", self.KEY_INPUT_0: "off", self.KEY_INPUT_1: "off"})
self.__input_0_func = input_0_func self.__input_0_func = input_0_func
self.__input_1_func = input_1_func self.__input_1_func = input_1_func
self.__output_0_auto_off__ = output_0_auto_off self.__output_0_auto_off__ = output_0_auto_off
@ -156,8 +146,8 @@ class shelly(base):
self.__delayed_off__ = task.delayed(float(self.__output_0_auto_off__), self.__auto_off__, self.KEY_OUTPUT_0) self.__delayed_off__ = task.delayed(float(self.__output_0_auto_off__), self.__auto_off__, self.KEY_OUTPUT_0)
# #
self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None) self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None)
self.add_callback(self.KEY_OUTPUT_0, self.__start_auto_off__, True) self.add_callback(self.KEY_OUTPUT_0, self.__start_auto_off__, "on")
self.add_callback(self.KEY_OUTPUT_0, self.__stop_auto_off__, True) self.add_callback(self.KEY_OUTPUT_0, self.__stop_auto_off__, "off")
self.add_callback(self.KEY_OUTPUT_1, self.print_formatted, None) self.add_callback(self.KEY_OUTPUT_1, self.print_formatted, None)
# #
self.add_callback(self.KEY_INPUT_0, self.__input_function__, None) self.add_callback(self.KEY_INPUT_0, self.__input_function__, None)
@ -174,7 +164,7 @@ class shelly(base):
def __tx__(self, keys_changed): def __tx__(self, keys_changed):
for key in keys_changed: for key in keys_changed:
self.mqtt_client.send(self.topic + '/' + key, "on" if self.data.get(key) else "off") self.mqtt_client.send(self.topic + '/' + key, self.data.get(key))
def __input_function__(self, device, key, data): def __input_function__(self, device, key, data):
if key == self.KEY_INPUT_0: if key == self.KEY_INPUT_0:
@ -207,11 +197,14 @@ class shelly(base):
self.__set_data__(key, 'off') self.__set_data__(key, 'off')
def __set_data__(self, key, value): def __set_data__(self, key, value):
self.store_data(**{key: value == "on"}) if value in ["on", "off"]:
self.store_data(**{key: value})
else:
print("Wrong value (%s)!" % repr(value))
def __toggle_data__(self, key): def __toggle_data__(self, key):
if key in self.data: if key in self.data:
self.__set_data__(key, "on" if not self.data.get(key) else "off") self.__set_data__(key, 'on' if self.data.get(key) == 'off' else 'off')
def command(self, command): def command(self, command):
if command in self.COMMANDS: if command in self.COMMANDS:
@ -234,15 +227,15 @@ class shelly(base):
elif command == self.COMMANDS[8]: elif command == self.COMMANDS[8]:
self.__toggle_data__(self.KEY_INPUT_0) self.__toggle_data__(self.KEY_INPUT_0)
time.sleep(0.4) time.sleep(0.4)
self.__set_data__(self.KEY_LONGPUSH_0, True) self.__set_data__(self.KEY_LONGPUSH_0, 'on')
time.sleep(0.1) time.sleep(0.1)
self.__set_data__(self.KEY_LONGPUSH_0, False) self.__set_data__(self.KEY_LONGPUSH_0, 'off')
elif command == self.COMMANDS[9]: elif command == self.COMMANDS[9]:
self.__toggle_data__(self.KEY_INPUT_1) self.__toggle_data__(self.KEY_INPUT_1)
time.sleep(0.4) time.sleep(0.4)
self.__set_data__(self.KEY_LONGPUSH_1, True) self.__set_data__(self.KEY_LONGPUSH_1, 'on')
time.sleep(0.1) time.sleep(0.1)
self.__set_data__(self.KEY_LONGPUSH_1, False) self.__set_data__(self.KEY_LONGPUSH_1, 'off')
else: else:
print("%s: not yet implemented!" % command) print("%s: not yet implemented!" % command)
else: else:
@ -250,33 +243,45 @@ class shelly(base):
def print_formatted(self, device, key, value): def print_formatted(self, device, key, value):
if value is not None: if value is not None:
info = (" - %ds" % self.__output_0_auto_off__) if self.__output_0_auto_off__ is not None and value else "" info = (" - %ds" % self.__output_0_auto_off__) if self.__output_0_auto_off__ is not None and value == "on" else ""
channel = "(%s%s)" % (self.names.get(key, key), info) channel = "(%s%s)" % (self.names.get(key, key), info)
print_light(COLOR_SHELLY, value, self.topic, channel) print_light(COLOR_SHELLY, value == "on", self.topic, channel)
class my_powerplug(base): class my_powerplug(base):
KEY_OUTPUT_0 = "state" KEY_OUTPUT_0 = "0"
KEY_OUTPUT_1 = "1"
KEY_OUTPUT_2 = "2"
KEY_OUTPUT_3 = "3"
COMMANDS = [ COMMANDS = [
"get_output", "toggle_output", "get_output_0", "toggle_output_0",
"get_output_1", "toggle_output_1",
"get_output_2", "toggle_output_2",
"get_output_3", "toggle_output_3",
] ]
def __init__(self, mqtt_client, topic, channel): def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic + '/' + "output/%d" % (channel + 1)) super().__init__(mqtt_client, topic)
# #
self.data[self.KEY_OUTPUT_0] = False for i in range(0, 4):
self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None) self.data[str(i)] = False
self.add_callback(str(i), self.print_formatted, None)
def __rx__(self, client, userdata, message): def __rx__(self, client, userdata, message):
if message.topic == self.topic + '/set': if message.topic.startswith(self.topic + '/output/') and message.topic.endswith('/set'):
payload = payload_filter(message.payload) try:
if payload == "toggle": channels = [int(message.topic.split('/')[-2]) - 1]
payload = not self.data.get(self.KEY_OUTPUT_0) except ValueError:
self.store_data(**{self.KEY_OUTPUT_0: payload}) channels = range(0, 4)
for channel in channels:
payload = payload_filter(message.payload)
if payload == "toggle":
payload = not self.data.get(str(channel))
self.store_data(**{str(channel): payload})
def __tx__(self, keys_changed): def __tx__(self, keys_changed):
for key in keys_changed: for key in keys_changed:
self.mqtt_client.send(self.topic, json.dumps(self.data.get(key))) self.mqtt_client.send(self.topic + "/output/" + str(int(key) + 1), json.dumps(self.data.get(key)))
def command(self, command): def command(self, command):
if command in self.COMMANDS: if command in self.COMMANDS:
@ -284,6 +289,18 @@ class my_powerplug(base):
self.print_formatted(self, self.KEY_OUTPUT_0, self.data.get(self.KEY_OUTPUT_0)) self.print_formatted(self, self.KEY_OUTPUT_0, self.data.get(self.KEY_OUTPUT_0))
elif command == self.COMMANDS[1]: elif command == self.COMMANDS[1]:
self.store_data(**{self.KEY_OUTPUT_0: not self.data.get(self.KEY_OUTPUT_0)}) self.store_data(**{self.KEY_OUTPUT_0: not self.data.get(self.KEY_OUTPUT_0)})
elif command == self.COMMANDS[2]:
self.print_formatted(self, self.KEY_OUTPUT_1, self.data.get(self.KEY_OUTPUT_1))
elif command == self.COMMANDS[3]:
self.store_data(**{self.KEY_OUTPUT_1: not self.data.get(self.KEY_OUTPUT_1)})
elif command == self.COMMANDS[4]:
self.print_formatted(self, self.KEY_OUTPUT_2, self.data.get(self.KEY_OUTPUT_2))
elif command == self.COMMANDS[5]:
self.store_data(**{self.KEY_OUTPUT_2: not self.data.get(self.KEY_OUTPUT_2)})
elif command == self.COMMANDS[6]:
self.print_formatted(self, self.KEY_OUTPUT_3, self.data.get(self.KEY_OUTPUT_3))
elif command == self.COMMANDS[7]:
self.store_data(**{self.KEY_OUTPUT_3: not self.data.get(self.KEY_OUTPUT_3)})
else: else:
print("%s: not yet implemented!" % command) print("%s: not yet implemented!" % command)
else: else:
@ -291,7 +308,7 @@ class my_powerplug(base):
def print_formatted(self, device, key, value): def print_formatted(self, device, key, value):
if value is not None: if value is not None:
print_light(COLOR_POWERPLUG, value, self.topic, "(%s)" % self.names.get(key, "State")) print_light(COLOR_POWERPLUG, value, self.topic, "(%s)" % self.names.get(key, "Channel %d" % (int(key) + 1)))
class silvercrest_powerplug(base): class silvercrest_powerplug(base):
@ -305,7 +322,7 @@ class silvercrest_powerplug(base):
super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None) self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None)
# #
self.store_data(**{self.KEY_OUTPUT_0: False}) self.store_data(**{self.KEY_OUTPUT_0: "off"})
def __rx__(self, client, userdata, message): def __rx__(self, client, userdata, message):
if message.topic == self.topic + '/set': if message.topic == self.topic + '/set':
@ -314,24 +331,20 @@ class silvercrest_powerplug(base):
state = json.loads(message.payload).get('state').lower() state = json.loads(message.payload).get('state').lower()
if state in STATES: if state in STATES:
if state == STATES[0]: if state == STATES[0]:
self.store_data(**{self.KEY_OUTPUT_0: True}) self.store_data(**{self.KEY_OUTPUT_0: 'on'})
elif state == STATES[1]: elif state == STATES[1]:
self.store_data(**{self.KEY_OUTPUT_0: False}) self.store_data(**{self.KEY_OUTPUT_0: 'off'})
else: else:
self.store_data(**{not self.data.get(self.KEY_OUTPUT_0)}) self.store_data(**{self.KEY_OUTPUT_0: "off" if self.data.get(self.KEY_OUTPUT_0) == "on" else "on"})
def __tx__(self, keys_changed):
for key in keys_changed:
self.mqtt_client.send(self.topic + '/' + key, "on" if self.data.get(key) else "off")
def command(self, command): def command(self, command):
if command in self.COMMANDS: if command in self.COMMANDS:
if command == self.COMMANDS[0]: if command == self.COMMANDS[0]:
self.print_formatted(self, self.KEY_OUTPUT_0, self.data.get(self.KEY_OUTPUT_0)) self.print_formatted(self, self.KEY_OUTPUT_0, self.data.get(self.KEY_OUTPUT_0))
elif command == self.COMMANDS[1]: elif command == self.COMMANDS[1]:
self.store_data(**{self.KEY_OUTPUT_0: True}) self.store_data(**{self.KEY_OUTPUT_0: 'on'})
elif command == self.COMMANDS[2]: elif command == self.COMMANDS[2]:
self.store_data(**{self.KEY_OUTPUT_0: False}) self.store_data(**{self.KEY_OUTPUT_0: 'off'})
else: else:
print("%s: not yet implemented!" % command) print("%s: not yet implemented!" % command)
else: else:
@ -339,11 +352,40 @@ class silvercrest_powerplug(base):
def print_formatted(self, device, key, value): def print_formatted(self, device, key, value):
if value is not None: if value is not None:
print_light(COLOR_POWERPLUG, value, self.topic, "(%s)" % self.names.get(key, key)) print_light(COLOR_POWERPLUG, value == "on", self.topic, "(%s)" % self.names.get(key, key))
class silvercrest_motion_sensor(base):
KEY_OCCUPANCY = "occupancy"
COMMANDS = ['motion']
def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic)
self.data[self.KEY_OCCUPANCY] = False
self.add_callback(self.KEY_OCCUPANCY, self.print_formatted, None)
def __rx__(self, client, userdata, message):
pass
def command(self, command):
try:
command, value = command.split(' ')
except ValueError:
value = None
else:
value = json.loads(value)
if command == self.COMMANDS[0]:
self.store_data(**{self.KEY_OCCUPANCY: True})
time.sleep(value or 10)
self.store_data(**{self.KEY_OCCUPANCY: False})
def print_formatted(self, device, key, value):
if value is not None:
print_light(COLOR_MOTION_SENSOR, value, self.topic, "")
class tradfri_light(base): class tradfri_light(base):
KEY_OUTPUT_0 = "state" KEY_STATE = "state"
KEY_BRIGHTNESS = "brightness" KEY_BRIGHTNESS = "brightness"
KEY_COLOR_TEMP = "color_temp" KEY_COLOR_TEMP = "color_temp"
KEY_BRIGHTNESS_MOVE = "brightness_move" KEY_BRIGHTNESS_MOVE = "brightness_move"
@ -355,7 +397,7 @@ class tradfri_light(base):
def __init__(self, mqtt_client, topic, enable_state=True, enable_brightness=False, enable_color_temp=False, send_on_power_on=True): def __init__(self, mqtt_client, topic, enable_state=True, enable_brightness=False, enable_color_temp=False, send_on_power_on=True):
super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
self.send_on_power_on = send_on_power_on self.send_on_power_on = send_on_power_on
self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None) self.add_callback(self.KEY_STATE, self.print_formatted, None)
self.add_callback(self.KEY_BRIGHTNESS, self.print_formatted, None) self.add_callback(self.KEY_BRIGHTNESS, self.print_formatted, None)
self.add_callback(self.KEY_COLOR_TEMP, self.print_formatted, None) self.add_callback(self.KEY_COLOR_TEMP, self.print_formatted, None)
# #
@ -371,41 +413,34 @@ class tradfri_light(base):
def __init_data__(self, enable_state, enable_brightness, enable_color_temp): def __init_data__(self, enable_state, enable_brightness, enable_color_temp):
data = {} data = {}
if enable_state: if enable_state:
data[self.KEY_OUTPUT_0] = False data[self.KEY_STATE] = 'off'
self.commands.extend(self.STATE_COMMANDS) self.commands.extend(self.STATE_COMMANDS)
if enable_brightness: if enable_brightness:
data[self.KEY_BRIGHTNESS] = 50 data[self.KEY_BRIGHTNESS] = 128
self.brightnes_move = (0, time.time()) self.brightnes_move = (0, time.time())
self.commands.extend(self.BRIGHTNESS_COMMANDS) self.commands.extend(self.BRIGHTNESS_COMMANDS)
if enable_color_temp: if enable_color_temp:
data[self.KEY_COLOR_TEMP] = 5 data[self.KEY_COLOR_TEMP] = 352
self.commands.extend(self.COLOR_TEMP_COMMANDS) self.commands.extend(self.COLOR_TEMP_COMMANDS)
self.store_data(**data) self.store_data(**data)
def __rx__(self, client, userdata, message): def __rx__(self, client, userdata, message):
data = json.loads(message.payload) data = json.loads(message.payload)
if self.data.get(self.KEY_OUTPUT_0) or data.get(self.KEY_OUTPUT_0) in ['on', 'toggle']: if self.data.get(self.KEY_STATE) == 'on' or data.get(self.KEY_STATE) in ['on', 'toggle']:
if message.topic.startswith(self.topic) and message.topic.endswith('/set'): if message.topic.startswith(self.topic) and message.topic.endswith('/set'):
for targetkey in data: for targetkey in data:
value = data[targetkey] value = data[targetkey]
if targetkey in self.data.keys(): if targetkey in self.data.keys():
if targetkey == self.KEY_OUTPUT_0: if targetkey == self.KEY_STATE and value == "toggle":
if value == "toggle": value = "on" if self.data.get(self.KEY_STATE) == "off" else "off"
value = not self.data.get(self.KEY_OUTPUT_0)
else:
value = value == "on"
elif targetkey == self.KEY_BRIGHTNESS:
value = round((value - 1) / 2.53, 0)
elif targetkey == self.KEY_COLOR_TEMP:
value = round((value - 250) / 20.4, 0)
self.store_data(**{targetkey: value}) self.store_data(**{targetkey: value})
else: else:
if targetkey == self.KEY_BRIGHTNESS_MOVE: if targetkey == self.KEY_BRIGHTNESS_MOVE:
new_value = self.data.get(self.KEY_BRIGHTNESS) + (time.time() - self.brightnes_move[1]) * self.brightnes_move[0] new_value = self.data.get(self.KEY_BRIGHTNESS) + (time.time() - self.brightnes_move[1]) * self.brightnes_move[0]
if new_value < 0: if new_value < 0:
new_value = 0 new_value = 0
if new_value > 256: if new_value > 255:
new_value = 256 new_value = 255
self.store_data(**{self.KEY_BRIGHTNESS: int(new_value)}) self.store_data(**{self.KEY_BRIGHTNESS: int(new_value)})
self.brightnes_move = (value, time.time()) self.brightnes_move = (value, time.time())
else: else:
@ -413,16 +448,6 @@ class tradfri_light(base):
elif message.topic == self.topic + '/get': elif message.topic == self.topic + '/get':
self.__tx__(None) self.__tx__(None)
def __tx__(self, keys_changed):
tx_data = copy.copy(self.data)
if self.KEY_OUTPUT_0 in tx_data:
tx_data[self.KEY_OUTPUT_0] = "on" if tx_data[self.KEY_OUTPUT_0] else "off"
if self.KEY_BRIGHTNESS in tx_data:
tx_data[self.KEY_BRIGHTNESS] = 1 + round(2.53 * tx_data[self.KEY_BRIGHTNESS], 0)
if self.KEY_COLOR_TEMP in tx_data:
tx_data[self.KEY_COLOR_TEMP] = 250 + round(20.4 * tx_data[self.KEY_COLOR_TEMP], 0)
self.mqtt_client.send(self.topic, json.dumps(tx_data))
def command(self, command): def command(self, command):
try: try:
command, value = command.split(' ') command, value = command.split(' ')
@ -430,9 +455,9 @@ class tradfri_light(base):
value = None value = None
if command in self.capabilities(): if command in self.capabilities():
if command == self.STATE_COMMANDS[0]: if command == self.STATE_COMMANDS[0]:
self.print_formatted(self, self.KEY_OUTPUT_0, self.data.get(self.KEY_OUTPUT_0)) self.print_formatted(self, self.KEY_STATE, self.data.get(self.KEY_STATE))
elif command == self.STATE_COMMANDS[1]: elif command == self.STATE_COMMANDS[1]:
self.store_data(**{self.KEY_OUTPUT_0: not self.data.get(self.KEY_OUTPUT_0)}) self.store_data(**{self.KEY_STATE: 'off' if self.data.get(self.KEY_STATE) == 'on' else 'on'})
elif command == self.BRIGHTNESS_COMMANDS[0]: elif command == self.BRIGHTNESS_COMMANDS[0]:
self.print_formatted(self, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS)) self.print_formatted(self, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS))
elif command == self.BRIGHTNESS_COMMANDS[1]: elif command == self.BRIGHTNESS_COMMANDS[1]:
@ -447,28 +472,28 @@ class tradfri_light(base):
print("Unknown command!") print("Unknown command!")
def power_off(self, device, key, value): def power_off(self, device, key, value):
self.data[self.KEY_OUTPUT_0] = False self.data[self.KEY_STATE] = 'off'
self.print_formatted(self, self.KEY_OUTPUT_0, False) self.print_formatted(self, self.KEY_STATE, 'off')
def power_on(self, device, key, value): def power_on(self, device, key, value):
if self.send_on_power_on: if self.send_on_power_on:
self.store_data(**{self.KEY_OUTPUT_0: True}) self.store_data(**{self.KEY_STATE: 'on'})
else: else:
self.data[self.KEY_OUTPUT_0] = True self.data[self.KEY_STATE] = 'on'
self.print_formatted(self, self.KEY_OUTPUT_0, True) self.print_formatted(self, self.KEY_STATE, 'on')
def print_formatted(self, device, key, value): def print_formatted(self, device, key, value):
if value is not None: if value is not None:
color = COLOR_LIGHT_ACTIVE color = COLOR_LIGHT_ACTIVE
if key == self.KEY_OUTPUT_0: if key == self.KEY_STATE:
print_light(COLOR_LIGHT_ACTIVE, value, self.topic, "") print_light(COLOR_LIGHT_ACTIVE, value == "on", self.topic, "")
self.print_formatted(device, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS)) self.print_formatted(device, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS))
self.print_formatted(device, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP)) self.print_formatted(device, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP))
elif key in [self.KEY_BRIGHTNESS, self.KEY_COLOR_TEMP]: elif key in [self.KEY_BRIGHTNESS, self.KEY_COLOR_TEMP]:
perc_value = round(value, 0) if key == self.KEY_BRIGHTNESS else round(10 * value, 0) perc_value = round(value * 100 / 256, 0) if key == self.KEY_BRIGHTNESS else round((value - 250) * 100 / 204, 0)
print_percent( print_percent(
COLOR_LIGHT_PASSIVE if not self.data.get(self.KEY_OUTPUT_0) else COLOR_LIGHT_ACTIVE, COLOR_LIGHT_PASSIVE if self.data.get(self.KEY_STATE) != "on" else COLOR_LIGHT_ACTIVE,
'B' if key == self.KEY_BRIGHTNESS else 'C', 'B' if key == gui_light.KEY_BRIGHTNESS else 'C',
perc_value, perc_value,
"%3d%%" % perc_value, "%3d%%" % perc_value,
self.topic, self.topic,
@ -476,109 +501,44 @@ class tradfri_light(base):
) )
class brennenstuhl_heating_valve(base): class gui_light(tradfri_light):
TEMP_RANGE = [10, 30]
#
KEY_TEMPERATURE_SETPOINT = "current_heating_setpoint"
KEY_TEMPERATURE = "local_temperature"
#
COMMANDS = [
"get_temperature_setpoint", "set_temperature_setpoint", "set_local_temperature",
]
def __init__(self, mqtt_client, topic):
super().__init__(mqtt_client, topic)
self.store_data(**{
self.KEY_TEMPERATURE_SETPOINT: 20,
self.KEY_TEMPERATURE: 20.7,
})
self.add_callback(self.KEY_TEMPERATURE_SETPOINT, self.print_formatted, None)
def __rx__(self, client, userdata, message):
if message.topic.startswith(self.topic) and message.topic.endswith("/set"):
payload = payload_filter(message.payload)
self.store_data(**payload)
def command(self, command):
try:
command, value = command.split(' ')
except ValueError:
value = None
if command in self.COMMANDS:
if command == self.COMMANDS[0]:
self.print_formatted(self, self.KEY_TEMPERATURE_SETPOINT, self.data.get(self.KEY_TEMPERATURE_SETPOINT))
elif command == self.COMMANDS[1]:
self.store_data(**{self.KEY_TEMPERATURE_SETPOINT: command_float_value(value)})
elif command == self.COMMANDS[2]:
self.store_data(**{self.KEY_TEMPERATURE: command_float_value(value)})
def print_formatted(self, device, key, value):
devicename = ' - '.join(self.topic.split('/')[1:])
if key == self.KEY_TEMPERATURE_SETPOINT:
perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0])
perc = 100 if perc > 100 else perc
perc = 0 if perc < 0 else perc
print_percent(COLOR_HEATING_VALVE, '\u03d1', perc, "%4.1f°C" % value, self.topic, "")
class videv_light(base):
AUTOSEND = False AUTOSEND = False
# #
KEY_STATE = "state" KEY_ENABLE = "enable"
KEY_BRIGHTNESS = "brightness"
KEY_COLOR_TEMP = "color_temp"
KEY_TIMER = "timer" KEY_TIMER = "timer"
# KEY_LED_X = "led%d"
STATE_COMMANDS = ("get_state", "toggle_state", )
BRIGHTNESS_COMMANDS = ("get_brightness", "set_brightness", )
COLOR_TEMP_COMMANDS = ("get_color_temp", "set_color_temp", )
TIMER_COMMANDS = ("get_timer", )
def __init__(self, mqtt_client, topic, enable_state=True, enable_brightness=False, enable_color_temp=False, enable_timer=False): def __init__(self, mqtt_client, topic, enable_state=True, enable_brightness=False, enable_color_temp=False):
super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic, enable_state, enable_brightness, enable_color_temp)
self.enable_state = enable_state self.add_callback(self.KEY_ENABLE, self.print_formatted, None)
self.enable_brightness = enable_brightness self.add_callback(self.KEY_TIMER, self.print_formatted, None)
self.enable_color_temp = enable_color_temp for i in range(0, 10):
self.enable_timer = enable_timer self.add_callback(self.KEY_LED_X % i, self.print_formatted, None)
self.led_names = {}
# #
self.maxvalue = None self.maxvalue = None
# add commands to be available
def __init_data__(self, enable_state, enable_brightness, enable_color_temp):
data = {}
data[self.KEY_ENABLE] = False
if enable_state: if enable_state:
# init default value data[self.KEY_STATE] = False
self.data[self.KEY_STATE] = False
# add print callback
self.add_callback(self.KEY_STATE, self.print_formatted, None)
# add commands to be available
self.commands.extend(self.STATE_COMMANDS)
if enable_brightness: if enable_brightness:
# init default value data[self.KEY_BRIGHTNESS] = 50
self.data[self.KEY_BRIGHTNESS] = 50
# add print callback
self.add_callback(self.KEY_BRIGHTNESS, self.print_formatted, None)
# add commands to be available
self.commands.extend(self.BRIGHTNESS_COMMANDS)
if enable_color_temp: if enable_color_temp:
# init default value data[self.KEY_COLOR_TEMP] = 5
self.data[self.KEY_COLOR_TEMP] = 5 data[self.KEY_TIMER] = '-'
# add print callback for i in range(0, 10):
self.add_callback(self.KEY_COLOR_TEMP, self.print_formatted, None) data[self.KEY_LED_X % i] = False
# add commands to be available self.store_data(**data)
self.commands.extend(self.COLOR_TEMP_COMMANDS)
if enable_timer:
# init default value
self.data[self.KEY_TIMER] = 0
# add print callback
self.add_callback(self.KEY_TIMER, self.print_formatted, None)
# add commands to be available
self.commands.extend(self.TIMER_COMMANDS)
def __rx__(self, client, userdata, message): def __rx__(self, client, userdata, message):
value = payload_filter(message.payload) value = payload_filter(message.payload)
if message.topic.startswith(self.topic): if message.topic.startswith(self.topic) and message.topic.endswith('/set'):
targetkey = message.topic.split('/')[-1] targetkey = message.topic.split('/')[-2]
if targetkey in self.data.keys(): if targetkey in self.data.keys():
self.store_data(**{targetkey: value}) self.store_data(**{targetkey: value})
elif targetkey != "__info__": else:
print("Unknown key %s in %s::%s" % (targetkey, message.topic, self.__class__.__name__)) print("Unknown key %s in %s::%s" % (targetkey, message.topic, self.__class__.__name__))
elif message.topic == self.topic + '/get': elif message.topic == self.topic + '/get':
self.__tx__(None) self.__tx__(None)
@ -606,22 +566,26 @@ class videv_light(base):
self.print_formatted(self, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP)) self.print_formatted(self, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP))
elif command == self.COLOR_TEMP_COMMANDS[1]: elif command == self.COLOR_TEMP_COMMANDS[1]:
self.send(self.KEY_COLOR_TEMP, command_int_value(value)) self.send(self.KEY_COLOR_TEMP, command_int_value(value))
elif command == self.TIMER_COMMANDS[0]:
self.print_formatted(self, self.KEY_TIMER, self.data.get(self.KEY_TIMER))
else: else:
print("%s: not yet implemented!" % command) print("%s: not yet implemented!" % command)
else: else:
print("Unknown command!") print("Unknown command!")
def add_led_name(self, key, name):
self.led_names[key] = name
def print_formatted(self, device, key, value): def print_formatted(self, device, key, value):
if value is not None: if value is not None:
device = " - ".join(self.topic.split('/')[1:]) device = " - ".join(self.topic.split('/')[1:])
if key == self.KEY_STATE: if key == self.KEY_STATE:
print_switch(COLOR_GUI_ACTIVE, value, self.topic, "") print_switch(COLOR_GUI_ACTIVE, value, self.topic, "")
elif key == self.KEY_ENABLE:
self.print_formatted(device, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS))
self.print_formatted(device, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP))
elif key in [self.KEY_BRIGHTNESS, self.KEY_COLOR_TEMP]: elif key in [self.KEY_BRIGHTNESS, self.KEY_COLOR_TEMP]:
perc_value = round(value * 10 if key == self.KEY_COLOR_TEMP else value, 0) perc_value = round(value * 10 if key == self.KEY_COLOR_TEMP else value, 0)
print_percent( print_percent(
COLOR_GUI_ACTIVE, COLOR_GUI_PASSIVE if not self.data.get(self.KEY_ENABLE, False) else COLOR_GUI_ACTIVE,
'B' if key == self.KEY_BRIGHTNESS else 'C', 'B' if key == self.KEY_BRIGHTNESS else 'C',
perc_value, perc_value,
"%3d%%" % perc_value, "%3d%%" % perc_value,
@ -642,191 +606,241 @@ class videv_light(base):
perc = 0 perc = 0
self.maxvalue = None self.maxvalue = None
print_percent(COLOR_GUI_ACTIVE, 't', perc, '%3d%%' % perc, self.topic, '(%.1f)' % disp_value) print_percent(COLOR_GUI_ACTIVE, 't', perc, '%3d%%' % perc, self.topic, '(%.1f)' % disp_value)
elif key.startswith(self.KEY_LED_X[:-2]):
print_light(COLOR_GUI_ACTIVE, value, self.topic, '(%s)' % self.led_names.get(key, key), True)
# class silvercrest_motion_sensor(base): class tradfri_button(base):
# KEY_OCCUPANCY = "occupancy" KEY_ACTION = "action"
# COMMANDS = ['motion'] #
ACTION_TOGGLE = "toggle"
ACTION_BRIGHTNESS_UP = "brightness_up_click"
ACTION_BRIGHTNESS_DOWN = "brightness_down_click"
ACTION_RIGHT = "arrow_right_click"
ACTION_LEFT = "arrow_left_click"
ACTION_BRIGHTNESS_UP_LONG = "brightness_up_hold"
ACTION_BRIGHTNESS_DOWN_LONG = "brightness_down_hold"
ACTION_RIGHT_LONG = "arrow_right_hold"
ACTION_LEFT_LONG = "arrow_left_hold"
#
COMMANDS = [ACTION_TOGGLE, ACTION_LEFT, ACTION_RIGHT, ACTION_BRIGHTNESS_UP, ACTION_BRIGHTNESS_DOWN,
ACTION_LEFT_LONG, ACTION_RIGHT_LONG, ACTION_BRIGHTNESS_UP_LONG, ACTION_BRIGHTNESS_DOWN_LONG]
# def __init__(self, mqtt_client, topic): def __init__(self, mqtt_client, topic):
# super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
# self.data[self.KEY_OCCUPANCY] = False
# self.add_callback(self.KEY_OCCUPANCY, self.print_formatted, None)
# def __rx__(self, client, userdata, message): def __rx__(self, client, userdata, message):
# pass pass
# def command(self, command): def command(self, command):
# try: try:
# command, value = command.split(' ') command, value = command.split(' ')
# except ValueError: except ValueError:
# value = None value = None
# else: else:
# value = json.loads(value) value = json.loads(value)
# if command == self.COMMANDS[0]: if command in self.capabilities():
# self.store_data(**{self.KEY_OCCUPANCY: True}) action = self.COMMANDS[self.COMMANDS.index(command)]
# time.sleep(value or 10) if self.COMMANDS.index(command) <= 4:
# self.store_data(**{self.KEY_OCCUPANCY: False}) self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
elif self.COMMANDS.index(command) <= 8:
# def print_formatted(self, device, key, value): self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
# if value is not None: time.sleep(value or 0.5)
# print_light(COLOR_MOTION_SENSOR, value, self.topic, "") action = '_'.join(action.split('_')[:-1] + ['release'])
self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
# class tradfri_button(base): class gui_led_array(base):
# KEY_ACTION = "action" AUTOSEND = False
# # #
# ACTION_TOGGLE = "toggle" KEY_LED_0 = "led0"
# ACTION_BRIGHTNESS_UP = "brightness_up_click" KEY_LED_1 = "led1"
# ACTION_BRIGHTNESS_DOWN = "brightness_down_click" KEY_LED_2 = "led2"
# ACTION_RIGHT = "arrow_right_click" KEY_LED_3 = "led3"
# ACTION_LEFT = "arrow_left_click" KEY_LED_4 = "led4"
# ACTION_BRIGHTNESS_UP_LONG = "brightness_up_hold" KEY_LED_5 = "led5"
# ACTION_BRIGHTNESS_DOWN_LONG = "brightness_down_hold" KEY_LED_6 = "led6"
# ACTION_RIGHT_LONG = "arrow_right_hold" KEY_LED_7 = "led7"
# ACTION_LEFT_LONG = "arrow_left_hold" KEY_LED_8 = "led8"
# # KEY_LED_9 = "led9"
# COMMANDS = [ACTION_TOGGLE, ACTION_LEFT, ACTION_RIGHT, ACTION_BRIGHTNESS_UP, ACTION_BRIGHTNESS_DOWN,
# ACTION_LEFT_LONG, ACTION_RIGHT_LONG, ACTION_BRIGHTNESS_UP_LONG, ACTION_BRIGHTNESS_DOWN_LONG]
# def __init__(self, mqtt_client, topic): def __init__(self, mqtt_client, topic, ):
# super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
for i in range(0, 10):
key = getattr(self, "KEY_LED_%d" % i)
self.data[key] = False
self.add_callback(key, self.print_formatted, None)
# def __rx__(self, client, userdata, message): def __rx__(self, client, userdata, message):
# pass value = payload_filter(message.payload)
if message.topic.startswith(self.topic) and message.topic.endswith('/set'):
targetkey = message.topic.split('/')[-2]
if targetkey in self.data.keys():
self.store_data(**{targetkey: value})
else:
print("Unknown key %s in %s" % (targetkey, self.__class__.__name__))
# def command(self, command): def print_formatted(self, device, key, value):
# try: print_light(COLOR_GUI_ACTIVE, value, self.topic, '(%s)' % self.names.get(key, key), True)
# command, value = command.split(' ')
# except ValueError:
# value = None
# else:
# value = json.loads(value)
# if command in self.capabilities():
# action = self.COMMANDS[self.COMMANDS.index(command)]
# if self.COMMANDS.index(command) <= 4:
# self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
# elif self.COMMANDS.index(command) <= 8:
# self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
# time.sleep(value or 0.5)
# action = '_'.join(action.split('_')[:-1] + ['release'])
# self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
# class remote(base): class remote(base):
# def __rx__(self, client, userdata, message): def __rx__(self, client, userdata, message):
# if message.topic == self.topic + "/VOLUP": if message.topic == self.topic + "/VOLUP":
# if payload_filter(message.payload): if payload_filter(message.payload):
# icon = u'\u1403' icon = u'\u1403'
# else: else:
# icon = u'\u25a1' icon = u'\u25a1'
# elif message.topic == self.topic + "/VOLDOWN": elif message.topic == self.topic + "/VOLDOWN":
# if payload_filter(message.payload): if payload_filter(message.payload):
# icon = u'\u1401' icon = u'\u1401'
# else: else:
# icon = u'\u25a1' icon = u'\u25a1'
# else: else:
# return return
# devicename = ' - '.join(self.topic.split('/')[1:-1]) devicename = ' - '.join(self.topic.split('/')[1:-1])
# print(COLOR_REMOTE + 10 * ' ' + icon + 6 * ' ' + devicename + colored.attr("reset")) print(COLOR_REMOTE + 10 * ' ' + icon + 6 * ' ' + devicename + colored.attr("reset"))
# class gui_heating_valve(base): class brennenstuhl_heating_valve(base):
# AUTOSEND = False TEMP_RANGE = [10, 30]
# # #
# TEMP_RANGE = [10, 30] KEY_TEMPERATURE_SETPOINT = "current_heating_setpoint"
# # KEY_TEMPERATURE = "local_temperature"
# KEY_TIMER = "timer" #
# KEY_TEMPERATURE = "temperature" COMMANDS = [
# KEY_SETPOINT_TEMP = "setpoint_temp" "get_temperature_setpoint", "set_temperature_setpoint",
# KEY_SETPOINT_TO_DEFAULT = "setpoint_to_default" ]
# KEY_BOOST = 'boost'
# KEY_AWAY = "away"
# KEY_SUMMER = "summer"
# KEY_ENABLE = "enable"
# #
# COMMANDS = [
# "get_temperature",
# "get_temperature_setpoint", "set_temperature_setpoint",
# "trigger_boost", "trigger_setpoint_to_default",
# "toggle_away", "toggle_summer",
# ]
# def __init__(self, mqtt_client, topic): def __init__(self, mqtt_client, topic):
# super().__init__(mqtt_client, topic) super().__init__(mqtt_client, topic)
# self.add_callback(self.KEY_SETPOINT_TEMP, self.print_formatted, None) self.store_data(**{
# self.add_callback(self.KEY_TIMER, self.print_formatted, None) self.KEY_TEMPERATURE_SETPOINT: 20,
# self.add_callback(self.KEY_AWAY, self.print_formatted, None) self.KEY_TEMPERATURE: 20.7,
# self.add_callback(self.KEY_SUMMER, self.print_formatted, None) })
# # self.add_callback(self.KEY_TEMPERATURE_SETPOINT, self.print_formatted, None)
# self.store_data(**{
# self.KEY_TEMPERATURE: 20.7,
# self.KEY_SETPOINT_TEMP: 20,
# self.KEY_TIMER: 0,
# self.KEY_AWAY: False,
# self.KEY_SUMMER: False,
# self.KEY_ENABLE: True
# })
# def __rx__(self, client, userdata, message): def __rx__(self, client, userdata, message):
# value = payload_filter(message.payload) if message.topic.startswith(self.topic) and message.topic.endswith("/set"):
# if message.topic.startswith(self.topic) and message.topic.endswith('/set'): payload = payload_filter(message.payload)
# targetkey = message.topic.split('/')[-2] self.store_data(**payload)
# if targetkey in self.data.keys():
# self.store_data(**{targetkey: value})
# else:
# print("Unknown key %s in %s::%s" % (targetkey, message.topic, self.__class__.__name__))
# elif message.topic == self.topic + '/get':
# self.__tx__(None)
# def send(self, key, data): def command(self, command):
# if data is not None: try:
# topic = self.topic + '/' + key command, value = command.split(' ')
# self.mqtt_client.send(topic, json.dumps(data)) except ValueError:
value = None
if command in self.COMMANDS:
if command == self.COMMANDS[0]:
self.print_formatted(self, self.KEY_TEMPERATURE_SETPOINT, self.data.get(self.KEY_TEMPERATURE_SETPOINT))
elif command == self.COMMANDS[1]:
self.store_data(**{self.KEY_TEMPERATURE_SETPOINT: command_float_value(value)})
# def command(self, command): def print_formatted(self, device, key, value):
# try: devicename = ' - '.join(self.topic.split('/')[1:])
# command, value = command.split(' ') if key == self.KEY_TEMPERATURE_SETPOINT:
# except ValueError: perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0])
# value = None perc = 100 if perc > 100 else perc
# if command in self.COMMANDS: perc = 0 if perc < 0 else perc
# if command == self.COMMANDS[0]: print_percent(COLOR_HEATING_VALVE, '\u03d1', perc, "%4.1f°C" % value, self.topic, "")
# self.print_formatted(self, self.KEY_TEMPERATURE, self.data.get(self.KEY_TEMPERATURE))
# elif command == self.COMMANDS[1]:
# self.print_formatted(self, self.KEY_SETPOINT_TEMP, self.data.get(self.KEY_SETPOINT_TEMP))
# elif command == self.COMMANDS[2]:
# self.send(self.KEY_SETPOINT_TEMP, command_float_value(value))
# elif command == self.COMMANDS[3]:
# self.send(self.KEY_BOOST, True)
# elif command == self.COMMANDS[4]:
# self.send(self.KEY_SETPOINT_TO_DEFAULT, True)
# elif command == self.COMMANDS[5]:
# self.send(self.KEY_AWAY, not self.data.get(self.KEY_AWAY))
# elif command == self.COMMANDS[6]:
# self.send(self.KEY_SUMMER, not self.data.get(self.KEY_SUMMER))
# def print_formatted(self, device, key, value):
# devicename = ' - '.join(self.topic.split('/')[1:]) class gui_heating_valve(base):
# if key == self.KEY_TIMER: AUTOSEND = False
# value /= 60 #
# try: TEMP_RANGE = [10, 30]
# perc = 100 * value / 60 #
# except TypeError: KEY_TIMER = "timer"
# value = 0 KEY_TEMPERATURE = "temperature"
# perc = 0 KEY_SETPOINT_TEMP = "setpoint_temp"
# print_percent(COLOR_GUI_ACTIVE, 't', perc, "%4.1fmin" % value, self.topic, "(Timer)") KEY_SETPOINT_TO_DEFAULT = "setpoint_to_default"
# elif key == self.KEY_TEMPERATURE: KEY_BOOST = 'boost'
# perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0]) KEY_AWAY = "away"
# perc = 100 if perc > 100 else perc KEY_SUMMER = "summer"
# perc = 0 if perc < 0 else perc KEY_ENABLE = "enable"
# print_percent(COLOR_GUI_ACTIVE, '\u03d1', perc, "%4.1f°C" % value, self.topic, "(Temperature)") #
# elif key == self.KEY_SETPOINT_TEMP: COMMANDS = [
# perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0]) "get_temperature",
# perc = 100 if perc > 100 else perc "get_temperature_setpoint", "set_temperature_setpoint",
# perc = 0 if perc < 0 else perc "trigger_boost", "trigger_setpoint_to_default",
# print_percent(COLOR_GUI_ACTIVE if self.data.get(self.KEY_ENABLE) else COLOR_GUI_PASSIVE, "toggle_away", "toggle_summer",
# '\u03d1', perc, "%4.1f°C" % value, self.topic, "(Setpoint)") ]
# elif key == self.KEY_AWAY:
# print_switch(COLOR_GUI_ACTIVE, value, self.topic, "(Away Mode)") def __init__(self, mqtt_client, topic):
# elif key == self.KEY_SUMMER: super().__init__(mqtt_client, topic)
# print_switch(COLOR_GUI_ACTIVE, value, self.topic, "(Summer Mode)") self.add_callback(self.KEY_SETPOINT_TEMP, self.print_formatted, None)
self.add_callback(self.KEY_TIMER, self.print_formatted, None)
self.add_callback(self.KEY_AWAY, self.print_formatted, None)
self.add_callback(self.KEY_SUMMER, self.print_formatted, None)
#
self.store_data(**{
self.KEY_TEMPERATURE: 20.7,
self.KEY_SETPOINT_TEMP: 20,
self.KEY_TIMER: 0,
self.KEY_AWAY: False,
self.KEY_SUMMER: False,
self.KEY_ENABLE: True
})
def __rx__(self, client, userdata, message):
value = payload_filter(message.payload)
if message.topic.startswith(self.topic) and message.topic.endswith('/set'):
targetkey = message.topic.split('/')[-2]
if targetkey in self.data.keys():
self.store_data(**{targetkey: value})
else:
print("Unknown key %s in %s::%s" % (targetkey, message.topic, self.__class__.__name__))
elif message.topic == self.topic + '/get':
self.__tx__(None)
def send(self, key, data):
if data is not None:
topic = self.topic + '/' + key
self.mqtt_client.send(topic, json.dumps(data))
def command(self, command):
try:
command, value = command.split(' ')
except ValueError:
value = None
if command in self.COMMANDS:
if command == self.COMMANDS[0]:
self.print_formatted(self, self.KEY_TEMPERATURE, self.data.get(self.KEY_TEMPERATURE))
elif command == self.COMMANDS[1]:
self.print_formatted(self, self.KEY_SETPOINT_TEMP, self.data.get(self.KEY_SETPOINT_TEMP))
elif command == self.COMMANDS[2]:
self.send(self.KEY_SETPOINT_TEMP, command_float_value(value))
elif command == self.COMMANDS[3]:
self.send(self.KEY_BOOST, True)
elif command == self.COMMANDS[4]:
self.send(self.KEY_SETPOINT_TO_DEFAULT, True)
elif command == self.COMMANDS[5]:
self.send(self.KEY_AWAY, not self.data.get(self.KEY_AWAY))
elif command == self.COMMANDS[6]:
self.send(self.KEY_SUMMER, not self.data.get(self.KEY_SUMMER))
def print_formatted(self, device, key, value):
devicename = ' - '.join(self.topic.split('/')[1:])
if key == self.KEY_TIMER:
value /= 60
try:
perc = 100 * value / 60
except TypeError:
value = 0
perc = 0
print_percent(COLOR_GUI_ACTIVE, 't', perc, "%4.1fmin" % value, self.topic, "(Timer)")
elif key == self.KEY_TEMPERATURE:
perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0])
perc = 100 if perc > 100 else perc
perc = 0 if perc < 0 else perc
print_percent(COLOR_GUI_ACTIVE, '\u03d1', perc, "%4.1f°C" % value, self.topic, "(Temperature)")
elif key == self.KEY_SETPOINT_TEMP:
perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0])
perc = 100 if perc > 100 else perc
perc = 0 if perc < 0 else perc
print_percent(COLOR_GUI_ACTIVE if self.data.get(self.KEY_ENABLE) else COLOR_GUI_PASSIVE,
'\u03d1', perc, "%4.1f°C" % value, self.topic, "(Setpoint)")
elif key == self.KEY_AWAY:
print_switch(COLOR_GUI_ACTIVE, value, self.topic, "(Away Mode)")
elif key == self.KEY_SUMMER:
print_switch(COLOR_GUI_ACTIVE, value, self.topic, "(Summer Mode)")

View File

@ -1,6 +1,6 @@
import config import config
from __simulation__.devices import shelly, silvercrest_powerplug, tradfri_light, my_powerplug, brennenstuhl_heating_valve from __simulation__.devices import shelly, silvercrest_powerplug, tradfri_light, tradfri_button, silvercrest_motion_sensor, my_powerplug, remote, brennenstuhl_heating_valve
from __simulation__.devices import videv_light from __simulation__.devices import gui_light, gui_led_array, gui_heating_valve
import inspect import inspect
@ -40,58 +40,58 @@ class base(object):
class gfw_floor(base): class gfw_floor(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
self.gui_main_light = gui_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_GUI, True, True, True)
self.main_light = shelly(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) self.main_light = shelly(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 1, True, True, True, False) self.main_light_zigbee_1 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 1, True, True, True, False)
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True) self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_1.power_on, "on")
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False) self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_1.power_off, "off")
self.main_light_zigbee_2 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 2, True, True, True, False) self.main_light_zigbee_2 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 2, True, True, True, False)
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_2.power_on, True) self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_2.power_on, "on")
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_2.power_off, False) self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_1.power_off, "off")
#
self.videv_main_light = videv_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_VIDEV, True, True, True)
class gfw_marion(base): class gfw_marion(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
self.gui_main_light = gui_light(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_GUI, True, False, False)
self.main_light = shelly(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) self.main_light = shelly(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE) self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE)
self.gui_heating_valve = gui_heating_valve(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_GUI)
#
self.videv_main_light = videv_light(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_VIDEV, True, False, False)
class gfw_dirk(base): class gfw_dirk(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
self.gui_main_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI, True, True, True)
self.main_light = shelly(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) self.main_light = shelly(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE, True, True, True) self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE, True, True, True)
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True) self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False) self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
self.amplifier = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 0)
self.amplifier.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Amplifier")
self.desk_light = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 1)
self.desk_light.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Desk Light")
self.cd_player = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 2)
self.cd_player.add_channel_name(my_powerplug.KEY_OUTPUT_0, "CD_Player")
self.pc_dock = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 3)
self.pc_dock.add_channel_name(my_powerplug.KEY_OUTPUT_0, "PC_Dock")
self.desk_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE, True, True, True)
self.desk_light.add_callback(my_powerplug.KEY_OUTPUT_0, self.desk_light_zigbee.power_on, True)
self.desk_light.add_callback(my_powerplug.KEY_OUTPUT_0, self.desk_light_zigbee.power_off, False)
self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)
# #
self.videv_main_light = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_VIDEV, True, True, True) self.powerplug = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG)
self.videv_amplifier = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_VIDEV, True, False, False) self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Amplifier")
self.videv_desk_light = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_VIDEV, True, True, True) self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_1, "Desk_Light")
self.videv_cd_player = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_VIDEV, True, False, False) self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_2, "CD_Player")
self.videv_pc_dock = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_VIDEV, True, False, False) self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_3, "PC_Dock")
self.gui_amplifier = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_GUI, True, False, False)
self.gui_desk_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI, True, True, True)
self.desk_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE, True, True, True)
self.powerplug.add_callback(my_powerplug.KEY_OUTPUT_1, self.desk_light_zigbee.power_on, True)
self.powerplug.add_callback(my_powerplug.KEY_OUTPUT_1, self.desk_light_zigbee.power_off, False)
self.gui_cd_player = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_GUI, True, False, False)
self.gui_pc_dock = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_GUI, True, False, False)
#
self.remote = remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
#
self.input_device = tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
self.led_array = gui_led_array(mqtt_client, config.TOPIC_GFW_DIRK_DEVICE_CHOOSER_LED)
self.led_array.add_channel_name(gui_led_array.KEY_LED_0, "Main Light")
self.led_array.add_channel_name(gui_led_array.KEY_LED_1, "Desk Light")
self.led_array.add_channel_name(gui_led_array.KEY_LED_2, "Amplifier")
#
self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)
self.gui_heating_valve = gui_heating_valve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_GUI)
class gfw(base): class gfw(base):
@ -103,43 +103,32 @@ class gfw(base):
class ffw_julian(base): class ffw_julian(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI, True, True, True)
self.main_light = shelly(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) self.main_light = shelly(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE, True, True, True) self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE, True, True, True)
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True) self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False) self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
#
self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_VIDEV, True, True, True)
class ffw_livingroom(base): class ffw_livingroom(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_GUI, True, True, True)
self.main_light = shelly(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) self.main_light = shelly(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE, True, True, True)
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True)
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False)
#
self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_VIDEV, True, True, True)
class ffw_sleep(base): class ffw_sleep(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_GUI, True, True, False)
self.main_light = shelly(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) self.main_light = shelly(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE, True, True, True)
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True)
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False)
#
self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_VIDEV, True, True, False)
class ffw_bath(base): class ffw_bath(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE) self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE)
self.gui_heating_valve = gui_heating_valve(mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_GUI)
class ffw(base): class ffw(base):
@ -152,90 +141,77 @@ class ffw(base):
class ffe_floor(base): class ffe_floor(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_GUI, True, False, False)
self.main_light = shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) self.main_light = shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
#
self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV, True, False, False)
class ffe_kitchen(base): class ffe_kitchen(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI, True, False, False)
self.main_light = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) self.main_light = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
#
self.gui_circulation_pump = gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_GUI, True, False, False)
self.circulation_pump = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY, self.circulation_pump = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY,
input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER, output_0_auto_off=10*60) input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER, output_0_auto_off=10*60)
self.circulation_pump.add_channel_name(shelly.KEY_OUTPUT_0, "Circulation Pump") self.circulation_pump.add_channel_name(shelly.KEY_OUTPUT_0, "Circulation Pump")
#
self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV, True, False, False)
self.videv_circulation_pump = videv_light(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV, True, False, False, True)
class ffe_diningroom(base): class ffe_diningroom(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_GUI, True, False, False)
self.main_light = shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) self.main_light = shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
self.gui_floor_lamp = gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_GUI, True, False, False)
self.floor_lamp = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG) self.floor_lamp = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
self.floor_lamp.add_channel_name(silvercrest_powerplug.KEY_OUTPUT_0, "Floor Lamp") self.floor_lamp.add_channel_name(silvercrest_powerplug.KEY_OUTPUT_0, "Floor Lamp")
if config.CHRISTMAS: if config.CHRISTMAS:
self.garland = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG) self.garland = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
self.garland.add_channel_name(silvercrest_powerplug, "Garland") self.garland.add_channel_name(silvercrest_powerplug, "Garland")
#
self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV, True, False, False)
self.videv_floor_lamp = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV, True, False, False)
if config.CHRISTMAS:
self.videv_garland = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_VIDEV, True, False, False)
class ffe_sleep(base): class ffe_sleep(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_GUI, True, True, True)
self.main_light = shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) self.main_light = shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE, True, True, True) self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE, True, True, True)
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True) self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False) self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
self.bed_light_di_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE, True, True, False)
self.bed_light_ma = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)
self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE)
# #
self.videv_bed_light_ma = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV, True, False, False) self.gui_bed_light_di = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_GUI, True, True, False)
self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV, True, True, True) self.bed_light_di_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE, True, True, False)
self.videv_bed_light_di = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV, True, True, False) self.gui_bed_light_ma = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_GUI, True, False, False)
self.videv_bed_light_ma = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV, True, False, False) self.bed_light_ma_powerplug = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)
#
self.input_device = tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
self.led_array = gui_led_array(mqtt_client, config.TOPIC_FFE_SLEEP_DEVICE_CHOOSER_LED)
self.led_array.add_channel_name(gui_led_array.KEY_LED_0, "Main Light")
self.led_array.add_channel_name(gui_led_array.KEY_LED_1, "Bed Light Dirk")
#
self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE)
self.gui_heating_valve = gui_heating_valve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_GUI)
class ffe_livingroom(base): class ffe_livingroom(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_GUI, True, True, True)
self.main_light = shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) self.main_light = shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE, True, True, True) self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE, True, True, True)
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True) self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False) self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
for i in range(1, 7):
self.floor_lamp_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % 1, True, True, True)
for i in range(2, 7):
setattr(self, "floor_lamp_zigbee_%d" % i, tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i, True, True, True)) setattr(self, "floor_lamp_zigbee_%d" % i, tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i, True, True, True))
self.gui_floor_lamp = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_GUI, True, True, True)
if config.CHRISTMAS: if config.CHRISTMAS:
self.xmas_tree = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG) self.xmas_tree = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
self.xmas_tree.add_channel_name(silvercrest_powerplug, "Xmas-Tree") self.xmas_tree.add_channel_name(silvercrest_powerplug, "Xmas-Tree")
self.gui_xmas_tree = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_GUI)
self.xmas_star = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG) self.xmas_star = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
self.xmas_star.add_channel_name(silvercrest_powerplug, "Xmas-Star") self.xmas_star.add_channel_name(silvercrest_powerplug, "Xmas-Star")
#
self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV, True, True, True)
self.videv_floor_lamp = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV, True, True, True)
if config.CHRISTMAS:
self.videv_xmas_tree = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV)
class ffe(base): class ffe(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
@ -248,11 +224,13 @@ class ffe(base):
class stairway(base): class stairway(base):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
self.gui_main_light = gui_light(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_GUI, True, False, False)
self.gui_main_light.add_led_name(self.gui_main_light.KEY_LED_X % 0, "Motion Ground Floor")
self.gui_main_light.add_led_name(self.gui_main_light.KEY_LED_X % 1, "Motion First Floor")
self.main_light = shelly(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER) self.main_light = shelly(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light") self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
self.motion_sensor_gf = silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF)
# self.motion_sensor_ff = silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF)
self.videv_main_light = videv_light(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV, True, False, False, True)
class house(base): class house(base):

View File

@ -1,249 +1,232 @@
import colored import colored
import inspect
from __simulation__ import devices
import time import time
DT_TOGGLE = 0.3 DT_TOGGLE = 0.1
TEST_FULL = 'full'
TEST_SMOKE = 'smoke'
#
COLOR_SUCCESS = colored.fg("light_green")
COLOR_FAIL = colored.fg("light_red")
class test_smarthome(object): class test_smarthome(object):
def __init__(self, rooms): def __init__(self, house):
# add testcases by room objects self.house = house
for name in rooms.getmembers():
obj = rooms.getobjbyname(name)
if obj.__class__.__name__ == "videv_light":
common_name = '.'.join(name.split('.')[:-1]) + '.' + name.split('.')[-1][6:]
li_device = rooms.getobjbyname(common_name + '_zigbee') if obj.enable_brightness or obj.enable_color_temp else None
try:
sw_device = rooms.getobjbyname(common_name) if obj.enable_state else None
except AttributeError:
# must be a device without switching device
sw_device = li_device
setattr(self, common_name.replace('.', '_'), testcase_light(obj, sw_device, li_device))
# add test collection
self.all = test_collection(self)
def getmembers(self, prefix=''): def __smoke__(self):
rv = [] result = ""
for name, obj in inspect.getmembers(self): result += "Smoke-Test\n"
if prefix: result += " GUI Element exists for every shelly instance\n"
full_name = prefix + '.' + name result += self.__gui_element_exists__("shelly")
else: result += " On-Off test for every shelly instance\n"
full_name = name result += self.__on_off_test__("shelly")
if not name.startswith('_'): result += " GUI Element exists for every silvercrest_powerplug instance\n"
result += self.__gui_element_exists__("silvercrest_powerplug")
result += " On-Off test for every silvercrest_powerplug instance\n"
result += self.__on_off_test__("silvercrest_powerplug")
result += " GUI Element exists for every my_powerplug instance and port\n"
result += self.__gui_element_exists_my_powerplug__()
result += " On-Off test for every my_powerplug instance\n"
result += self.__on_off_test_my_powerplug__()
result += " GUI Element exists for every tradfri_light instance\n"
result += self.__gui_element_exists__("tradfri_light")
result += " Enable and disable test for gui elements corresponding with tradfri_light\n"
result += self.__br_ct_enable_test__()
result += " Chnage brightness and color_temp by gui test\n"
result += self.__br_ct_change_test__()
return result
def __full__(self):
result = "Full-Test"
return result
def smoke(self):
print(self.__smoke__())
def full(self):
out = self.__smoke__()
out += self.__full__()
print(out)
def print_error(self, text, lvl=2):
return lvl*" " + colored.fg("light_red") + '* ' + text + "\n" + colored.attr("reset")
def print_success(self, text, lvl=2):
return lvl*" " + colored.fg("light_green") + '* ' + text + "\n" + colored.attr("reset")
def __gui_element_exists__(self, obj_name):
result = ""
for member in self.house.getmembers():
obj = self.house.getobjbyname(member)
if obj.__class__.__name__ == obj_name:
if obj_name == "tradfri_light":
basename = member[:member.index('_zigbee')]
else:
basename = member
try: try:
if obj.__class__.__bases__[0].__name__ == "testcase" or obj.__class__.__name__ == "test_collection": gui = self.house.getobjbyname('.'.join(basename.split('.')[:-1]) + '.gui_' + basename.split('.')[-1])
rv.append(full_name) except AttributeError:
result += self.print_error("No GUI element available, while testing %s (%s)." % (member, obj_name))
else:
result += self.print_success("GUI element available, while testing %s (%s)." % (member, obj_name))
return result
def __gui_element_exists_my_powerplug__(self):
result = ""
for member in self.house.getmembers():
obj = self.house.getobjbyname(member)
if obj.__class__.__name__ == "my_powerplug":
for channel in [obj.KEY_OUTPUT_0, obj.KEY_OUTPUT_1, obj.KEY_OUTPUT_2, obj.KEY_OUTPUT_3]:
try:
gui = self.house.getobjbyname('.'.join(member.split(
'.')[:-1]) + '.gui_' + obj.names.get(channel.lower(), "__dummy__").lower())
except AttributeError:
result += self.print_error("No GUI element available, while testing %s (%s)." % (member, obj.names.get(channel)))
else: else:
rv.extend(obj.getmembers(full_name)) result += self.print_success("GUI element available, while testing %s (%s)." % (member, obj.names.get(channel)))
return result
def __on_off_test_my_powerplug__(self):
result = ""
for member in self.house.getmembers():
obj = self.house.getobjbyname(member)
if obj.__class__.__name__ == "my_powerplug":
for channel in [obj.KEY_OUTPUT_0, obj.KEY_OUTPUT_1, obj.KEY_OUTPUT_2, obj.KEY_OUTPUT_3]:
try:
gui = self.house.getobjbyname('.'.join(member.split(
'.')[:-1]) + '.gui_' + obj.names.get(channel.lower(), "__dummy__").lower())
except AttributeError:
raise AttributeError
pass # exists test already covers non existing gui-elements
else:
success = True
# Initial state equal between obj and gui
obj_state = obj.data.get(channel)
gui_state = gui.data.get(gui.KEY_STATE)
if obj_state != gui_state:
result += self.print_error("Initial state of %s (%s) is not equal to GUI state (%s), while testing %s (%s)" %
("my_powerplug", obj_state, gui_state, member, obj.names.get(channel)))
success = False
# state obj change results in state change of obj and gui
for i in range(1, 3):
gui.command("toggle_state")
time.sleep(2 * DT_TOGGLE)
last_obj_state = obj_state
obj_state = obj.data.get(channel)
gui_state = gui.data.get(gui.KEY_STATE)
if last_obj_state == obj_state:
result += self.print_error("State after %d. toggle of gui state: State unchanged (%s), while testing %s (%s)" %
(i, obj_state, member, obj.names.get(channel)))
success = False
if obj_state != gui_state:
result += self.print_error("State after %d. toggle of gui state:: State of device (%s) is not equal to GUI state (%s), while testing %s (%s)" %
(i, obj_state, gui_state, member, obj.names.get(channel)))
success = False
#
if success:
result += self.print_success("On-Off test successfull, while testing %s (%s)." % (member, obj.names.get(channel)))
return result
def __on_off_test__(self, obj_name):
result = ""
for member in self.house.getmembers():
obj = self.house.getobjbyname(member)
if obj.__class__.__name__ == obj_name:
try:
gui = self.house.getobjbyname('.'.join(member.split('.')[:-1]) + '.gui_' + member.split('.')[-1])
except AttributeError: except AttributeError:
pass pass # exists test already covers non existing gui-elements
return rv else:
success = True
# Initial state equal between obj and gui
obj_state = obj.data.get(obj.KEY_OUTPUT_0).lower() == "on"
gui_state = gui.data.get(gui.KEY_STATE)
if obj_state != gui_state:
result += self.print_error("Initial state of %s (%s) is not equal to GUI state (%s), while testing %s (%s)" %
(obj_name, obj_state, gui_state, member, obj_name))
success = False
# state obj change results in state change of obj and gui
for i in range(1, 3):
gui.command("toggle_state")
time.sleep(2 * DT_TOGGLE)
last_obj_state = obj_state
obj_state = obj.data.get(obj.KEY_OUTPUT_0).lower() == "on"
gui_state = gui.data.get(gui.KEY_STATE)
if last_obj_state == obj_state:
result += self.print_error("State after %d. toggle of gui state: State unchanged (%s), while testing %s (%s)" %
(i, obj_state, member, obj_name))
success = False
if obj_state != gui_state:
result += self.print_error("State after %d. toggle of gui state:: State of device (%s) is not equal to GUI state (%s), while testing %s (%s)" %
(i, obj_state, gui_state, member, obj_name))
success = False
#
if success:
result += self.print_success("On-Off test successfull, while testing %s." % (member))
return result
def getobjbyname(self, name): def __br_ct_enable_test__(self):
if name.startswith("test."): result = ""
name = name[5:] for member in self.house.getmembers():
obj = self obj = self.house.getobjbyname(member)
for subname in name.split('.'): if obj.__class__.__name__ == "tradfri_light":
obj = getattr(obj, subname) basename = member[:member.index('_zigbee')]
return obj gui = self.house.getobjbyname('.'.join(basename.split('.')[:-1]) + '.gui_' + basename.split('.')[-1])
success = True
#
if gui.data.get(gui.KEY_ENABLE) != False:
result += self.print_error("Inital enable state is not False, while testing %s." % (member))
success = False
#
gui.command("toggle_state")
time.sleep(2 * DT_TOGGLE)
if gui.data.get(gui.KEY_ENABLE) != True:
result += self.print_error("Enable state is not True after switching on, while testing %s." % (member))
success = False
#
gui.command("toggle_state")
time.sleep(2 * DT_TOGGLE)
if gui.data.get(gui.KEY_ENABLE) != False:
result += self.print_error("Enable state is not False after switching off, while testing %s." % (member))
success = False
#
if success:
result += self.print_success("Enable-Disable test successfull, while testing %s." % (member))
return result
def command(self, full_command): def __br_ct_change_test__(self):
try: result = ""
parameter = " " + full_command.split(' ')[1] for member in self.house.getmembers():
except IndexError: obj = self.house.getobjbyname(member)
parameter = "" if obj.__class__.__name__ == "tradfri_light":
command = full_command.split(' ')[0].split('.')[-1] + parameter basename = member[:member.index('_zigbee')]
device_name = '.'.join(full_command.split(' ')[0].split('.')[:-1]) gui = self.house.getobjbyname('.'.join(basename.split('.')[:-1]) + '.gui_' + basename.split('.')[-1])
self.getobjbyname(device_name).command(command) success = True
#
if gui.data.get(gui.KEY_STATE) != True:
class test_result_base(object): gui.command("toggle_state")
def __init__(self): time.sleep(2 * DT_TOGGLE)
self.__init_test_counters__() if gui.data.get(gui.KEY_STATE) != True:
result += self.print_error("Unable to switch on light, while testing %s." % (member))
def __init_test_counters__(self): success = False
self.test_counter = 0 continue
self.success_tests = 0 #
self.failed_tests = 0 if "set_brightness" in obj.capabilities():
brightness = gui.data.get(obj.KEY_BRIGHTNESS)
def statistic(self): targetvalue = brightness + (25 if brightness <= 50 else -25)
return (self.test_counter, self.success_tests, self.failed_tests) gui.command("set_brightness %d" % targetvalue)
time.sleep(2 * DT_TOGGLE)
def print_statistic(self): if gui.data.get(obj.KEY_BRIGHTNESS) != targetvalue:
color = COLOR_SUCCESS if self.test_counter == self.success_tests else COLOR_FAIL result += self.print_error("Brightness change by gui was not successfull, while testing %s." % (member))
print(color + "*** SUCCESS: (%4d/%4d) FAIL: (%4d/%4d) ***\n" % (self.success_tests, success = False
self.test_counter, self.failed_tests, self.test_counter) + colored.attr("reset")) if "set_color_temp" in obj.capabilities():
color_temp = gui.data.get(obj.KEY_COLOR_TEMP)
targetvalue = color_temp + (3 if color_temp <= 5 else -3)
class test_collection(test_result_base): gui.command("set_color_temp %d" % targetvalue)
def __init__(self, test_instance): time.sleep(2 * DT_TOGGLE)
super().__init__() if gui.data.get(obj.KEY_COLOR_TEMP) != targetvalue:
self.test_instance = test_instance result += self.print_error("Color temperature change by gui was not successfull, while testing %s." % (member))
success = False
def capabilities(self): #
return [TEST_FULL, TEST_SMOKE] gui.command("toggle_state")
time.sleep(2 * DT_TOGGLE)
def command(self, command): #
self.__init_test_counters__() if success:
for member in self.test_instance.getmembers(): result += self.print_success("Brightness-ColorTemp test successfull, while testing %s." % (member))
obj = self.test_instance.getobjbyname(member) return result
if id(obj) != id(self):
obj.test_all(command)
num, suc, fail = obj.statistic()
self.test_counter += num
self.success_tests += suc
self.failed_tests += fail
self.print_statistic()
class testcase(test_result_base):
def __init__(self):
super().__init__()
self.__test_list__ = []
def capabilities(self):
if len(self.__test_list__) > 0 and not 'test_all' in self.__test_list__:
self.__test_list__.append('test_all')
self.__test_list__.sort()
return self.__test_list__
def test_all(self, test=TEST_FULL):
test_counter = 0
success_tests = 0
failed_tests = 0
for tc_name in self.capabilities():
if tc_name != "test_all":
self.command(tc_name, test)
test_counter += self.test_counter
success_tests += self.success_tests
failed_tests += self.failed_tests
self.test_counter = test_counter
self.success_tests = success_tests
self.failed_tests = failed_tests
def command(self, command, test=TEST_FULL):
self.__init_test_counters__()
tc = getattr(self, command)
self.__init_test_counters__()
rv = tc(test)
self.print_statistic()
def heading(self, desciption):
print(desciption)
def sub_heading(self, desciption):
print(2 * " " + desciption)
def result(self, desciption, success):
self.test_counter += 1
if success:
self.success_tests += 1
else:
self.failed_tests += 1
print(4 * " " + ("SUCCESS - " if success else "FAIL - ") + desciption)
class testcase_light(testcase):
def __init__(self, videv, sw_device, li_device):
self.videv = videv
self.sw_device = sw_device
self.li_device = li_device
self.__test_list__ = []
if self.videv.enable_state:
self.__test_list__.append('test_power_on_off')
if self.videv.enable_brightness:
self.__test_list__.append('test_brightness')
if self.videv.enable_color_temp:
self.__test_list__.append('test_color_temp')
def test_power_on_off(self, test=TEST_FULL):
self.heading("Power On/ Off test (%s)" % self.videv.topic)
#
sw_state = self.sw_device.get_data(self.sw_device.KEY_OUTPUT_0)
#
for i in range(0, 2):
self.sub_heading("State change of switching device")
#
self.sw_device.store_data(**{self.sw_device.KEY_OUTPUT_0: not self.sw_device.data.get(self.sw_device.KEY_OUTPUT_0)})
time.sleep(DT_TOGGLE)
self.result("Virtual device state after Switch on by switching device", sw_state != self.videv.get_data(self.videv.KEY_STATE))
self.result("Switching device state after Switch on by switching device",
sw_state != self.sw_device.get_data(self.sw_device.KEY_OUTPUT_0))
self.sub_heading("State change of virtual device")
#
self.videv.send(self.videv.KEY_STATE, not self.videv.data.get(self.videv.KEY_STATE))
time.sleep(DT_TOGGLE)
self.result("Virtual device state after Switch off by virtual device", sw_state == self.videv.get_data(self.videv.KEY_STATE))
self.result("Switching device state after Switch on by switching device",
sw_state == self.sw_device.get_data(self.sw_device.KEY_OUTPUT_0))
def test_brightness(self, test=TEST_FULL):
self.heading("Brightness test (%s)" % self.videv.topic)
#
br_state = self.li_device.get_data(self.li_device.KEY_BRIGHTNESS)
delta = -15 if br_state > 50 else 15
self.sw_device.store_data(**{self.sw_device.KEY_OUTPUT_0: True})
time.sleep(DT_TOGGLE)
for i in range(0, 2):
self.sub_heading("Brightness change by light device")
#
self.li_device.store_data(**{self.li_device.KEY_BRIGHTNESS: br_state + delta})
time.sleep(DT_TOGGLE)
self.result("Virtual device state after setting brightness by light device",
br_state + delta == self.videv.get_data(self.videv.KEY_BRIGHTNESS))
self.result("Light device state after setting brightness by light device", br_state +
delta == self.li_device.get_data(self.li_device.KEY_BRIGHTNESS))
self.sub_heading("Brightness change by virtual device")
#
self.videv.send(self.videv.KEY_BRIGHTNESS, br_state)
time.sleep(DT_TOGGLE)
self.result("Virtual device state after setting brightness by light device", br_state == self.videv.get_data(self.videv.KEY_BRIGHTNESS))
self.result("Light device state after setting brightness by light device",
br_state == self.li_device.get_data(self.li_device.KEY_BRIGHTNESS))
self.sw_device.store_data(**{self.sw_device.KEY_OUTPUT_0: False})
time.sleep(DT_TOGGLE)
def test_color_temp(self, test=TEST_FULL):
self.heading("Color temperature test (%s)" % self.videv.topic)
#
ct_state = self.li_device.get_data(self.li_device.KEY_COLOR_TEMP)
delta = -3 if ct_state > 5 else 3
self.sw_device.store_data(**{self.sw_device.KEY_OUTPUT_0: True})
time.sleep(DT_TOGGLE)
for i in range(0, 2):
self.sub_heading("Color temperature change by light device")
#
self.li_device.store_data(**{self.li_device.KEY_COLOR_TEMP: ct_state + delta})
time.sleep(DT_TOGGLE)
self.result("Virtual device state after setting color temperature by light device",
ct_state + delta == self.videv.get_data(self.videv.KEY_COLOR_TEMP))
self.result("Light device state after setting color temperature by light device", ct_state +
delta == self.li_device.get_data(self.li_device.KEY_COLOR_TEMP))
self.sub_heading("Color temperature change by virtual device")
#
self.videv.send(self.videv.KEY_COLOR_TEMP, ct_state)
time.sleep(DT_TOGGLE)
self.result("Virtual device state after setting color temperature by light device",
ct_state == self.videv.get_data(self.videv.KEY_COLOR_TEMP))
self.result("Light device state after setting color temperature by light device",
ct_state == self.li_device.get_data(self.li_device.KEY_COLOR_TEMP))
self.sw_device.store_data(**{self.sw_device.KEY_OUTPUT_0: False})
time.sleep(DT_TOGGLE)

View File

@ -580,17 +580,17 @@ class tradfri_light(base):
def unpack_filter(self, key): def unpack_filter(self, key):
if key == self.KEY_BRIGHTNESS: if key == self.KEY_BRIGHTNESS:
self[key] = round((self[key] - 1) * 100 / 253, 0) self[key] = (self[key] - 1) * 100 / 254
elif key == self.KEY_COLOR_TEMP: elif key == self.KEY_COLOR_TEMP:
self[key] = round((self[key] - 250) * 10 / 204, 0) self[key] = (self[key] - 250) * 10 / 204
else: else:
super().unpack_filter(key) super().unpack_filter(key)
def pack_filter(self, key, data): def pack_filter(self, key, data):
if key == self.KEY_BRIGHTNESS: if key == self.KEY_BRIGHTNESS:
return round(data * 253 / 100 + 1, 0) return data * 254 / 100 + 1
elif key == self.KEY_COLOR_TEMP: elif key == self.KEY_COLOR_TEMP:
return round(data * 204 / 10 + 250, 0) return data * 204 / 10 + 250
else: else:
return super().pack_filter(key, data) return super().pack_filter(key, data)
@ -708,6 +708,180 @@ class tradfri_button(base):
return "Low battery level detected for %s. Battery level was %.0f%%." % (self.topic, self.get(self.KEY_BATTERY)) return "Low battery level detected for %s. Battery level was %.0f%%." % (self.topic, self.get(self.KEY_BATTERY))
class nodered_gui_leds(base):
KEY_LED_0 = "led0"
KEY_LED_1 = "led1"
KEY_LED_2 = "led2"
KEY_LED_3 = "led3"
KEY_LED_4 = "led4"
KEY_LED_5 = "led5"
KEY_LED_6 = "led6"
KEY_LED_7 = "led7"
KEY_LED_8 = "led8"
KEY_LED_9 = "led9"
KEY_LED_LIST = [KEY_LED_0, KEY_LED_1, KEY_LED_2, KEY_LED_3, KEY_LED_4, KEY_LED_5, KEY_LED_6, KEY_LED_7, KEY_LED_8, KEY_LED_9]
#
TX_TYPE = base.TX_VALUE
def set_led(self, key, data):
"""data: [True, False]"""
self.logger.debug("Sending %s with content %s", key, str(data))
self.pack(key, data)
class nodered_gui_timer(base):
KEY_TIMER = "timer"
#
TX_TYPE = base.TX_VALUE
def set_timer(self, data):
"""data: numeric"""
self.pack(self.KEY_TIMER, data)
def set_timer_mcb(self, device, key, data):
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_timer(data)
class nodered_gui_button(base):
KEY_STATE = "state"
#
RX_KEYS = [KEY_STATE]
#
# RX
#
@property
def state(self):
"""rv: [True, False]"""
return self.get(self.KEY_STATE)
class nodered_gui_switch(nodered_gui_button):
TX_TYPE = base.TX_VALUE
#
# TX
#
def set_state(self, data):
"""data: [True, False]"""
self.pack(self.KEY_STATE, data)
def set_state_mcb(self, device, key, data):
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_state(data)
class nodered_gui_light(nodered_gui_switch, nodered_gui_leds, nodered_gui_timer):
KEY_ENABLE = "enable"
KEY_BRIGHTNESS = "brightness"
KEY_COLOR_TEMP = "color_temp"
#
TX_TYPE = base.TX_VALUE
#
RX_KEYS = nodered_gui_switch.RX_KEYS + [KEY_ENABLE, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
#
# RX
#
@property
def enable(self):
"""rv: [True, False]"""
return self.get(self.KEY_ENABLE)
@property
def brightness(self):
"""rv: [True, False]"""
return self.get(self.KEY_BRIGHTNESS)
@property
def color_temp(self):
"""rv: [True, False]"""
return self.get(self.KEY_COLOR_TEMP)
#
# TX
#
def set_enable(self, data):
"""data: [True, False]"""
self.pack(self.KEY_ENABLE, data)
def set_enable_mcb(self, device, key, data):
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_enable(data)
def set_brightness(self, data):
"""data: [0%, ..., 100%]"""
self.pack(self.KEY_BRIGHTNESS, data)
def set_brightness_mcb(self, device, key, data):
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_brightness(data)
def set_color_temp(self, data):
"""data: [0, ..., 10]"""
self.pack(self.KEY_COLOR_TEMP, data)
def set_color_temp_mcb(self, device, key, data):
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_color_temp(data)
class nodered_gui_radiator(nodered_gui_timer):
KEY_TEMPERATURE = "temperature"
KEY_SETPOINT_TEMP = "setpoint_temp"
KEY_SETPOINT_TO_DEFAULT = "setpoint_to_default"
KEY_BOOST = 'boost'
KEY_AWAY = "away"
KEY_SUMMER = "summer"
KEY_ENABLE = "enable"
#
RX_KEYS = [KEY_TEMPERATURE, KEY_SETPOINT_TEMP, KEY_SETPOINT_TO_DEFAULT, KEY_BOOST, KEY_AWAY, KEY_SUMMER]
#
# TX
#
def set_temperature(self, data):
"""data: [True, False]"""
self.pack(self.KEY_TEMPERATURE, data)
def set_temperature_mcb(self, device, key, data):
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_temperature(data)
def set_setpoint_temperature(self, data):
"""data: [True, False]"""
self.pack(self.KEY_SETPOINT_TEMP, data)
def set_setpoint_temperature_mcb(self, device, key, data):
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_setpoint_temperature(data)
def set_away(self, data):
"""data: [True, False]"""
self.pack(self.KEY_AWAY, data)
def set_away_mcb(self, device, key, data):
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_away(data)
def set_summer(self, data):
"""data: [True, False]"""
self.pack(self.KEY_SUMMER, data)
def set_summer_mcb(self, device, key, data):
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_summer(data)
def set_enable(self, data):
"""data: [True, False]"""
self.pack(self.KEY_ENABLE, data)
def set_enable_mcb(self, device, key, data):
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_enable(data)
class brennenstuhl_heatingvalve(base): class brennenstuhl_heatingvalve(base):
KEY_LINKQUALITY = "linkquality" KEY_LINKQUALITY = "linkquality"
KEY_BATTERY = "battery" KEY_BATTERY = "battery"

View File

@ -5,10 +5,9 @@
import config import config
import devices import devices
from function.modules import brightness_choose_n_action, timer_on_activation, heating_function from function.modules import brightness_choose_n_action, timer_on_activation, heating_function
import logging
from function.rooms import room from function.rooms import room
from function.videv import videv_switching, videv_switch_brightness, videv_switching_timer, videv_switch_brightness_color_temp, videv_heating, videv_multistate from function.videv import videv_switching, videv_switch_brightness, videv_switching_timer, videv_switch_brightness_color_temp, videv_heating, videv_multistate
import logging
try: try:
from config import APP_NAME as ROOT_LOGGER_NAME from config import APP_NAME as ROOT_LOGGER_NAME
except ImportError: except ImportError:
@ -25,6 +24,12 @@ class first_floor_east_floor(room):
self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY) self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY)
super().__init__(mqtt_client) super().__init__(mqtt_client)
##### TEMPORARY ###################################################################################################################
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_GUI)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
##### TEMPORARY ###################################################################################################################
# #
# Virtual Device Interface # Virtual Device Interface
# #
@ -52,6 +57,17 @@ class first_floor_east_kitchen(room):
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) self.circulation_pump_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.main_light_shelly.flash_0_mcb, True)
##### TEMPORARY ###################################################################################################################
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
self.gui_circulation_pump = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_GUI)
self.gui_circulation_pump.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.circulation_pump_shelly.set_output_0_mcb)
self.circulation_pump_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_circulation_pump.set_state_mcb)
self.circulation_pump.add_callback(timer_on_activation.KEY_TIMER, None, self.gui_circulation_pump.set_timer_mcb, True)
##### TEMPORARY ###################################################################################################################
# #
# Virtual Device Interface # Virtual Device Interface
# #
@ -65,6 +81,11 @@ class first_floor_east_kitchen(room):
self.circulation_pump, timer_on_activation.KEY_TIMER self.circulation_pump, timer_on_activation.KEY_TIMER
) )
def all_off(self, device=None, key=None, data=None):
self.circulation_pump_shelly.set_output_0(False)
self.circulation_pump_shelly.set_output_1(False)
return super().all_off(device, key, data)
class first_floor_east_dining(room): class first_floor_east_dining(room):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
@ -78,6 +99,16 @@ class first_floor_east_dining(room):
self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG) self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
super().__init__(mqtt_client) super().__init__(mqtt_client)
##### TEMPORARY ###################################################################################################################
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_GUI)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
self.gui_floorlamp = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_GUI)
self.gui_floorlamp.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.floorlamp_powerplug.set_output_0_mcb)
self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.gui_floorlamp.set_state_mcb)
##### TEMPORARY ###################################################################################################################
# #
# Functionality initialisation # Functionality initialisation
# #
@ -100,6 +131,12 @@ class first_floor_east_dining(room):
self.garland_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0 self.garland_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
) )
def all_off(self, device=None, key=None, data=None):
super().all_off(device, key, data)
self.floorlamp_powerplug.set_output_0(False)
if config.CHRISTMAS:
self.garland_powerplug.set_output_0(False)
class first_floor_east_sleep(room): class first_floor_east_sleep(room):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
@ -136,6 +173,68 @@ class first_floor_east_sleep(room):
# heating function # heating function
self.heating_function = heating_function(self.heating_valve, config.DEFAULT_TEMPERATURE_FFE_SLEEP) self.heating_function = heating_function(self.heating_valve, config.DEFAULT_TEMPERATURE_FFE_SLEEP)
##### TEMPORARY ###################################################################################################################
# main light
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_GUI)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_enable_mcb)
self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_main_light.set_brightness_mcb)
self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_main_light.set_color_temp_mcb)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.main_light_tradfri.set_brightness_mcb)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.main_light_tradfri.set_color_temp_mcb)
# bed light
self.gui_bed_light_di = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_GUI)
self.gui_bed_light_di.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.bed_light_di_tradfri.set_output_0_mcb)
self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_bed_light_di.set_state_mcb)
self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_bed_light_di.set_enable_mcb)
self.gui_bed_light_di.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.bed_light_di_tradfri.set_brightness_mcb)
self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_bed_light_di.set_enable_mcb)
self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_bed_light_di.set_brightness_mcb)
self.gui_bed_light_ma = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_GUI)
self.gui_bed_light_ma.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.bed_light_ma_powerplug.set_output_0_mcb)
self.bed_light_ma_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.gui_bed_light_ma.set_state_mcb)
# heating
self.gui_heating = devices.nodered_gui_radiator(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_GUI)
self.heating_function.add_callback(heating_function.KEY_TEMPERATURE_CURRENT, None, self.gui_heating.set_temperature_mcb, True)
def set_heating_setpoint(device, key, data):
self.heating_function.set(heating_function.KEY_USER_TEMPERATURE_SETPOINT, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TEMP, None, set_heating_setpoint)
self.heating_function.add_callback(heating_function.KEY_TEMPERATURE_SETPOINT, None, self.gui_heating.set_setpoint_temperature_mcb, True)
def boost(device, key, data):
self.heating_function.set(heating_function.KEY_START_BOOST, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_BOOST, None, boost)
def setpoint_to_default(device, key, data):
self.heating_function.set(heating_function.KEY_SET_DEFAULT_TEMPERATURE, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TO_DEFAULT, None, setpoint_to_default)
def away_mode(device, key, data):
self.heating_function.set(heating_function.KEY_AWAY_MODE, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_AWAY, None, away_mode)
self.heating_function.add_callback(heating_function.KEY_AWAY_MODE, None, self.gui_heating.set_away_mcb)
def summer_mode(device, key, data):
self.heating_function.set(heating_function.KEY_SUMMER_MODE, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SUMMER, None, summer_mode)
self.heating_function.add_callback(heating_function.KEY_SUMMER_MODE, None, self.gui_heating.set_summer_mcb)
self.heating_function.add_callback(heating_function.KEY_BOOST_TIMER, None, self.gui_heating.set_timer_mcb)
# active device led
self.gui_led_active_device = devices.nodered_gui_leds(mqtt_client, config.TOPIC_FFE_SLEEP_DEVICE_CHOOSER_LED)
def update_active_device_led(device, key, data):
for i in range(0, len(self.brightness_functions.brightness_device_list)):
self.gui_led_active_device.set_led(devices.nodered_gui_leds.KEY_LED_LIST[i], data == i)
self.brightness_functions.add_callback(brightness_choose_n_action.KEY_ACTIVE_DEVICE, None, update_active_device_led, True)
##### TEMPORARY ###################################################################################################################
# #
# Virtual Device Interface # Virtual Device Interface
# #
@ -163,6 +262,11 @@ class first_floor_east_sleep(room):
brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 2 brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 2
) )
def all_off(self, device=None, key=None, data=None):
super().all_off(device, key, data)
self.bed_light_di_tradfri.set_output_0(False)
self.bed_light_ma_powerplug.set_output_0(False)
class first_floor_east_living(room): class first_floor_east_living(room):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
@ -186,6 +290,33 @@ class first_floor_east_living(room):
# floor lamp synchronisation with main_light # floor lamp synchronisation with main_light
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_tradfri.set_output_0_mcb, True) self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_tradfri.set_output_0_mcb, True)
##### TEMPORARY ###################################################################################################################
# main light
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_GUI)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_enable_mcb)
self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_main_light.set_brightness_mcb)
self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_main_light.set_color_temp_mcb)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.main_light_tradfri.set_brightness_mcb)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.main_light_tradfri.set_color_temp_mcb)
self.gui_floorlamp = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_GUI)
self.gui_floorlamp.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.floorlamp_tradfri.set_output_0_mcb)
self.gui_floorlamp.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.floorlamp_tradfri.set_brightness_mcb)
self.gui_floorlamp.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.floorlamp_tradfri.set_color_temp_mcb)
self.floorlamp_tradfri[0].add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_floorlamp.set_state_mcb)
self.floorlamp_tradfri[0].add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_floorlamp.set_enable_mcb)
self.floorlamp_tradfri[0].add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_floorlamp.set_brightness_mcb)
self.floorlamp_tradfri[0].add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_floorlamp.set_color_temp_mcb)
if config.CHRISTMAS:
self.gui_xmas_tree = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_GUI)
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.gui_xmas_tree.set_state_mcb)
self.gui_xmas_tree.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_xmas_tree.set_output_0_mcb)
##### TEMPORARY ###################################################################################################################
# #
# Virtual Device Interface # Virtual Device Interface
# #
@ -206,3 +337,10 @@ class first_floor_east_living(room):
mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV, mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV,
self.powerplug_xmas_tree, devices.silvercrest_powerplug.KEY_OUTPUT_0 self.powerplug_xmas_tree, devices.silvercrest_powerplug.KEY_OUTPUT_0
) )
def all_off(self, device=None, key=None, data=None):
super().all_off(device, key, data)
self.floorlamp_tradfri.set_output_0(False)
if config.CHRISTMAS:
self.powerplug_xmas_tree.set_output_0(False)
self.powerplug_xmas_star.set_output_0(False)

View File

@ -4,10 +4,10 @@
import config import config
import devices import devices
import logging
from function.modules import heating_function from function.modules import heating_function
from function.rooms import room from function.rooms import room
from function.videv import videv_switch_brightness, videv_switch_brightness_color_temp, videv_heating from function.videv import videv_switch_brightness, videv_switch_brightness_color_temp, videv_heating
import logging
try: try:
@ -27,6 +27,18 @@ class first_floor_west_julian(room):
self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE) self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE)
super().__init__(mqtt_client) super().__init__(mqtt_client)
##### TEMPORARY ###################################################################################################################
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_enable_mcb)
self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_main_light.set_brightness_mcb)
self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_main_light.set_color_temp_mcb)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.main_light_tradfri.set_brightness_mcb)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.main_light_tradfri.set_color_temp_mcb)
##### TEMPORARY ###################################################################################################################
# #
# Virtual Device Interface # Virtual Device Interface
# #
@ -51,6 +63,36 @@ class first_floor_west_bath(room):
# heating function # heating function
self.heating_function = heating_function(self.heating_valve, config.DEFAULT_TEMPERATURE_FFW_BATH) self.heating_function = heating_function(self.heating_valve, config.DEFAULT_TEMPERATURE_FFW_BATH)
##### TEMPORARY ###################################################################################################################
self.gui_heating = devices.nodered_gui_radiator(mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_GUI)
self.heating_function.add_callback(heating_function.KEY_TEMPERATURE_CURRENT, None, self.gui_heating.set_temperature_mcb, True)
def set_heating_setpoint(device, key, data):
self.heating_function.set(heating_function.KEY_USER_TEMPERATURE_SETPOINT, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TEMP, None, set_heating_setpoint)
self.heating_function.add_callback(heating_function.KEY_TEMPERATURE_SETPOINT, None, self.gui_heating.set_setpoint_temperature_mcb, True)
def boost(device, key, data):
self.heating_function.set(heating_function.KEY_START_BOOST, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_BOOST, None, boost)
def setpoint_to_default(device, key, data):
self.heating_function.set(heating_function.KEY_SET_DEFAULT_TEMPERATURE, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TO_DEFAULT, None, setpoint_to_default)
def away_mode(device, key, data):
self.heating_function.set(heating_function.KEY_AWAY_MODE, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_AWAY, None, away_mode)
self.heating_function.add_callback(heating_function.KEY_AWAY_MODE, None, self.gui_heating.set_away_mcb)
def summer_mode(device, key, data):
self.heating_function.set(heating_function.KEY_SUMMER_MODE, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SUMMER, None, summer_mode)
self.heating_function.add_callback(heating_function.KEY_SUMMER_MODE, None, self.gui_heating.set_summer_mcb)
self.heating_function.add_callback(heating_function.KEY_BOOST_TIMER, None, self.gui_heating.set_timer_mcb)
##### TEMPORARY ###################################################################################################################
# #
# Virtual Device Interface # Virtual Device Interface
# #
@ -59,6 +101,9 @@ class first_floor_west_bath(room):
self.heating_function self.heating_function
) )
def all_off(self):
pass
class first_floor_west_living(room): class first_floor_west_living(room):
def __init__(self, mqtt_client): def __init__(self, mqtt_client):
@ -70,6 +115,18 @@ class first_floor_west_living(room):
self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE) self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE)
super().__init__(mqtt_client) super().__init__(mqtt_client)
##### TEMPORARY ###################################################################################################################
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_GUI)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_enable_mcb)
self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_main_light.set_brightness_mcb)
self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_main_light.set_color_temp_mcb)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.main_light_tradfri.set_brightness_mcb)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.main_light_tradfri.set_color_temp_mcb)
##### TEMPORARY ###################################################################################################################
# #
# Virtual Device Interface # Virtual Device Interface
# #
@ -91,6 +148,16 @@ class first_floor_west_sleep(room):
self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE) self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE)
super().__init__(mqtt_client) super().__init__(mqtt_client)
##### TEMPORARY ###################################################################################################################
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_GUI)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_enable_mcb)
self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_main_light.set_brightness_mcb)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.main_light_tradfri.set_brightness_mcb)
##### TEMPORARY ###################################################################################################################
# #
# Virtual Device Interface # Virtual Device Interface
# #

View File

@ -4,10 +4,10 @@
import config import config
import devices import devices
from function.modules import brightness_choose_n_action, heating_function, switched_light from function.modules import brightness_choose_n_action, heating_function
import logging
from function.rooms import room from function.rooms import room
from function.videv import videv_switching, videv_switch_brightness_color_temp, videv_heating, videv_multistate, videv_audio_player from function.videv import videv_switching, videv_switch_brightness_color_temp, videv_heating, videv_multistate, videv_audio_player
import logging
import task import task
try: try:
@ -34,7 +34,19 @@ class ground_floor_west_floor(room):
# Functionality initialisation # Functionality initialisation
# #
# Request silvercrest data of lead light after power on # Request silvercrest data of lead light after power on
switched_light(self.main_light_shelly, devices.shelly.KEY_OUTPUT_0, self.main_light_tradfri) self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.main_light_tradfri[0].request_data, True)
##### TEMPORARY ###################################################################################################################
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_GUI)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_enable_mcb)
self.main_light_tradfri[0].add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_main_light.set_brightness_mcb)
self.main_light_tradfri[0].add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_main_light.set_color_temp_mcb)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.main_light_tradfri.set_brightness_mcb)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.main_light_tradfri.set_color_temp_mcb)
##### TEMPORARY ###################################################################################################################
# #
# Virtual Device Interface # Virtual Device Interface
@ -63,6 +75,40 @@ class ground_floor_west_marion(room):
# heating function # heating function
self.heating_function = heating_function(self.heating_valve, config.DEFAULT_TEMPERATURE_GFW_MARION) self.heating_function = heating_function(self.heating_valve, config.DEFAULT_TEMPERATURE_GFW_MARION)
##### TEMPORARY ###################################################################################################################
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_GUI)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
self.gui_heating = devices.nodered_gui_radiator(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_GUI)
self.heating_function.add_callback(heating_function.KEY_TEMPERATURE_CURRENT, None, self.gui_heating.set_temperature_mcb, True)
def set_heating_setpoint(device, key, data):
self.heating_function.set(heating_function.KEY_USER_TEMPERATURE_SETPOINT, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TEMP, None, set_heating_setpoint)
self.heating_function.add_callback(heating_function.KEY_TEMPERATURE_SETPOINT, None, self.gui_heating.set_setpoint_temperature_mcb, True)
def boost(device, key, data):
self.heating_function.set(heating_function.KEY_START_BOOST, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_BOOST, None, boost)
def setpoint_to_default(device, key, data):
self.heating_function.set(heating_function.KEY_SET_DEFAULT_TEMPERATURE, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TO_DEFAULT, None, setpoint_to_default)
def away_mode(device, key, data):
self.heating_function.set(heating_function.KEY_AWAY_MODE, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_AWAY, None, away_mode)
self.heating_function.add_callback(heating_function.KEY_AWAY_MODE, None, self.gui_heating.set_away_mcb)
def summer_mode(device, key, data):
self.heating_function.set(heating_function.KEY_SUMMER_MODE, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SUMMER, None, summer_mode)
self.heating_function.add_callback(heating_function.KEY_SUMMER_MODE, None, self.gui_heating.set_summer_mcb)
self.heating_function.add_callback(heating_function.KEY_BOOST_TIMER, None, self.gui_heating.set_timer_mcb)
##### TEMPORARY ###################################################################################################################
# #
# Virtual Device Interface # Virtual Device Interface
# #
@ -82,6 +128,10 @@ class ground_floor_west_dirk(room):
STATE_ACTIVE_DEVICE_AMPLIFIER = 2 STATE_ACTIVE_DEVICE_AMPLIFIER = 2
STATE_ACTIVE_DEVICE_MAX_VALUE = STATE_ACTIVE_DEVICE_AMPLIFIER STATE_ACTIVE_DEVICE_MAX_VALUE = STATE_ACTIVE_DEVICE_AMPLIFIER
# #
LED_ACTIVE_DEVICE_MAIN_LIGHT = devices.nodered_gui_leds.KEY_LED_0
LED_ACTIVE_DEVICE_DESK_LIGHT = devices.nodered_gui_leds.KEY_LED_1
LED_ACTIVE_DEVICE_AMPLIFIER = devices.nodered_gui_leds.KEY_LED_2
#
KEY_POWERPLUG_AMPLIFIER = devices.my_powerplug.KEY_OUTPUT_0 KEY_POWERPLUG_AMPLIFIER = devices.my_powerplug.KEY_OUTPUT_0
KEY_POWERPLUG_CD_PLAYER = devices.my_powerplug.KEY_OUTPUT_2 KEY_POWERPLUG_CD_PLAYER = devices.my_powerplug.KEY_OUTPUT_2
KEY_POWERPLUG_DESK_LIGHT = devices.my_powerplug.KEY_OUTPUT_1 KEY_POWERPLUG_DESK_LIGHT = devices.my_powerplug.KEY_OUTPUT_1
@ -144,6 +194,71 @@ class ground_floor_west_dirk(room):
# heating function # heating function
self.heating_function = heating_function(self.heating_valve, config.DEFAULT_TEMPERATURE_GFW_DIRK) self.heating_function = heating_function(self.heating_valve, config.DEFAULT_TEMPERATURE_GFW_DIRK)
##### TEMPORARY ###################################################################################################################
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI)
self.gui_desk_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI)
self.gui_amplifier = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_GUI)
self.gui_cd_player = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_GUI)
self.gui_pc_dock = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_GUI)
# Callback initialisation
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_enable_mcb)
self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_main_light.set_brightness_mcb)
self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_main_light.set_color_temp_mcb)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.main_light_tradfri.set_brightness_mcb)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.main_light_tradfri.set_color_temp_mcb)
self.gui_desk_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.powerplug_common.set_output_1_mcb)
self.powerplug_common.add_callback(self.KEY_POWERPLUG_DESK_LIGHT, None, self.gui_desk_light.set_state_mcb)
self.gui_desk_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.desk_light_tradfri.set_brightness_mcb)
self.gui_desk_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.desk_light_tradfri.set_color_temp_mcb)
self.powerplug_common.add_callback(self.KEY_POWERPLUG_DESK_LIGHT, None, self.gui_desk_light.set_enable_mcb)
self.desk_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_desk_light.set_brightness_mcb)
self.desk_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_desk_light.set_color_temp_mcb)
self.gui_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_amplifier.set_state_mcb)
self.gui_cd_player.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_2_mcb)
self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.gui_cd_player.set_state_mcb)
self.gui_pc_dock.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_3_mcb)
self.powerplug_common.add_callback(self.KEY_POWERPLUG_PC_DOCK, None, self.gui_pc_dock.set_state_mcb)
self.gui_heating = devices.nodered_gui_radiator(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_GUI)
self.heating_function.add_callback(heating_function.KEY_TEMPERATURE_CURRENT, None, self.gui_heating.set_temperature_mcb, True)
def set_heating_setpoint(device, key, data):
self.heating_function.set(heating_function.KEY_USER_TEMPERATURE_SETPOINT, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TEMP, None, set_heating_setpoint)
self.heating_function.add_callback(heating_function.KEY_TEMPERATURE_SETPOINT, None, self.gui_heating.set_setpoint_temperature_mcb, True)
def boost(device, key, data):
self.heating_function.set(heating_function.KEY_START_BOOST, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_BOOST, None, boost)
def setpoint_to_default(device, key, data):
self.heating_function.set(heating_function.KEY_SET_DEFAULT_TEMPERATURE, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TO_DEFAULT, None, setpoint_to_default)
def away_mode(device, key, data):
self.heating_function.set(heating_function.KEY_AWAY_MODE, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_AWAY, None, away_mode)
self.heating_function.add_callback(heating_function.KEY_AWAY_MODE, None, self.gui_heating.set_away_mcb)
def summer_mode(device, key, data):
self.heating_function.set(heating_function.KEY_SUMMER_MODE, data)
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SUMMER, None, summer_mode)
self.heating_function.add_callback(heating_function.KEY_SUMMER_MODE, None, self.gui_heating.set_summer_mcb)
self.heating_function.add_callback(heating_function.KEY_BOOST_TIMER, None, self.gui_heating.set_timer_mcb)
self.gui_led_active_device = devices.nodered_gui_leds(mqtt_client, config.TOPIC_GFW_DIRK_DEVICE_CHOOSER_LED)
def update_active_device_led(device, key, data):
for i in range(0, len(self.brightness_functions.brightness_device_list)):
self.gui_led_active_device.set_led(devices.nodered_gui_leds.KEY_LED_LIST[i], data == i)
self.brightness_functions.add_callback(brightness_choose_n_action.KEY_ACTIVE_DEVICE, None, update_active_device_led, True)
##### TEMPORARY ###################################################################################################################
# #
# Virtual Device Interface # Virtual Device Interface
# #
@ -188,6 +303,10 @@ class ground_floor_west_dirk(room):
# #
self.delayed_task_remote = task.delayed(1.0, self.send_audio_source) self.delayed_task_remote = task.delayed(1.0, self.send_audio_source)
def all_off(self, device=None, key=None, data=None):
super().all_off(device, key, data)
self.powerplug_common.set_output_all(False)
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:
# switch on of cd player # switch on of cd player

View File

@ -25,11 +25,6 @@ except ImportError:
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
class switched_light(object):
def __init__(self, sw_device, sw_key, li_device):
sw_device.add_callback(devices.shelly.KEY_OUTPUT_0, True, li_device.request_data, True)
class brightness_choose_n_action(common_base): class brightness_choose_n_action(common_base):
KEY_ACTIVE_DEVICE = 'active_device' KEY_ACTIVE_DEVICE = 'active_device'
# #
@ -59,6 +54,8 @@ class brightness_choose_n_action(common_base):
callback_device: A device for installing callback which are executed, when the device is switched on or off. It needs the following method: callback_device: A device for installing callback which are executed, when the device is switched on or off. It needs the following method:
* .add_callback(key, data or None, callback, on_changes_only) * .add_callback(key, data or None, callback, on_changes_only)
""" """
if len(self.brightness_device_list) >= len(devices.nodered_gui_leds.KEY_LED_LIST):
raise ValueError("Number of devices is limited by number of leds in devices.nodered_gui_leds.")
self.brightness_device_list.append(brightness_device) self.brightness_device_list.append(brightness_device)
self.callback_device_list.append((callback_device, callback_key)) self.callback_device_list.append((callback_device, callback_key))
self.device_states.append(False) self.device_states.append(False)

View File

@ -36,6 +36,21 @@ class stairway(room):
timer_value=config.USER_ON_TIME_STAIRWAYS timer_value=config.USER_ON_TIME_STAIRWAYS
) )
##### TEMPORARY ###################################################################################################################
self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_GUI)
self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
self.motion_sensor_light.add_callback(motion_sensor_light.KEY_TIMER, None, self.gui_main_light.set_timer_mcb)
def set_led(device, key, data):
if key == motion_sensor_light.KEY_MOTION_SENSOR_0:
self.gui_main_light.set_led(devices.nodered_gui_light.KEY_LED_0, data)
if key == motion_sensor_light.KEY_MOTION_SENSOR_1:
self.gui_main_light.set_led(devices.nodered_gui_light.KEY_LED_1, data)
self.motion_sensor_light.add_callback(motion_sensor_light.KEY_MOTION_SENSOR_0, None, set_led)
self.motion_sensor_light.add_callback(motion_sensor_light.KEY_MOTION_SENSOR_1, None, set_led)
##### TEMPORARY ###################################################################################################################
# #
# Virtual Device Interface # Virtual Device Interface
# #

View File

@ -48,9 +48,7 @@ class base(mqtt_base):
# send default data to videv interface # send default data to videv interface
def __rx_ext_device_data__(self, ext_device, ext_key, data): def __rx_ext_device_data__(self, ext_device, ext_key, data):
my_key = self.__display_dict__[(id(ext_device), ext_key)] self.__tx__(self.__display_dict__[(id(ext_device), ext_key)], data)
self[my_key] = data
self.__tx__(my_key, data)
def __tx__(self, key, data): def __tx__(self, key, data):
if key in self.__control_dict__: if key in self.__control_dict__:

View File

@ -13,7 +13,7 @@ if __name__ == "__main__":
mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER, mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
password=config.MQTT_PASSWORD, name=config.APP_NAME + '_simulation') password=config.MQTT_PASSWORD, name=config.APP_NAME + '_simulation')
# #
COMMANDS = ['quit', 'help'] COMMANDS = ['quit', 'help', 'test.smoke', 'test.full']
# #
h = house(mc) h = house(mc)
for name in h.getmembers(): for name in h.getmembers():
@ -22,10 +22,6 @@ if __name__ == "__main__":
COMMANDS.append(name + '.' + c) COMMANDS.append(name + '.' + c)
# #
ts = test_smarthome(h) ts = test_smarthome(h)
for name in ts.getmembers():
d = ts.getobjbyname(name)
for c in d.capabilities():
COMMANDS.append('test.' + name + '.' + c)
def reduced_list(text): def reduced_list(text):
""" """
@ -72,8 +68,8 @@ if __name__ == "__main__":
break break
elif userfeedback == 'help': elif userfeedback == 'help':
print("Help is not yet implemented!") print("Help is not yet implemented!")
elif userfeedback.startswith("test"): elif userfeedback == 'test.full':
ts.command(userfeedback) ts.full()
elif userfeedback == 'test.smoke': elif userfeedback == 'test.smoke':
ts.smoke() ts.smoke()
elif command in COMMANDS[2:]: elif command in COMMANDS[2:]:

View File

@ -7,19 +7,11 @@ import time
logger = logging.getLogger(config.APP_NAME) logger = logging.getLogger(config.APP_NAME)
# TODO: Extend virtual devices and implement all_off functionality in function.all_functions.init_off_functionality # TODO: Change Nodered topics to videv
# TODO: Extend virtual devices
# * All Off # * All Off
# * ... # * ...
# TODO: Restructure nodered gui (own heating page - with circulation pump) # TODO: Remove gui from rooms and devices
# TODO: Extend tests in simulation
# - Synch functions (ffe.livingroom.floorlamp [with main_light and 1-6], ffe.diningroom/floorlamp, ffe.dirk.amplifier (with spotify, mpd, cd_player), gfw.floor.main_light)
# - Remote actions after amplifier on
# - Switching button functions (gfw_dirk, ffe.sleep)
# - Heating functionality (base: set temp, set default, away_mode, summer_mode, start and stop boost)
# - Brightness button functions (gfw.dirk, ffe.sleep)
# - Motion stairways (incl. sensor feedback)
# - Heating functionality (extended: timer)
# - Timer (circulation and stairways)
# TODO: Rework devices to base.mqtt (pack -> set, ...) # TODO: Rework devices to base.mqtt (pack -> set, ...)
# TODO: Implement handling of warnings (videv element to show in webapp?) # TODO: Implement handling of warnings (videv element to show in webapp?)