|
@@ -1,19 +1,170 @@
|
1
|
1
|
#!/usr/bin/env python
|
2
|
2
|
# -*- coding: utf-8 -*-
|
3
|
3
|
#
|
|
4
|
+import config
|
|
5
|
+import devices
|
|
6
|
+import inspect
|
4
|
7
|
import logging
|
5
|
8
|
|
6
|
|
-__all__ = ['all_functions', 'first_floor_dining']
|
7
|
|
-
|
8
|
|
-from . import first_floor_dining
|
9
|
|
-
|
10
|
9
|
try:
|
11
|
10
|
from config import APP_NAME as ROOT_LOGGER_NAME
|
12
|
11
|
except ImportError:
|
13
|
12
|
ROOT_LOGGER_NAME = 'root'
|
14
|
13
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
15
|
14
|
|
|
15
|
+# TODO: Add brightness and color temp including disable of gui elements.
|
|
16
|
+# TODO: Add lamp sleep_di
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+class room(object):
|
|
20
|
+ def gui_switch_feedback(self, device, key, data):
|
|
21
|
+ self.gui_switch_main_light.set_feedback(data)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+class room_shelly(room):
|
|
25
|
+ def __init__(self, mqtt_client, topic_shelly, topic_gui_switch):
|
|
26
|
+ self.main_light_shelly = devices.shelly(mqtt_client, topic=topic_shelly)
|
|
27
|
+ #
|
|
28
|
+ self.gui_switch_main_light = devices.nodered_gui(mqtt_client, topic=topic_gui_switch)
|
|
29
|
+ #
|
|
30
|
+ # Callback initialisation
|
|
31
|
+ #
|
|
32
|
+ self.gui_switch_main_light.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command)
|
|
33
|
+ self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_switch_feedback)
|
|
34
|
+
|
|
35
|
+ def all_off(self):
|
|
36
|
+ self.main_light_shelly.set_output_0(False)
|
|
37
|
+ self.main_light_shelly.set_output_1(False)
|
|
38
|
+
|
|
39
|
+ def gui_switch_command(self, device, key, data):
|
|
40
|
+ logger.info("Switching \"%s\" main light: %s", type(self).__name__, str(data))
|
|
41
|
+ self.main_light_shelly.set_output_0(data)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+class first_floor_east_floor(room_shelly):
|
|
45
|
+ def __init__(self, mqtt_client):
|
|
46
|
+ # http://shelly1l-3C6105E4E629
|
|
47
|
+ super().__init__(mqtt_client, "shellies/floor_madi", "gui/ffe_floor")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+class first_floor_east_kitchen(room_shelly):
|
|
51
|
+ # TODO: add circulation pump (switch, time)
|
|
52
|
+ def __init__(self, mqtt_client):
|
|
53
|
+ # http://shelly1l-8CAAB5616C01
|
|
54
|
+ super().__init__(mqtt_client, "shellies/kitchen", "gui/ffe_kitchen")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+class first_floor_east_dining(room_shelly):
|
|
58
|
+ def __init__(self, mqtt_client):
|
|
59
|
+ # http://shelly1l-84CCA8ADD055
|
|
60
|
+ super().__init__(mqtt_client, "shellies/diningroom", "gui/ffe_diningroom")
|
|
61
|
+ self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, "zigbee_og_e/powerplug/dining_floorlamp")
|
|
62
|
+ if config.CHRISTMAS:
|
|
63
|
+ self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, topic="zigbee_og_e/powerplug/aux")
|
|
64
|
+ #
|
|
65
|
+ self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_dining_floorlamp")
|
|
66
|
+ #
|
|
67
|
+ # Callback initialisation
|
|
68
|
+ #
|
|
69
|
+ self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation)
|
|
70
|
+ self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp)
|
|
71
|
+ self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0,
|
|
72
|
+ None, self.gui_switch_feedback_floorlamp)
|
|
73
|
+ #
|
|
74
|
+ self.main_light_shelly_last = None
|
|
75
|
+
|
|
76
|
+ def floorlamp_synchronisation(self, device, key, data):
|
|
77
|
+ if data != self.main_light_shelly_last:
|
|
78
|
+ logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
|
|
79
|
+ self.floorlamp_powerplug.set_output_0(data)
|
|
80
|
+ self.main_light_shelly_last = data
|
|
81
|
+
|
|
82
|
+ def gui_switch_command_floorlamp(self, device, key, data):
|
|
83
|
+ logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data))
|
|
84
|
+ self.floorlamp_powerplug.set_output_0(data)
|
|
85
|
+
|
|
86
|
+ def gui_switch_feedback_floorlamp(self, device, key, data):
|
|
87
|
+ self.gui_switch_floorlamp.set_feedback(data)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+class first_floor_east_sleep_madi(room_shelly):
|
|
91
|
+ def __init__(self, mqtt_client):
|
|
92
|
+ # http://shelly1l-E8DB84A254C7
|
|
93
|
+ super().__init__(mqtt_client, "shellies/sleep_madi", "gui/ffe_sleep_madi")
|
|
94
|
+ self.main_light_tradfri = devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/sleep_madi")
|
|
95
|
+ self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/sleep_bed_di")
|
|
96
|
+ self.button_tradfri = devices.tradfri_button(mqtt_client, topic="zigbee_og_e/input_device/og_east")
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+class first_floor_east_living(room_shelly):
|
|
100
|
+ def __init__(self, mqtt_client):
|
|
101
|
+ # http://shelly1l-3C6105E3F910
|
|
102
|
+ super().__init__(mqtt_client, "shellies/livingroom", "gui/ffe_livingroom")
|
|
103
|
+ self.main_light_tradfri = devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/livingroom")
|
|
104
|
+ for i in range(1, 7):
|
|
105
|
+ setattr(self, 'floorlamp_tradfri_%d' % i,
|
|
106
|
+ devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/living_floorlamp_%d" % i))
|
|
107
|
+ #
|
|
108
|
+ self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_living_floorlamp")
|
|
109
|
+ #
|
|
110
|
+ # Callback initialisation
|
|
111
|
+ #
|
|
112
|
+ self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation)
|
|
113
|
+ self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp)
|
|
114
|
+ self.floorlamp_tradfri_1.add_callback(devices.tradfri_light.KEY_OUTPUT_0,
|
|
115
|
+ None, self.gui_switch_feedback_floorlamp)
|
|
116
|
+ #
|
|
117
|
+ self.main_light_shelly_last = None
|
|
118
|
+
|
|
119
|
+ def __floorlamp_devices__(self):
|
|
120
|
+ rv = []
|
|
121
|
+ for i in range(1, 7):
|
|
122
|
+ rv.append(getattr(self, 'floorlamp_tradfri_%d' % i))
|
|
123
|
+ return rv
|
|
124
|
+
|
|
125
|
+ def floorlamp_synchronisation(self, device, key, data):
|
|
126
|
+ if data != self.main_light_shelly_last:
|
|
127
|
+ logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
|
|
128
|
+ for device in self.__floorlamp_devices__():
|
|
129
|
+ device.set_output_0(data)
|
|
130
|
+ self.main_light_shelly_last = data
|
|
131
|
+
|
|
132
|
+ def gui_switch_command_floorlamp(self, device, key, data):
|
|
133
|
+ logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data))
|
|
134
|
+ for device in self.__floorlamp_devices__():
|
|
135
|
+ device.set_output_0(data)
|
|
136
|
+
|
|
137
|
+ def gui_switch_feedback_floorlamp(self, device, key, data):
|
|
138
|
+ self.gui_switch_floorlamp.set_feedback(data)
|
|
139
|
+
|
16
|
140
|
|
17
|
141
|
class all_functions(object):
|
18
|
|
- def __init__(self, device_collection):
|
19
|
|
- first_floor_dining.room_function(device_collection)
|
|
142
|
+ def __init__(self, mqtt_client):
|
|
143
|
+ self.rooms = {}
|
|
144
|
+ self.__devices__ = None
|
|
145
|
+ #
|
|
146
|
+ # first floor east
|
|
147
|
+ #
|
|
148
|
+ self.ffe_floor = first_floor_east_floor(mqtt_client)
|
|
149
|
+ self.ffe_kitchen = first_floor_east_kitchen(mqtt_client)
|
|
150
|
+ self.ffe_dining = first_floor_east_dining(mqtt_client)
|
|
151
|
+ self.ffe_sleep_madi = first_floor_east_sleep_madi(mqtt_client)
|
|
152
|
+ self.ffe_living = first_floor_east_living(mqtt_client)
|
|
153
|
+
|
|
154
|
+ def ffe_off(self):
|
|
155
|
+ self.ffe_floor.off()
|
|
156
|
+ self.ffe_kitchen.off()
|
|
157
|
+ self.ffe_dining.off()
|
|
158
|
+ self.ffe_sleep_madi.off()
|
|
159
|
+ self.ffe_living.off()
|
|
160
|
+
|
|
161
|
+ def devicelist(self):
|
|
162
|
+ raise Exception
|
|
163
|
+ # TODO: generate list by using getattr
|
|
164
|
+ if self.__devices__ is None:
|
|
165
|
+ self.__devices__ = []
|
|
166
|
+ for room in self.rooms:
|
|
167
|
+ for name, obj in inspect.getmembers(room):
|
|
168
|
+ if type(obj) in devices.DEVICE_TYPE_LIST():
|
|
169
|
+ self.__devices__.append(obj)
|
|
170
|
+ return self.__devices__
|