Browse Source

Integration of module devdi

tags/v1.3.0
Dirk Alders 1 year ago
parent
commit
6e9bc517a3

+ 3
- 0
.gitmodules View File

@@ -10,3 +10,6 @@
10 10
 [submodule "geo"]
11 11
 	path = geo
12 12
 	url = https://git.mount-mockery.de/pylib/geo.git
13
+[submodule "devdi"]
14
+	path = devdi
15
+	url = https://git.mount-mockery.de/smarthome/smart_devdi.git

+ 2
- 3
.vscode/settings.json View File

@@ -1,12 +1,11 @@
1 1
 {
2 2
   "python.defaultInterpreterPath": "./venv/bin/python",
3 3
   "autopep8.args": ["--max-line-length=150"],
4
-  "python.formatting.provider": "none",
5 4
   "[python]": {
6
-    "editor.defaultFormatter": "ms-python.python",
5
+    "python.formatting.provider": "none",
6
+    "editor.defaultFormatter": "ms-python.autopep8",
7 7
     "editor.formatOnSave": true
8 8
   },
9
-  "editor.formatOnSave": true,
10 9
   "editor.fontSize": 14,
11 10
   "emmet.includeLanguages": { "django-html": "html" },
12 11
   "python.testing.pytestArgs": ["-v", "--cov", "--cov-report=xml", "__test__"],

+ 1
- 0
devdi

@@ -0,0 +1 @@
1
+Subproject commit 773d0a6679810b365bbd4537156c513b0f496c5a

+ 44
- 933
devices/__init__.py
File diff suppressed because it is too large
View File


+ 104
- 0
devices/base.py View File

@@ -0,0 +1,104 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+from base import mqtt_base
5
+from base import videv_base
6
+import json
7
+
8
+BATTERY_WARN_LEVEL = 10
9
+
10
+
11
+def is_json(data):
12
+    try:
13
+        json.loads(data)
14
+    except json.decoder.JSONDecodeError:
15
+        return False
16
+    else:
17
+        return True
18
+
19
+
20
+class base(mqtt_base):
21
+    TX_TOPIC = "set"
22
+    TX_VALUE = 0
23
+    TX_DICT = 1
24
+    TX_TYPE = -1
25
+    TX_FILTER_DATA_KEYS = []
26
+    #
27
+    RX_KEYS = []
28
+    RX_IGNORE_TOPICS = []
29
+    RX_IGNORE_KEYS = []
30
+    RX_FILTER_DATA_KEYS = []
31
+    #
32
+    KEY_WARNING = '__WARNING__'
33
+
34
+    def __init__(self, mqtt_client, topic):
35
+        super().__init__(mqtt_client, topic, default_values=dict.fromkeys(self.RX_KEYS + [self.KEY_WARNING]))
36
+        # data storage
37
+        # initialisations
38
+        mqtt_client.add_callback(topic=self.topic, callback=self.receive_callback)
39
+        mqtt_client.add_callback(topic=self.topic+"/#", callback=self.receive_callback)
40
+
41
+    def set(self, key, data, block_callback=[]):
42
+        if key in self.RX_IGNORE_KEYS:
43
+            pass    # ignore these keys
44
+        elif key in self.RX_KEYS or key == self.KEY_WARNING:
45
+            return super().set(key, data, block_callback)
46
+        else:
47
+            self.logger.warning("Unexpected key %s", key)
48
+
49
+    def receive_callback(self, client, userdata, message):
50
+        if message.topic != self.topic + '/' + videv_base.KEY_INFO:
51
+            content_key = message.topic[len(self.topic) + 1:]
52
+            if content_key not in self.RX_IGNORE_TOPICS and (not message.topic.endswith(self.TX_TOPIC) or len(self.TX_TOPIC) == 0):
53
+                self.logger.debug("Unpacking content_key \"%s\" from message.", content_key)
54
+                if is_json(message.payload):
55
+                    data = json.loads(message.payload)
56
+                    if type(data) is dict:
57
+                        for key in data:
58
+                            self.set(key, self.__device_to_instance_filter__(key, data[key]))
59
+                    else:
60
+                        self.set(content_key, self.__device_to_instance_filter__(content_key, data))
61
+                # String
62
+                else:
63
+                    self.set(content_key, self.__device_to_instance_filter__(content_key, message.payload.decode('utf-8')))
64
+            else:
65
+                self.logger.debug("Ignoring topic %s", content_key)
66
+
67
+    def __device_to_instance_filter__(self, key, data):
68
+        if key in self.RX_FILTER_DATA_KEYS:
69
+            if data in [1, 'on', 'ON']:
70
+                return True
71
+            elif data in [0, 'off', 'OFF']:
72
+                return False
73
+        return data
74
+
75
+    def __instance_to_device_filter__(self, key, data):
76
+        if key in self.TX_FILTER_DATA_KEYS:
77
+            if data is True:
78
+                return "on"
79
+            elif data is False:
80
+                return "off"
81
+        return data
82
+
83
+    def send_command(self, key, data):
84
+        data = self.__instance_to_device_filter__(key, data)
85
+        if self.TX_TOPIC is not None:
86
+            if self.TX_TYPE < 0:
87
+                self.logger.error("Unknown tx type. Set TX_TYPE of class to a known value")
88
+            else:
89
+                self.logger.debug("Sending data for %s - %s", key, str(data))
90
+                if self.TX_TYPE == self.TX_DICT:
91
+                    try:
92
+                        self.mqtt_client.send('/'.join([self.topic, self.TX_TOPIC]), json.dumps({key: data}))
93
+                    except TypeError:
94
+                        print(self.topic)
95
+                        print(key.__dict__)
96
+                        print(key)
97
+                        print(data)
98
+                        raise TypeError
99
+                else:
100
+                    if type(data) not in [str, bytes]:
101
+                        data = json.dumps(data)
102
+                    self.mqtt_client.send('/'.join([self.topic, key, self.TX_TOPIC] if len(self.TX_TOPIC) > 0 else [self.topic, key]), data)
103
+        else:
104
+            self.logger.error("Unknown tx toptic. Set TX_TOPIC of class to a known value")

+ 95
- 0
devices/brennenstuhl.py View File

@@ -0,0 +1,95 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+from devices.base import base
5
+from devices.base import BATTERY_WARN_LEVEL
6
+import json
7
+
8
+
9
+class brennenstuhl_heatingvalve(base):
10
+    """ Communication (MQTT)
11
+
12
+        brennenstuhl_heatingvalve {
13
+                                |      "away_mode": ["ON", "OFF"]
14
+                                |      "battery": [0...100] %
15
+                                |      "child_lock": ["LOCK", "UNLOCK"]
16
+                                |      "current_heating_setpoint": [5...30] °C
17
+                                |      "linkquality": [0...255] lqi
18
+                                |      "local_temperature": [numeric] °C
19
+                                |      "preset": ["manual", ...]
20
+                                |      "system_mode": ["heat", ...]
21
+                                |      "valve_detection": ["ON", "OFF"]
22
+                                |      "window_detection": ["ON", "OFF"]
23
+                                | }
24
+                                +- set {
25
+                                           "away_mode": ["ON", "OFF", "TOGGLE"]
26
+                                           "child_lock": ["LOCK", "UNLOCK"]
27
+                                           "current_heating_setpoint": [5...30] °C
28
+                                           "preset": ["manual", ...]
29
+                                           "system_mode": ["heat", ...]
30
+                                           "valve_detection": ["ON", "OFF", "TOGGLE"]
31
+                                           "window_detection": ["ON", "OFF", "TOGGLE"]
32
+                                       }
33
+    """
34
+    KEY_LINKQUALITY = "linkquality"
35
+    KEY_BATTERY = "battery"
36
+    KEY_HEATING_SETPOINT = "current_heating_setpoint"
37
+    KEY_TEMPERATURE = "local_temperature"
38
+    #
39
+    KEY_AWAY_MODE = "away_mode"
40
+    KEY_CHILD_LOCK = "child_lock"
41
+    KEY_PRESET = "preset"
42
+    KEY_SYSTEM_MODE = "system_mode"
43
+    KEY_VALVE_DETECTION = "valve_detection"
44
+    KEY_WINDOW_DETECTION = "window_detection"
45
+    #
46
+    TX_TYPE = base.TX_DICT
47
+    #
48
+    RX_KEYS = [KEY_LINKQUALITY, KEY_BATTERY, KEY_HEATING_SETPOINT, KEY_TEMPERATURE]
49
+    RX_IGNORE_KEYS = [KEY_AWAY_MODE, KEY_CHILD_LOCK, KEY_PRESET, KEY_SYSTEM_MODE, KEY_VALVE_DETECTION, KEY_WINDOW_DETECTION]
50
+
51
+    def __init__(self, mqtt_client, topic):
52
+        super().__init__(mqtt_client, topic)
53
+        self.mqtt_client.send(self.topic + '/' + self.TX_TOPIC, json.dumps({self.KEY_WINDOW_DETECTION: "ON",
54
+                              self.KEY_CHILD_LOCK: "UNLOCK", self.KEY_VALVE_DETECTION: "ON", self.KEY_SYSTEM_MODE: "heat", self.KEY_PRESET: "manual"}))
55
+        #
56
+        self.add_callback(self.KEY_BATTERY, None, self.__warning__, True)
57
+        self.__battery_warning__ = False
58
+
59
+    #
60
+    # WARNING CALL
61
+    #
62
+    def __warning__(self, client, key, data):
63
+        if data <= BATTERY_WARN_LEVEL:
64
+            if not self.__battery_warning__:
65
+                self.__battery_warning__ = True
66
+                w = warning(self.topic, warning.TYPE_BATTERY_LOW, "Battery low (%.1f%%)", data)
67
+                self.logger.warning(w)
68
+                self.set(self.KEY_WARNING, w)
69
+        else:
70
+            self.__battery_warning__ = False
71
+
72
+    #
73
+    # RX
74
+    #
75
+    @property
76
+    def linkqulity(self):
77
+        return self.get(self.KEY_LINKQUALITY)
78
+
79
+    @property
80
+    def heating_setpoint(self):
81
+        return self.get(self.KEY_HEATING_SETPOINT)
82
+
83
+    @property
84
+    def temperature(self):
85
+        return self.get(self.KEY_TEMPERATURE)
86
+
87
+    #
88
+    # TX
89
+    #
90
+    def set_heating_setpoint(self, setpoint):
91
+        self.send_command(self.KEY_HEATING_SETPOINT, setpoint)
92
+
93
+    def set_heating_setpoint_mcb(self, device, key, data):
94
+        self.logger.info("Changing heating setpoint to %s", str(data))
95
+        self.set_heating_setpoint(data)

+ 247
- 0
devices/mydevices.py View File

@@ -0,0 +1,247 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+from devices.base import base
5
+import logging
6
+
7
+
8
+class powerplug(base):
9
+    """ Communication (MQTT)
10
+
11
+        my_powerplug
12
+                   +- output
13
+                           +- 1 [True, False]                   <- status
14
+                           |  +- set [True, False, "toggle"]    <- command
15
+                           +- 2 [True, False]                   <- status
16
+                           |  +- set [True, False, "toggle"]    <- command
17
+                           +- 3 [True, False]                   <- status
18
+                           |  +- set [True, False, "toggle"]    <- command
19
+                           +- 4 [True, False]                   <- status
20
+                           |  +- set [True, False, "toggle"]    <- command
21
+                           +- all
22
+                              +- set [True, False, "toggle"]    <- command
23
+    """
24
+    KEY_OUTPUT_0 = "output/1"
25
+    KEY_OUTPUT_1 = "output/2"
26
+    KEY_OUTPUT_2 = "output/3"
27
+    KEY_OUTPUT_3 = "output/4"
28
+    KEY_OUTPUT_ALL = "output/all"
29
+    KEY_OUTPUT_LIST = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_OUTPUT_3]
30
+    #
31
+    TX_TYPE = base.TX_VALUE
32
+    #
33
+    RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_OUTPUT_3]
34
+
35
+    def __init__(self, mqtt_client, topic):
36
+        super().__init__(mqtt_client, topic)
37
+
38
+    #
39
+    # RX
40
+    #
41
+    @property
42
+    def output_0(self):
43
+        """rv: [True, False]"""
44
+        return self.get(self.KEY_OUTPUT_0)
45
+
46
+    @property
47
+    def output_1(self):
48
+        """rv: [True, False]"""
49
+        return self.get(self.KEY_OUTPUT_1)
50
+
51
+    @property
52
+    def output_2(self):
53
+        """rv: [True, False]"""
54
+        return self.get(self.KEY_OUTPUT_2)
55
+
56
+    @property
57
+    def output_3(self):
58
+        """rv: [True, False]"""
59
+        return self.get(self.KEY_OUTPUT_3)
60
+
61
+    #
62
+    # TX
63
+    #
64
+    def set_output(self, key, state):
65
+        if key in self.KEY_OUTPUT_LIST:
66
+            self.send_command(key, state)
67
+        else:
68
+            logging.error("Unknown key to set the output!")
69
+
70
+    def set_output_0(self, state):
71
+        """state: [True, False]"""
72
+        self.send_command(self.KEY_OUTPUT_0, state)
73
+
74
+    def set_output_0_mcb(self, device, key, data):
75
+        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
76
+        self.set_output_0(data)
77
+
78
+    def toggle_output_0_mcb(self, device, key, data):
79
+        self.logger.info("Toggeling output 0")
80
+        self.set_output_0(not self.output_0)
81
+
82
+    def set_output_1(self, state):
83
+        """state: [True, False]"""
84
+        self.send_command(self.KEY_OUTPUT_1, state)
85
+
86
+    def set_output_1_mcb(self, device, key, data):
87
+        self.logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "Changing output 1 to %s", str(data))
88
+        self.set_output_1(data)
89
+
90
+    def toggle_output_1_mcb(self, device, key, data):
91
+        self.logger.info("Toggeling output 1")
92
+        self.set_output_1(not self.output_1)
93
+
94
+    def set_output_2(self, state):
95
+        """state: [True, False]"""
96
+        self.send_command(self.KEY_OUTPUT_2, state)
97
+
98
+    def set_output_2_mcb(self, device, key, data):
99
+        self.logger.log(logging.INFO if data != self.output_2 else logging.DEBUG, "Changing output 2 to %s", str(data))
100
+        self.set_output_2(data)
101
+
102
+    def toggle_output_2_mcb(self, device, key, data):
103
+        self.logger.info("Toggeling output 2")
104
+        self.set_output_2(not self.output_2)
105
+
106
+    def set_output_3(self, state):
107
+        """state: [True, False]"""
108
+        self.send_command(self.KEY_OUTPUT_3, state)
109
+
110
+    def set_output_3_mcb(self, device, key, data):
111
+        self.logger.log(logging.INFO if data != self.output_3 else logging.DEBUG, "Changing output 3 to %s", str(data))
112
+        self.set_output_3(data)
113
+
114
+    def toggle_output_3_mcb(self, device, key, data):
115
+        self.logger.info("Toggeling output 3")
116
+        self.set_output_3(not self.output_3)
117
+
118
+    def set_output_all(self, state):
119
+        """state: [True, False, 'toggle']"""
120
+        self.send_command(self.KEY_OUTPUT_ALL, state)
121
+
122
+    def set_output_all_mcb(self, device, key, data):
123
+        self.logger.info("Changing all outputs to %s", str(data))
124
+        self.set_output_all(data)
125
+
126
+    def all_off(self):
127
+        self.set_output_all(False)
128
+
129
+
130
+class remote(base):
131
+    """ Communication (MQTT)
132
+
133
+        remote (RAS5)                               <- command
134
+             +- CD [dc]
135
+             +- LINE1 [dc]
136
+             +- LINE2 [dc]
137
+             +- LINE3 [dc]
138
+             +- MUTE [dc]
139
+             +- POWER [dc]
140
+             +- VOLDOWN [dc]
141
+             +- VOLUP [dc]
142
+             +- PHONO [dc]
143
+             +- DOCK [dc]
144
+
145
+        remote (EUR642100)                          <- command
146
+             +- OPEN_CLOSE [dc]
147
+             +- VOLDOWN [dc]
148
+             +- VOLUP [dc]
149
+             +- ONE [dc]
150
+             +- TWO [dc]
151
+             +- THREE [dc]
152
+             +- FOUR [dc]
153
+             +- FIVE [dc]
154
+             +- SIX [dc]
155
+             +- SEVEN [dc]
156
+             +- EIGHT [dc]
157
+             +- NINE [dc]
158
+             +- ZERO [dc]
159
+             +- TEN [dc]
160
+             +- TEN_PLUS [dc]
161
+             +- PROGRAM [dc]
162
+             +- CLEAR [dc]
163
+             +- RECALL [dc]
164
+             +- TIME_MODE [dc]
165
+             +- A_B_REPEAT [dc]
166
+             +- REPEAT [dc]
167
+             +- RANDOM [dc]
168
+             +- AUTO_CUE [dc]
169
+             +- TAPE_LENGTH [dc]
170
+             +- SIDE_A_B [dc]
171
+             +- TIME_FADE [dc]
172
+             +- PEAK_SEARCH [dc]
173
+             +- SEARCH_BACK [dc]
174
+             +- SEARCH_FOR [dc]
175
+             +- TRACK_NEXT [dc]
176
+             +- TRACK_PREV [dc]
177
+             +- STOP [dc]
178
+             +- PAUSE [dc]
179
+             +- PLAY [dc]
180
+    """
181
+    KEY_CD = "CD"
182
+    KEY_LINE1 = "LINE1"
183
+    KEY_LINE3 = "LINE3"
184
+    KEY_MUTE = "MUTE"
185
+    KEY_POWER = "POWER"
186
+    KEY_VOLDOWN = "VOLDOWN"
187
+    KEY_VOLUP = "VOLUP"
188
+    #
189
+    TX_TOPIC = ''
190
+    TX_TYPE = base.TX_VALUE
191
+    #
192
+    RX_IGNORE_TOPICS = [KEY_CD, KEY_LINE1, KEY_LINE3, KEY_MUTE, KEY_POWER, KEY_VOLUP, KEY_VOLDOWN]
193
+
194
+    def set_cd(self, device=None, key=None, data=None):
195
+        self.send_command(self.KEY_CD, None)
196
+
197
+    def set_line1(self, device=None, key=None, data=None):
198
+        self.send_command(self.KEY_LINE1, None)
199
+
200
+    def set_line3(self, device=None, key=None, data=None):
201
+        self.send_command(self.KEY_LINE3, None)
202
+
203
+    def set_mute(self, device=None, key=None, data=None):
204
+        self.send_command(self.KEY_MUTE, None)
205
+
206
+    def set_power(self, device=None, key=None, data=None):
207
+        self.send_command(self.KEY_POWER, None)
208
+
209
+    def set_volume_up(self, data=False):
210
+        """data: [True, False]"""
211
+        self.send_command(self.KEY_VOLUP, data)
212
+
213
+    def set_volume_down(self, data=False):
214
+        """data: [True, False]"""
215
+        self.send_command(self.KEY_VOLDOWN, data)
216
+
217
+    def default_inc(self, device=None, key=None, data=None):
218
+        self.set_volume_up(True)
219
+
220
+    def default_dec(self, device=None, key=None, data=None):
221
+        self.set_volume_down(True)
222
+
223
+    def default_stop(self, device=None, key=None, data=None):
224
+        self.set_volume_up(False)
225
+
226
+
227
+class audio_status(base):
228
+    """ Communication (MQTT)
229
+
230
+        audio_status
231
+            +- state [True, False]                  <- status
232
+            +- title [text]                         <- status
233
+    """
234
+    KEY_STATE = "state"
235
+    KEY_TITLE = "title"
236
+    #
237
+    TX_TYPE = base.TX_VALUE
238
+    #
239
+    RX_KEYS = [KEY_STATE, KEY_TITLE]
240
+
241
+    def set_state(self, num, data):
242
+        """data: [True, False]"""
243
+        self.send_command(self.KEY_STATE + "/" + str(num), data)
244
+
245
+    def set_state_mcb(self, device, key, data):
246
+        self.logger.info("Changing state to %s", str(data))
247
+        self.set_state(data)

+ 179
- 0
devices/shelly.py View File

@@ -0,0 +1,179 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+from devices.base import base
5
+import logging
6
+import task
7
+
8
+
9
+class shelly(base):
10
+    """ Communication (MQTT)
11
+
12
+        shelly
13
+            +- relay
14
+            |      +- 0 ["on" / "off"]              <- status 
15
+            |      |  +- command ["on"/ "off"]      <- command
16
+            |      |  +- energy [numeric]           <- status
17
+            |      +- 1 ["on" / "off"]              <- status
18
+            |         +- command ["on"/ "off"]      <- command
19
+            |         +- energy [numeric]           <- status
20
+            +- input
21
+            |      +- 0 [0 / 1]                     <- status
22
+            |      +- 1 [0 / 1]                     <- status
23
+            +- input_event
24
+            |      +- 0                             <- status
25
+            |      +- 1                             <- status
26
+            +- logpush
27
+            |      +- 0 [0 / 1]                     <- status
28
+            |      +- 1 [0 / 1]                     <- status
29
+            +- temperature [numeric] °C             <- status
30
+            +- temperature_f [numeric] F            <- status
31
+            +- overtemperature [0 / 1]              <- status
32
+            +- id                                   <- status
33
+            +- model                                <- status
34
+            +- mac                                  <- status
35
+            +- ip                                   <- status
36
+            +- new_fw                               <- status
37
+            +- fw_ver                               <- status
38
+    """
39
+    KEY_OUTPUT_0 = "relay/0"
40
+    KEY_OUTPUT_1 = "relay/1"
41
+    KEY_INPUT_0 = "input/0"
42
+    KEY_INPUT_1 = "input/1"
43
+    KEY_LONGPUSH_0 = "longpush/0"
44
+    KEY_LONGPUSH_1 = "longpush/1"
45
+    KEY_TEMPERATURE = "temperature"
46
+    KEY_OVERTEMPERATURE = "overtemperature"
47
+    KEY_ID = "id"
48
+    KEY_MODEL = "model"
49
+    KEY_MAC = "mac"
50
+    KEY_IP = "ip"
51
+    KEY_NEW_FIRMWARE = "new_fw"
52
+    KEY_FIRMWARE_VERSION = "fw_ver"
53
+    #
54
+    TX_TOPIC = "command"
55
+    TX_TYPE = base.TX_VALUE
56
+    TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1]
57
+    #
58
+    RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_INPUT_0, KEY_INPUT_1, KEY_LONGPUSH_0, KEY_LONGPUSH_1, KEY_OVERTEMPERATURE, KEY_TEMPERATURE,
59
+               KEY_ID, KEY_MODEL, KEY_MAC, KEY_IP, KEY_NEW_FIRMWARE, KEY_FIRMWARE_VERSION]
60
+    RX_IGNORE_TOPICS = [KEY_OUTPUT_0 + '/' + "energy", KEY_OUTPUT_1 + '/' + "energy", 'input_event/0', 'input_event/1']
61
+    RX_IGNORE_KEYS = ['temperature_f']
62
+    RX_FILTER_DATA_KEYS = [KEY_INPUT_0, KEY_INPUT_1, KEY_LONGPUSH_0, KEY_LONGPUSH_1, KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OVERTEMPERATURE]
63
+
64
+    def __init__(self, mqtt_client, topic):
65
+        super().__init__(mqtt_client, topic)
66
+        #
67
+        self.output_key_delayed = None
68
+        self.delayed_flash_task = task.delayed(0.3, self.flash_task)
69
+        self.delayed_off_task = task.delayed(0.3, self.off_task)
70
+        #
71
+        self.add_callback(self.KEY_OVERTEMPERATURE, True, self.__warning__, True)
72
+        #
73
+        self.all_off_requested = False
74
+
75
+    def flash_task(self, *args):
76
+        if self.flash_active:
77
+            self.send_command(self.output_key_delayed, not self.get(self.output_key_delayed))
78
+            self.output_key_delayed = None
79
+            if self.all_off_requested:
80
+                self.delayed_off_task.run()
81
+
82
+    def off_task(self, *args):
83
+        self.all_off()
84
+
85
+    @property
86
+    def flash_active(self):
87
+        return self.output_key_delayed is not None
88
+
89
+    #
90
+    # WARNING CALL
91
+    #
92
+    def __warning__(self, client, key, data):
93
+        w = warning(self.topic, warning.TYPE_OVERTEMPERATURE, "Temperature to high (%.1f°C)", self.get(self.KEY_TEMPERATURE) or math.nan)
94
+        self.logger.warning(w)
95
+        self.set(self.KEY_WARNING, w)
96
+
97
+    #
98
+    # RX
99
+    #
100
+    @property
101
+    def output_0(self):
102
+        """rv: [True, False]"""
103
+        return self.get(self.KEY_OUTPUT_0)
104
+
105
+    @property
106
+    def output_1(self):
107
+        """rv: [True, False]"""
108
+        return self.get(self.KEY_OUTPUT_1)
109
+
110
+    @property
111
+    def input_0(self):
112
+        """rv: [True, False]"""
113
+        return self.get(self.KEY_INPUT_0)
114
+
115
+    @property
116
+    def input_1(self):
117
+        """rv: [True, False]"""
118
+        return self.get(self.KEY_INPUT_1)
119
+
120
+    @property
121
+    def longpush_0(self):
122
+        """rv: [True, False]"""
123
+        return self.get(self.KEY_LONGPUSH_0)
124
+
125
+    @property
126
+    def longpush_1(self):
127
+        """rv: [True, False]"""
128
+        return self.get(self.KEY_LONGPUSH_1)
129
+
130
+    @property
131
+    def temperature(self):
132
+        """rv: numeric value"""
133
+        return self.get(self.KEY_TEMPERATURE)
134
+
135
+    #
136
+    # TX
137
+    #
138
+    def set_output_0(self, state):
139
+        """state: [True, False]"""
140
+        self.send_command(self.KEY_OUTPUT_0, state)
141
+
142
+    def set_output_0_mcb(self, device, key, data):
143
+        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
144
+        self.set_output_0(data)
145
+
146
+    def toggle_output_0_mcb(self, device, key, data):
147
+        self.logger.info("Toggeling output 0")
148
+        self.set_output_0(not self.output_0)
149
+
150
+    def set_output_1(self, state):
151
+        """state: [True, False]"""
152
+        self.send_command(self.KEY_OUTPUT_1, state)
153
+
154
+    def set_output_1_mcb(self, device, key, data):
155
+        self.logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "Changing output 1 to %s", str(data))
156
+        self.set_output_1(data)
157
+
158
+    def toggle_output_1_mcb(self, device, key, data):
159
+        self.logger.info("Toggeling output 1")
160
+        self.set_output_1(not self.output_1)
161
+
162
+    def flash_0_mcb(self, device, key, data):
163
+        self.output_key_delayed = self.KEY_OUTPUT_0
164
+        self.toggle_output_0_mcb(device, key, data)
165
+        self.delayed_flash_task.run()
166
+
167
+    def flash_1_mcb(self, device, key, data):
168
+        self.output_key_delayed = self.KEY_OUTPUT_1
169
+        self.toggle_output_1_mcb(device, key, data)
170
+        self.delayed_flash_task.run()
171
+
172
+    def all_off(self):
173
+        if self.flash_active:
174
+            self.all_off_requested = True
175
+        else:
176
+            if self.output_0:
177
+                self.set_output_0(False)
178
+            if self.output_1:
179
+                self.set_output_1(False)

+ 114
- 0
devices/silvercrest.py View File

@@ -0,0 +1,114 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+from devices.base import base
5
+import logging
6
+
7
+
8
+class silvercrest_powerplug(base):
9
+    """ Communication (MQTT)
10
+
11
+        silvercrest_powerplug {
12
+                            |      "state": ["ON" / "OFF"]
13
+                            |      "linkquality": [0...255] lqi
14
+                            | }
15
+                            +- get {
16
+                            |           "state": ""
17
+                            |      }
18
+                            +- set {
19
+                                        "state": ["ON" / "OFF"]
20
+                                   }
21
+    """
22
+    KEY_LINKQUALITY = "linkquality"
23
+    KEY_OUTPUT_0 = "state"
24
+    #
25
+    TX_TYPE = base.TX_DICT
26
+    TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0]
27
+    #
28
+    RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0]
29
+    RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0]
30
+
31
+    def __init__(self, mqtt_client, topic):
32
+        super().__init__(mqtt_client, topic)
33
+
34
+    #
35
+    # RX
36
+    #
37
+    @property
38
+    def output_0(self):
39
+        """rv: [True, False]"""
40
+        return self.get(self.KEY_OUTPUT_0)
41
+
42
+    @property
43
+    def linkquality(self):
44
+        """rv: numeric value"""
45
+        return self.get(self.KEY_LINKQUALITY)
46
+
47
+    #
48
+    # TX
49
+    #
50
+    def set_output_0(self, state):
51
+        """state: [True, False]"""
52
+        self.send_command(self.KEY_OUTPUT_0, state)
53
+
54
+    def set_output_0_mcb(self, device, key, data):
55
+        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
56
+        self.set_output_0(data)
57
+
58
+    def toggle_output_0_mcb(self, device, key, data):
59
+        self.logger.info("Toggeling output 0")
60
+        self.set_output_0(not self.output_0)
61
+
62
+    def all_off(self):
63
+        if self.output_0:
64
+            self.set_output_0(False)
65
+
66
+
67
+class silvercrest_motion_sensor(base):
68
+    """ Communication (MQTT)
69
+
70
+        silvercrest_motion_sensor {
71
+                                      battery: [0...100] %
72
+                                      battery_low: [True, False]
73
+                                      linkquality: [0...255] lqi
74
+                                      occupancy: [True, False]
75
+                                      tamper: [True, False]
76
+                                      voltage: [0...] mV
77
+                                  }
78
+    """
79
+    KEY_BATTERY = "battery"
80
+    KEY_BATTERY_LOW = "battery_low"
81
+    KEY_LINKQUALITY = "linkquality"
82
+    KEY_OCCUPANCY = "occupancy"
83
+    KEY_UNMOUNTED = "tamper"
84
+    KEY_VOLTAGE = "voltage"
85
+    #
86
+    TX_TYPE = base.TX_DICT
87
+    #
88
+    RX_KEYS = [KEY_BATTERY, KEY_BATTERY_LOW, KEY_LINKQUALITY, KEY_OCCUPANCY, KEY_UNMOUNTED, KEY_VOLTAGE]
89
+
90
+    def __init__(self, mqtt_client, topic):
91
+        super().__init__(mqtt_client, topic)
92
+        #
93
+        self.add_callback(self.KEY_BATTERY_LOW, True, self.__warning__, True)
94
+
95
+    #
96
+    # WARNING CALL
97
+    #
98
+    def __warning__(self, client, key, data):
99
+        w = warning(self.topic, warning.TYPE_BATTERY_LOW, "Battery low (%.1f%%)", self.get(self.KEY_BATTERY) or math.nan)
100
+        self.logger.warning(w)
101
+        self.set(self.KEY_WARNING, w)
102
+
103
+    #
104
+    # RX
105
+    #
106
+    @property
107
+    def linkquality(self):
108
+        """rv: numeric value"""
109
+        return self.get(self.KEY_LINKQUALITY)
110
+
111
+    @property
112
+    def battery(self):
113
+        """rv: numeric value"""
114
+        return self.get(self.KEY_BATTERY)

+ 207
- 0
devices/tradfri.py View File

@@ -0,0 +1,207 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+from devices.base import base
5
+from devices.base import BATTERY_WARN_LEVEL
6
+import logging
7
+
8
+
9
+class tradfri_light(base):
10
+    """ Communication (MQTT)
11
+
12
+        tradfri_light {
13
+                    |      "state": ["ON" / "OFF" / "TOGGLE"]
14
+                    |      "linkquality": [0...255] lqi
15
+                    |      "brightness": [0...254]
16
+                    |      "color_mode": ["color_temp"]
17
+                    |      "color_temp": ["coolest", "cool", "neutral", "warm", "warmest", 250...454]
18
+                    |      "color_temp_startup": ["coolest", "cool", "neutral", "warm", "warmest", "previous", 250...454]
19
+                    |      "update": []
20
+                    | }
21
+                    +- get {
22
+                    |           "state": ""
23
+                    |      }
24
+                    +- set {
25
+                                "state": ["ON" / "OFF"]
26
+                                "brightness": [0...256]
27
+                                "color_temp": [250...454]
28
+                                "transition": [0...] seconds
29
+                                "brightness_move": [-X...0...X] X/s
30
+                                "brightness_step": [-X...0...X]
31
+                                "color_temp_move": [-X...0...X] X/s
32
+                                "color_temp_step": [-X...0...X]
33
+                            }
34
+    """
35
+    KEY_LINKQUALITY = "linkquality"
36
+    KEY_OUTPUT_0 = "state"
37
+    KEY_BRIGHTNESS = "brightness"
38
+    KEY_COLOR_TEMP = "color_temp"
39
+    KEY_BRIGHTNESS_FADE = "brightness_move"
40
+    #
41
+    TX_TYPE = base.TX_DICT
42
+    TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP, KEY_BRIGHTNESS_FADE]
43
+    #
44
+    RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
45
+    RX_IGNORE_KEYS = ['update', 'color_mode', 'color_temp_startup']
46
+    RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
47
+
48
+    def __init__(self, mqtt_client, topic):
49
+        super().__init__(mqtt_client, topic)
50
+
51
+    def __device_to_instance_filter__(self, key, data):
52
+        if key == self.KEY_BRIGHTNESS:
53
+            return int(round((data - 1) * 100 / 253, 0))
54
+        elif key == self.KEY_COLOR_TEMP:
55
+            return int(round((data - 250) * 10 / 204, 0))
56
+        return super().__device_to_instance_filter__(key, data)
57
+
58
+    def __instance_to_device_filter__(self, key, data):
59
+        if key == self.KEY_BRIGHTNESS:
60
+            return int(round(data * 253 / 100 + 1, 0))
61
+        elif key == self.KEY_COLOR_TEMP:
62
+            return int(round(data * 204 / 10 + 250, 0))
63
+        return super().__instance_to_device_filter__(key, data)
64
+
65
+    #
66
+    # RX
67
+    #
68
+    @property
69
+    def output_0(self):
70
+        """rv: [True, False]"""
71
+        return self.get(self.KEY_OUTPUT_0, False)
72
+
73
+    @property
74
+    def linkquality(self):
75
+        """rv: numeric value"""
76
+        return self.get(self.KEY_LINKQUALITY, 0)
77
+
78
+    @property
79
+    def brightness(self):
80
+        """rv: numeric value [0%, ..., 100%]"""
81
+        return self.get(self.KEY_BRIGHTNESS, 0)
82
+
83
+    @property
84
+    def color_temp(self):
85
+        """rv: numeric value [0, ..., 10]"""
86
+        return self.get(self.KEY_COLOR_TEMP, 0)
87
+
88
+    #
89
+    # TX
90
+    #
91
+    def request_data(self, device=None, key=None, data=None):
92
+        self.mqtt_client.send(self.topic + "/get", '{"%s": ""}' % self.KEY_OUTPUT_0)
93
+
94
+    def set_output_0(self, state):
95
+        """state: [True, False]"""
96
+        self.send_command(self.KEY_OUTPUT_0, state)
97
+
98
+    def set_output_0_mcb(self, device, key, data):
99
+        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
100
+        self.set_output_0(data)
101
+
102
+    def toggle_output_0_mcb(self, device, key, data):
103
+        self.logger.info("Toggeling output 0")
104
+        self.set_output_0(not self.output_0)
105
+
106
+    def set_brightness(self, brightness):
107
+        """brightness: [0, ..., 100]"""
108
+        self.send_command(self.KEY_BRIGHTNESS, brightness)
109
+
110
+    def set_brightness_mcb(self, device, key, data):
111
+        self.logger.log(logging.INFO if data != self.brightness else logging.DEBUG, "Changing brightness to %s", str(data))
112
+        self.set_brightness(data)
113
+
114
+    def default_inc(self, speed=40):
115
+        self.send_command(self.KEY_BRIGHTNESS_FADE, speed)
116
+
117
+    def default_dec(self, speed=-40):
118
+        self.default_inc(speed)
119
+
120
+    def default_stop(self):
121
+        self.default_inc(0)
122
+
123
+    def set_color_temp(self, color_temp):
124
+        """color_temp: [0, ..., 10]"""
125
+        self.send_command(self.KEY_COLOR_TEMP, color_temp)
126
+
127
+    def set_color_temp_mcb(self, device, key, data):
128
+        self.logger.log(logging.INFO if data != self.color_temp else logging.DEBUG, "Changing color temperature to %s", str(data))
129
+        self.set_color_temp(data)
130
+
131
+    def all_off(self):
132
+        if self.output_0:
133
+            self.set_output_0(False)
134
+
135
+
136
+class tradfri_button(base):
137
+    """ Communication (MQTT)
138
+
139
+        tradfri_button {
140
+                            "action": [
141
+                                           "arrow_left_click",
142
+                                           "arrow_left_hold",
143
+                                           "arrow_left_release",
144
+                                           "arrow_right_click",
145
+                                           "arrow_right_hold",
146
+                                           "arrow_right_release",
147
+                                           "brightness_down_click",
148
+                                           "brightness_down_hold",
149
+                                           "brightness_down_release",
150
+                                           "brightness_up_click",
151
+                                           "brightness_up_hold",
152
+                                           "brightness_up_release",
153
+                                           "toggle"
154
+                                      ]
155
+                            "action_duration": [0...] s
156
+                            "battery": [0...100] %
157
+                            "linkquality": [0...255] lqi
158
+                            "update": []
159
+                       }
160
+    """
161
+    ACTION_TOGGLE = "toggle"
162
+    ACTION_BRIGHTNESS_UP = "brightness_up_click"
163
+    ACTION_BRIGHTNESS_DOWN = "brightness_down_click"
164
+    ACTION_RIGHT = "arrow_right_click"
165
+    ACTION_LEFT = "arrow_left_click"
166
+    ACTION_BRIGHTNESS_UP_LONG = "brightness_up_hold"
167
+    ACTION_BRIGHTNESS_UP_RELEASE = "brightness_up_release"
168
+    ACTION_BRIGHTNESS_DOWN_LONG = "brightness_down_hold"
169
+    ACTION_BRIGHTNESS_DOWN_RELEASE = "brightness_down_release"
170
+    ACTION_RIGHT_LONG = "arrow_right_hold"
171
+    ACTION_RIGHT_RELEASE = "arrow_right_release"
172
+    ACTION_LEFT_LONG = "arrow_left_hold"
173
+    ACTION_LEFT_RELEASE = "arrow_left_release"
174
+    #
175
+    KEY_LINKQUALITY = "linkquality"
176
+    KEY_BATTERY = "battery"
177
+    KEY_ACTION = "action"
178
+    KEY_ACTION_DURATION = "action_duration"
179
+    #
180
+    RX_KEYS = [KEY_LINKQUALITY, KEY_BATTERY, KEY_ACTION]
181
+    RX_IGNORE_KEYS = ['update', KEY_ACTION_DURATION]
182
+
183
+    def __init__(self, mqtt_client, topic):
184
+        super().__init__(mqtt_client, topic)
185
+        #
186
+        self.add_callback(self.KEY_BATTERY, None, self.__warning__, True)
187
+        self.__battery_warning__ = False
188
+
189
+    #
190
+    # WARNING CALL
191
+    #
192
+    def __warning__(self, client, key, data):
193
+        if data <= BATTERY_WARN_LEVEL:
194
+            if not self.__battery_warning__:
195
+                w = warning(self.topic, warning.TYPE_BATTERY_LOW, "Battery low (%.1f%%)", data)
196
+                self.logger.warning(w)
197
+                self.set(self.KEY_WARNING, w)
198
+        else:
199
+            self.__battery_warning__ = False
200
+
201
+    #
202
+    # RX
203
+    #
204
+    @property
205
+    def action(self):
206
+        """rv: action_txt"""
207
+        return self.get(self.KEY_ACTION)

+ 17
- 14
function/__init__.py View File

@@ -19,19 +19,19 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
19 19
 
20 20
 
21 21
 class all_functions(room_collection):
22
-    def __init__(self, mqtt_client):
23
-        super().__init__(mqtt_client)
22
+    def __init__(self, mqtt_client, pd, vd):
23
+        super().__init__(mqtt_client, pd, vd)
24 24
         #
25 25
         # Rooms
26 26
         #
27 27
         # stairway
28
-        self.stw = stairway(self.mqtt_client)
28
+        self.stw = stairway(self.mqtt_client, pd, vd)
29 29
         # ground floor west
30
-        self.gfw = ground_floor_west(self.mqtt_client)
30
+        self.gfw = ground_floor_west(self.mqtt_client, pd, vd)
31 31
         # first floor west
32
-        self.ffw = first_floor_west(self.mqtt_client)
32
+        self.ffw = first_floor_west(self.mqtt_client, pd, vd)
33 33
         # first floor east
34
-        self.ffe = first_floor_east(self.mqtt_client)
34
+        self.ffe = first_floor_east(self.mqtt_client, pd, vd)
35 35
         #
36 36
         # Interactions
37 37
         #
@@ -42,27 +42,30 @@ class all_functions(room_collection):
42 42
         # Warnings
43 43
         videv_warning = videv_warnings(self.mqtt_client, config.TOPIC_WARNINGS)
44 44
         for device in self.all_devices():
45
-            device.add_callback(devices.base.KEY_WARNING, None, videv_warning.warningcollector)
45
+            device.add_callback(devices.base.base.KEY_WARNING, None, videv_warning.warningcollector)
46 46
 
47 47
     def init_cross_room_interactions(self):
48 48
         # shelly dirk input 1
49 49
         self.last_gfw_dirk_input_1 = None
50
-        self.gfw.dirk.main_light_shelly.add_callback(devices.shelly.KEY_INPUT_1, None, self.gfw_dirk_input_1)
50
+        self.gfw.dirk.main_light_shelly.add_callback(self.gfw.dirk.main_light_shelly.KEY_INPUT_1, None, self.gfw_dirk_input_1)
51 51
         # tradfri button ffe_sleep right click
52
-        self.ffe.sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
53
-                                                   devices.tradfri_button.ACTION_RIGHT, self.ffe.floor.main_light_shelly.toggle_output_0_mcb)
52
+        self.ffe.sleep.button_tradfri.add_callback(self.ffe.sleep.button_tradfri.KEY_ACTION,
53
+                                                   self.ffe.sleep.button_tradfri.ACTION_RIGHT,
54
+                                                   self.ffe.floor.main_light_shelly.toggle_output_0_mcb)
54 55
 
55 56
     def init_off_functionality(self):
56 57
         # ALL OFF - Virtual device
57 58
         self.videv_all_off = all_off(self.mqtt_client, config.TOPIC_ALL_OFF_VIDEV, self)
58 59
 
59 60
         # ALL OFF - Long push stairway
60
-        self.stw.stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.stw.stairway.main_light_shelly.flash_0_mcb)
61
-        self.stw.stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.all_off)
61
+        self.stw.stairway.main_light_shelly.add_callback(self.stw.stairway.main_light_shelly.KEY_LONGPUSH_0,
62
+                                                         True, self.stw.stairway.main_light_shelly.flash_0_mcb)
63
+        self.stw.stairway.main_light_shelly.add_callback(self.stw.stairway.main_light_shelly.KEY_LONGPUSH_0, True, self.all_off)
62 64
 
63 65
         # FFE ALL OFF - Long push ffe_floor
64
-        self.ffe.floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe.floor.main_light_shelly.flash_0_mcb)
65
-        self.ffe.floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe.all_off)
66
+        self.ffe.floor.main_light_shelly.add_callback(self.ffe.floor.main_light_shelly.KEY_LONGPUSH_0,
67
+                                                      True, self.ffe.floor.main_light_shelly.flash_0_mcb)
68
+        self.ffe.floor.main_light_shelly.add_callback(self.ffe.floor.main_light_shelly.KEY_LONGPUSH_0, True, self.ffe.all_off)
66 69
 
67 70
         # FFE ALL OFF - Long push input device
68 71
         self.ffe.sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe.all_off)

+ 78
- 71
function/first_floor_east.py View File

@@ -3,7 +3,8 @@
3 3
 #
4 4
 
5 5
 import config
6
-import devices
6
+import devdi.props as props
7
+from devices import group
7 8
 from function.db import get_radiator_data, set_radiator_data
8 9
 from function.helpers import day_event
9 10
 from function.modules import brightness_choose_n_action, timer_on_activation, heating_function
@@ -17,26 +18,29 @@ except ImportError:
17 18
     ROOT_LOGGER_NAME = 'root'
18 19
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
19 20
 
21
+loc = props.LOC_FFE
22
+
20 23
 
21 24
 class first_floor_east(room_collection):
22
-    def __init__(self, mqtt_client):
23
-        super().__init__(mqtt_client)
24
-        self.dining = first_floor_east_dining(mqtt_client)
25
-        self.floor = first_floor_east_floor(mqtt_client)
26
-        self.kitchen = first_floor_east_kitchen(mqtt_client)
27
-        self.livingroom = first_floor_east_living(mqtt_client)
28
-        self.sleep = first_floor_east_sleep(mqtt_client)
25
+    def __init__(self, mqtt_client, pd, vd):
26
+        super().__init__(mqtt_client, pd, vd)
27
+        self.dining = first_floor_east_dining(mqtt_client, pd, vd)
28
+        self.floor = first_floor_east_floor(mqtt_client, pd, vd)
29
+        self.kitchen = first_floor_east_kitchen(mqtt_client, pd, vd)
30
+        self.livingroom = first_floor_east_living(mqtt_client, pd, vd)
31
+        self.sleep = first_floor_east_sleep(mqtt_client, pd, vd)
29 32
 
30 33
 
31 34
 class first_floor_east_floor(room):
32
-    def __init__(self, mqtt_client):
35
+    def __init__(self, mqtt_client, pd, vd):
36
+        roo = props.ROO_FLO
33 37
         #
34 38
         # Device initialisation
35 39
         #
36 40
         # http://shelly1l-3C6105E4E629
37 41
         # main light
38
-        self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY)
39
-        super().__init__(mqtt_client)
42
+        self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
43
+        super().__init__(mqtt_client, pd, vd)
40 44
 
41 45
         #
42 46
         # Virtual Device Interface
@@ -44,36 +48,37 @@ class first_floor_east_floor(room):
44 48
         # main light
45 49
         self.main_light = videv_switching(
46 50
             mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV,
47
-            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
51
+            self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0
48 52
         )
49 53
 
50 54
 
51 55
 class first_floor_east_kitchen(room):
52
-    def __init__(self, mqtt_client):
56
+    def __init__(self, mqtt_client, pd, vd):
57
+        roo = props.ROO_KIT
53 58
         #
54 59
         # Device initialisation
55 60
         #
56 61
         # http://shelly1l-8CAAB5616C01
57 62
         # main light
58
-        self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY)
63
+        self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
59 64
         # http://shelly1-e89f6d85a466/
60 65
         # circulation pump
61
-        self.circulation_pump_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY)
66
+        self.circulation_pump_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_CIR)
62 67
         # heating function
63
-        self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_KITCHEN_HEATING_VALVE_ZIGBEE)
68
+        self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA)
64 69
 
65
-        super().__init__(mqtt_client)
70
+        super().__init__(mqtt_client, pd, vd)
66 71
 
67 72
         #
68 73
         # Functionality initialisation
69 74
         #
70 75
         # circulation pump
71
-        self.circulation_pump = timer_on_activation(self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0, 10*60)
72
-        self.circulation_pump_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.main_light_shelly.flash_0_mcb, True)
76
+        self.circulation_pump = timer_on_activation(self.circulation_pump_shelly, self.circulation_pump_shelly.KEY_OUTPUT_0, 10*60)
77
+        self.circulation_pump_shelly.add_callback(self.circulation_pump_shelly.KEY_OUTPUT_0, True, self.main_light_shelly.flash_0_mcb, True)
73 78
         # heating function
74 79
         self.heating_function = heating_function(
75 80
             self.heating_valve,
76
-            config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
81
+            config.DEFAULT_TEMPERATURE,
77 82
             **get_radiator_data(self.heating_valve.topic)
78 83
         )
79 84
         self.heating_function.add_callback(None, None, set_radiator_data, True)
@@ -84,12 +89,12 @@ class first_floor_east_kitchen(room):
84 89
         # main light
85 90
         self.main_light_videv = videv_switching(
86 91
             mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV,
87
-            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
92
+            self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0
88 93
         )
89 94
         # circulation pump
90 95
         self.circulation_pump_videv = videv_switching_timer(
91 96
             mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV,
92
-            self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0,
97
+            self.circulation_pump_shelly, self.circulation_pump_shelly.KEY_OUTPUT_0,
93 98
             self.circulation_pump, timer_on_activation.KEY_TIMER
94 99
         )
95 100
         # heating function
@@ -100,7 +105,8 @@ class first_floor_east_kitchen(room):
100 105
 
101 106
 
102 107
 class first_floor_east_dining(room):
103
-    def __init__(self, mqtt_client):
108
+    def __init__(self, mqtt_client, pd, vd):
109
+        roo = props.ROO_DIN
104 110
         #
105 111
         # Device initialisation
106 112
         #
@@ -108,15 +114,15 @@ class first_floor_east_dining(room):
108 114
 
109 115
         # http://shelly1l-84CCA8ADD055
110 116
         # main light
111
-        self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY)
117
+        self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
112 118
         # floor lamp
113
-        self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
119
+        self.floorlamp_powerplug = pd.get(props.STG_ZFE, loc, roo, props.FUN_FLL)
114 120
         # heating function
115
-        self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_DININGROOM_HEATING_VALVE_ZIGBEE)
121
+        self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA)
116 122
         # garland
117 123
         if config.CHRISTMAS:
118
-            self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
119
-        super().__init__(mqtt_client)
124
+            self.garland_powerplug = pd.get(props.STG_ZFE, loc, roo, props.FUN_GAR)
125
+        super().__init__(mqtt_client, pd, vd)
120 126
 
121 127
         #
122 128
         # Functionality initialisation
@@ -124,12 +130,12 @@ class first_floor_east_dining(room):
124 130
         self.day_events.add_callback(None, True, self.__day_events__, True)
125 131
 
126 132
         # main light
127
-        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True)
133
+        self.main_light_shelly.add_callback(self.main_light_shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True)
128 134
 
129 135
         # heating function
130 136
         self.heating_function = heating_function(
131 137
             self.heating_valve,
132
-            config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
138
+            config.DEFAULT_TEMPERATURE,
133 139
             **get_radiator_data(self.heating_valve.topic)
134 140
         )
135 141
         self.heating_function.add_callback(None, None, set_radiator_data, True)
@@ -140,12 +146,12 @@ class first_floor_east_dining(room):
140 146
         # main light
141 147
         self.main_light_videv = videv_switching(
142 148
             mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV,
143
-            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
149
+            self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0
144 150
         )
145 151
         # floor lamp
146 152
         self.floorlamp_videv = videv_switching(
147 153
             mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV,
148
-            self.floorlamp_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
154
+            self.floorlamp_powerplug, self.floorlamp_powerplug.KEY_OUTPUT_0
149 155
         )
150 156
         # heating function
151 157
         self.heating_function_videv = videv_heating(
@@ -156,7 +162,7 @@ class first_floor_east_dining(room):
156 162
         if config.CHRISTMAS:
157 163
             self.garland_videv = videv_switching(
158 164
                 mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_VIDEV,
159
-                self.garland_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
165
+                self.garland_powerplug, self.garland_powerplug.KEY_OUTPUT_0
160 166
             )
161 167
 
162 168
     def __day_events__(self, device, key, data):
@@ -169,44 +175,45 @@ class first_floor_east_dining(room):
169 175
 
170 176
 
171 177
 class first_floor_east_sleep(room):
172
-    def __init__(self, mqtt_client):
178
+    def __init__(self, mqtt_client, pd, vd):
179
+        roo = props.ROO_SLP
173 180
         #
174 181
         # Device initialisation
175 182
         #
176 183
         # http://shelly1l-E8DB84A254C7
177 184
         # main light
178
-        self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY)
179
-        self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE)
185
+        self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
186
+        self.main_light_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
180 187
         # bed light
181
-        self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE)
182
-        self.bed_light_ma_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)
188
+        self.bed_light_di_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_BLD)
189
+        self.bed_light_ma_powerplug = pd.get(props.STG_ZFE, loc, roo, props.FUN_BLM)
183 190
         # heating function
184
-        self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE)
191
+        self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA)
185 192
         # button
186
-        self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
193
+        self.button_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_INP)
187 194
 
188
-        super().__init__(mqtt_client)
195
+        super().__init__(mqtt_client, pd, vd)
189 196
 
190 197
         #
191 198
         # Functionality initialisation
192 199
         #
193 200
         # button / brightness function
194 201
         self.brightness_functions = brightness_choose_n_action(self.button_tradfri)
195
-        self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
196
-        self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0)
202
+        self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0)
203
+        self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri, self.bed_light_di_tradfri.KEY_OUTPUT_0)
197 204
         # button / main light
198
-        self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_TOGGLE,
205
+        self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_TOGGLE,
199 206
                                          self.main_light_shelly.toggle_output_0_mcb)
200 207
         # button / bed light
201
-        self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
208
+        self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_LEFT,
202 209
                                          self.bed_light_di_tradfri.toggle_output_0_mcb)
203
-        self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT_LONG,
210
+        self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_LEFT_LONG,
204 211
                                          self.bed_light_ma_powerplug.toggle_output_0_mcb)
205 212
 
206 213
         # heating function
207 214
         self.heating_function = heating_function(
208 215
             self.heating_valve,
209
-            config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
216
+            config.DEFAULT_TEMPERATURE,
210 217
             **get_radiator_data(self.heating_valve.topic)
211 218
         )
212 219
         self.heating_function.add_callback(None, None, set_radiator_data, True)
@@ -217,19 +224,19 @@ class first_floor_east_sleep(room):
217 224
         # main light
218 225
         self.main_light_videv = videv_switch_brightness_color_temp(
219 226
             mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV,
220
-            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
221
-            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
222
-            self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
227
+            self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
228
+            self.main_light_tradfri, self.main_light_tradfri.KEY_BRIGHTNESS,
229
+            self.main_light_tradfri, self.main_light_tradfri.KEY_COLOR_TEMP
223 230
         )
224 231
         # bed light
225 232
         self.bed_light_di_videv = videv_switch_brightness(
226 233
             mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV,
227
-            self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0,
228
-            self.bed_light_di_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
234
+            self.bed_light_di_tradfri, self.bed_light_di_tradfri.KEY_OUTPUT_0,
235
+            self.bed_light_di_tradfri, self.bed_light_di_tradfri.KEY_BRIGHTNESS,
229 236
         )
230 237
         self.bed_light_ma_videv = videv_switching(
231 238
             mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV,
232
-            self.bed_light_ma_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
239
+            self.bed_light_ma_powerplug, self.bed_light_ma_powerplug.KEY_OUTPUT_0
233 240
         )
234 241
         # heating function
235 242
         self.heating_function_videv = videv_heating(
@@ -244,35 +251,35 @@ class first_floor_east_sleep(room):
244 251
 
245 252
 
246 253
 class first_floor_east_living(room):
247
-    def __init__(self, mqtt_client):
254
+    def __init__(self, mqtt_client, pd, vd):
255
+        roo = props.ROO_LIV
248 256
         #
249 257
         # Device initialisation
250 258
         #
251 259
         # http://shelly1l-3C6105E3F910
252 260
         # main light
253
-        self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY)
254
-        self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE)
261
+        self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
262
+        self.main_light_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
255 263
         # floor lamp
256
-        self.floorlamp_tradfri = devices.group(
257
-            *[devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i) for i in range(1, 7)])
264
+        self.floorlamp_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_FLL)
258 265
         # heating function
259
-        self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_LIVINGROOM_HEATING_VALVE_ZIGBEE)
266
+        self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA)
260 267
         # xmas tree
261 268
         if config.CHRISTMAS:
262
-            self.powerplug_xmas_tree = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
263
-            self.powerplug_xmas_star = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
269
+            self.powerplug_xmas_tree = pd.get(props.STG_ZFE, loc, roo, props.FUN_XTR)
270
+            self.powerplug_xmas_star = pd.get(props.STG_ZFE, loc, roo, props.FUN_XST)
264 271
 
265
-        super().__init__(mqtt_client)
272
+        super().__init__(mqtt_client, pd, vd)
266 273
 
267 274
         #
268 275
         # Functionality initialisation
269 276
         #
270 277
         # floor lamp synchronisation with main_light
271
-        self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_tradfri.set_output_0_mcb, True)
278
+        self.main_light_shelly.add_callback(self.main_light_shelly.KEY_OUTPUT_0, None, self.floorlamp_tradfri.set_output_0_mcb, True)
272 279
         # heating function
273 280
         self.heating_function = heating_function(
274 281
             self.heating_valve,
275
-            config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
282
+            config.DEFAULT_TEMPERATURE,
276 283
             **get_radiator_data(self.heating_valve.topic)
277 284
         )
278 285
         self.heating_function.add_callback(None, None, set_radiator_data, True)
@@ -283,16 +290,16 @@ class first_floor_east_living(room):
283 290
         # main light
284 291
         self.main_light_videv = videv_switch_brightness_color_temp(
285 292
             mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV,
286
-            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
287
-            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
288
-            self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
293
+            self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
294
+            self.main_light_tradfri, self.main_light_tradfri.KEY_BRIGHTNESS,
295
+            self.main_light_tradfri, self.main_light_tradfri.KEY_COLOR_TEMP
289 296
         )
290 297
         # floor lamp
291 298
         self.floorlamp_videv = videv_switch_brightness_color_temp(
292 299
             mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV,
293
-            self.floorlamp_tradfri, devices.tradfri_light.KEY_OUTPUT_0,
294
-            self.floorlamp_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
295
-            self.floorlamp_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
300
+            self.floorlamp_tradfri, self.floorlamp_tradfri.KEY_OUTPUT_0,
301
+            self.floorlamp_tradfri, self.floorlamp_tradfri.KEY_BRIGHTNESS,
302
+            self.floorlamp_tradfri, self.floorlamp_tradfri.KEY_COLOR_TEMP
296 303
         )
297 304
         # heating function
298 305
         self.heating_function_videv = videv_heating(
@@ -303,5 +310,5 @@ class first_floor_east_living(room):
303 310
         if config.CHRISTMAS:
304 311
             self.xmas_tree_videv = videv_switching(
305 312
                 mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV,
306
-                self.powerplug_xmas_tree, devices.silvercrest_powerplug.KEY_OUTPUT_0
313
+                self.powerplug_xmas_tree, self.powerplug_xmas_tree.KEY_OUTPUT_0
307 314
             )

+ 42
- 36
function/first_floor_west.py View File

@@ -3,7 +3,7 @@
3 3
 #
4 4
 
5 5
 import config
6
-import devices
6
+import devdi.props as props
7 7
 from function.db import get_radiator_data, set_radiator_data
8 8
 from function.modules import heating_function
9 9
 from function.rooms import room, room_collection
@@ -17,35 +17,38 @@ except ImportError:
17 17
     ROOT_LOGGER_NAME = 'root'
18 18
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
19 19
 
20
+loc = props.LOC_FFW
21
+
20 22
 
21 23
 class first_floor_west(room_collection):
22
-    def __init__(self, mqtt_client):
23
-        super().__init__(mqtt_client)
24
-        self.bath = first_floor_west_bath(mqtt_client)
25
-        self.julian = first_floor_west_julian(mqtt_client)
26
-        self.livingroom = first_floor_west_living(mqtt_client)
27
-        self.sleep = first_floor_west_sleep(mqtt_client)
24
+    def __init__(self, mqtt_client, pd, vd):
25
+        super().__init__(mqtt_client, pd, vd)
26
+        self.bath = first_floor_west_bath(mqtt_client, pd, vd)
27
+        self.julian = first_floor_west_julian(mqtt_client, pd, vd)
28
+        self.livingroom = first_floor_west_living(mqtt_client, pd, vd)
29
+        self.sleep = first_floor_west_sleep(mqtt_client, pd, vd)
28 30
 
29 31
 
30 32
 class first_floor_west_julian(room):
31
-    def __init__(self, mqtt_client):
33
+    def __init__(self, mqtt_client, pd, vd):
34
+        roo = props.ROO_JUL
32 35
         #
33 36
         # Device initialisation
34 37
         #
35 38
         # http://shelly1l-3C6105E43452
36 39
         # main light
37
-        self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY)
38
-        self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE)
40
+        self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
41
+        self.main_light_tradfri = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
39 42
         # heating function
40
-        self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFW_JULIAN_HEATING_VALVE_ZIGBEE)
41
-        super().__init__(mqtt_client)
43
+        self.heating_valve = pd.get(props.STG_ZFW, loc, roo, props.FUN_HEA)
44
+        super().__init__(mqtt_client, pd, vd)
42 45
         #
43 46
         # Functionality initialisation
44 47
         #
45 48
         # heating function
46 49
         self.heating_function = heating_function(
47 50
             self.heating_valve,
48
-            config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
51
+            config.DEFAULT_TEMPERATURE,
49 52
             **get_radiator_data(self.heating_valve.topic)
50 53
         )
51 54
         self.heating_function.add_callback(None, None, set_radiator_data, True)
@@ -56,9 +59,9 @@ class first_floor_west_julian(room):
56 59
         # main light
57 60
         self.main_light_videv = videv_switch_brightness_color_temp(
58 61
             mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_VIDEV,
59
-            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
60
-            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
61
-            self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
62
+            self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
63
+            self.main_light_tradfri, self.main_light_tradfri.KEY_BRIGHTNESS,
64
+            self.main_light_tradfri, self.main_light_tradfri.KEY_COLOR_TEMP
62 65
         )
63 66
         # heating function
64 67
         self.heating_function_videv = videv_heating(
@@ -68,13 +71,14 @@ class first_floor_west_julian(room):
68 71
 
69 72
 
70 73
 class first_floor_west_bath(room):
71
-    def __init__(self, mqtt_client):
74
+    def __init__(self, mqtt_client, pd, vd):
75
+        roo = props.ROO_BAT
72 76
         #
73 77
         # Device initialisation
74 78
         #
75 79
         # heating function
76
-        self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE)
77
-        super().__init__(mqtt_client)
80
+        self.heating_valve = pd.get(props.STG_ZFW, loc, roo, props.FUN_HEA)
81
+        super().__init__(mqtt_client, pd, vd)
78 82
 
79 83
         #
80 84
         # Functionality initialisation
@@ -82,7 +86,7 @@ class first_floor_west_bath(room):
82 86
         # heating function
83 87
         self.heating_function = heating_function(
84 88
             self.heating_valve,
85
-            config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
89
+            config.DEFAULT_TEMPERATURE,
86 90
             **get_radiator_data(self.heating_valve.topic)
87 91
         )
88 92
         self.heating_function.add_callback(None, None, set_radiator_data, True)
@@ -98,17 +102,18 @@ class first_floor_west_bath(room):
98 102
 
99 103
 
100 104
 class first_floor_west_living(room):
101
-    def __init__(self, mqtt_client):
105
+    def __init__(self, mqtt_client, pd, vd):
106
+        roo = props.ROO_LIV
102 107
         #
103 108
         # Device initialisation
104 109
         #
105 110
         # http://shelly1l-84CCA8ACE6A1
106 111
         # main light
107
-        self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY)
108
-        self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE)
112
+        self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
113
+        self.main_light_tradfri = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
109 114
         # # heating function
110
-        # self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFW_LIVINGROOM_HEATING_VALVE_ZIGBEE)
111
-        super().__init__(mqtt_client)
115
+        # self.heating_valve = pd.get(props.STG_ZFW, loc, roo, props.FUN_HEA)
116
+        super().__init__(mqtt_client, pd, vd)
112 117
 
113 118
         #
114 119
         # Functionality initialisation
@@ -127,9 +132,9 @@ class first_floor_west_living(room):
127 132
         # main light
128 133
         self.main_light_videv = videv_switch_brightness_color_temp(
129 134
             mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_VIDEV,
130
-            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
131
-            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
132
-            self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
135
+            self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
136
+            self.main_light_tradfri, self.main_light_tradfri.KEY_BRIGHTNESS,
137
+            self.main_light_tradfri, self.main_light_tradfri.KEY_COLOR_TEMP
133 138
         )
134 139
         # # heating function
135 140
         # self.heating_function_videv = videv_heating(
@@ -139,17 +144,18 @@ class first_floor_west_living(room):
139 144
 
140 145
 
141 146
 class first_floor_west_sleep(room):
142
-    def __init__(self, mqtt_client):
147
+    def __init__(self, mqtt_client, pd, vd):
148
+        roo = props.ROO_SLP
143 149
         #
144 150
         # Device initialisation
145 151
         #
146 152
         # http://shelly1-3494546A51F2
147 153
         # main light
148
-        self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY)
149
-        self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE)
154
+        self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
155
+        self.main_light_tradfri = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
150 156
         # heating function
151
-        self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFW_SLEEP_HEATING_VALVE_ZIGBEE)
152
-        super().__init__(mqtt_client)
157
+        self.heating_valve = pd.get(props.STG_ZFW, loc, roo, props.FUN_HEA)
158
+        super().__init__(mqtt_client, pd, vd)
153 159
 
154 160
         #
155 161
         # Functionality initialisation
@@ -157,7 +163,7 @@ class first_floor_west_sleep(room):
157 163
         # heating function
158 164
         self.heating_function = heating_function(
159 165
             self.heating_valve,
160
-            config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
166
+            config.DEFAULT_TEMPERATURE,
161 167
             **get_radiator_data(self.heating_valve.topic)
162 168
         )
163 169
         self.heating_function.add_callback(None, None, set_radiator_data, True)
@@ -168,8 +174,8 @@ class first_floor_west_sleep(room):
168 174
         # main light
169 175
         self.main_light_videv = videv_switch_brightness(
170 176
             mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_VIDEV,
171
-            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
172
-            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS
177
+            self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
178
+            self.main_light_tradfri, self.main_light_tradfri.KEY_BRIGHTNESS
173 179
         )
174 180
         # heating function
175 181
         self.heating_function_videv = videv_heating(

+ 65
- 55
function/ground_floor_west.py View File

@@ -3,7 +3,8 @@
3 3
 #
4 4
 
5 5
 import config
6
-import devices
6
+from devdi import props
7
+from devices import group
7 8
 from function.db import get_radiator_data, set_radiator_data
8 9
 from function.modules import brightness_choose_n_action, heating_function, switched_light
9 10
 from function.rooms import room, room_collection
@@ -17,54 +18,57 @@ except ImportError:
17 18
     ROOT_LOGGER_NAME = 'root'
18 19
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
19 20
 
21
+loc = props.LOC_GFW
22
+
20 23
 
21 24
 class ground_floor_west(room_collection):
22
-    def __init__(self, mqtt_client):
23
-        super().__init__(mqtt_client)
24
-        self.dirk = ground_floor_west_dirk(mqtt_client)
25
-        self.floor = ground_floor_west_floor(mqtt_client)
26
-        self.marion = ground_floor_west_marion(mqtt_client)
25
+    def __init__(self, mqtt_client, pd, vd):
26
+        super().__init__(mqtt_client, pd, vd)
27
+        self.dirk = ground_floor_west_dirk(mqtt_client, pd, vd)
28
+        self.floor = ground_floor_west_floor(mqtt_client, pd, vd)
29
+        self.marion = ground_floor_west_marion(mqtt_client, pd, vd)
27 30
 
28 31
 
29 32
 class ground_floor_west_floor(room):
30
-    def __init__(self, mqtt_client):
33
+    def __init__(self, mqtt_client, pd, vd):
34
+        roo = props.ROO_FLO
31 35
         #
32 36
         # Device initialisation
33 37
         #
34 38
         # http://shelly1l-84CCA8AD1148
35
-        self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY)
36
-        self.main_light_tradfri = devices.group(
37
-            devices.tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 1),
38
-            devices.tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 2)
39
-        )
40
-        super().__init__(mqtt_client)
39
+        self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
40
+        self.main_light_tradfri = pd.get(props.STG_ZGW, loc, roo, props.FUN_MAL)
41
+        super().__init__(mqtt_client, pd, vd)
41 42
 
42 43
         #
43 44
         # Functionality initialisation
44 45
         #
45 46
         # Request silvercrest data of lead light after power on
46
-        switched_light(self.main_light_shelly, devices.shelly.KEY_OUTPUT_0, self.main_light_tradfri)
47
+        switched_light(self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0, self.main_light_tradfri)
47 48
 
48 49
         #
49 50
         # Virtual Device Interface
50 51
         #
51 52
         self.main_light_videv = videv_switch_brightness_color_temp(
52 53
             mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_VIDEV,
53
-            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
54
-            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
55
-            self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
54
+            self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
55
+            self.main_light_tradfri, self.main_light_tradfri.KEY_BRIGHTNESS,
56
+            self.main_light_tradfri, self.main_light_tradfri.KEY_COLOR_TEMP
56 57
         )
57 58
 
58 59
 
59 60
 class ground_floor_west_marion(room):
60
-    def __init__(self, mqtt_client):
61
+    def __init__(self, mqtt_client, pd, vd):
62
+        roo = props.ROO_MAR
61 63
         #
62 64
         # Device initialisation
63 65
         #
64 66
         # http://shelly1l-E8DB84A1E067
65
-        self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY)
66
-        self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE)
67
-        super().__init__(mqtt_client)
67
+        # main light
68
+        self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
69
+        # heating function
70
+        self.heating_valve = pd.get(props.STG_ZGW, loc, roo, props.FUN_HEA)
71
+        super().__init__(mqtt_client, pd, vd)
68 72
 
69 73
         #
70 74
         # Functionality initialisation
@@ -72,7 +76,7 @@ class ground_floor_west_marion(room):
72 76
         # heating function
73 77
         self.heating_function = heating_function(
74 78
             self.heating_valve,
75
-            config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
79
+            config.DEFAULT_TEMPERATURE,
76 80
             **get_radiator_data(self.heating_valve.topic)
77 81
         )
78 82
         self.heating_function.add_callback(None, None, set_radiator_data, True)
@@ -82,7 +86,7 @@ class ground_floor_west_marion(room):
82 86
         #
83 87
         self.main_light_videv = videv_switching(
84 88
             mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_VIDEV,
85
-            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
89
+            self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0
86 90
         )
87 91
         self.heating_function_videv = videv_heating(
88 92
             mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_VIDEV,
@@ -96,69 +100,75 @@ class ground_floor_west_dirk(room):
96 100
     STATE_ACTIVE_DEVICE_AMPLIFIER = 2
97 101
     STATE_ACTIVE_DEVICE_MAX_VALUE = STATE_ACTIVE_DEVICE_AMPLIFIER
98 102
     #
99
-    KEY_POWERPLUG_AMPLIFIER = devices.my_powerplug.KEY_OUTPUT_0
100
-    KEY_POWERPLUG_CD_PLAYER = devices.my_powerplug.KEY_OUTPUT_2
101
-    KEY_POWERPLUG_DESK_LIGHT = devices.my_powerplug.KEY_OUTPUT_1
102
-    KEY_POWERPLUG_PC_DOCK = devices.my_powerplug.KEY_OUTPUT_3
103
-    #
104 103
     AUDIO_SOURCE_PC = 0
105 104
     AUDIO_SOURCE_CD = 1
106 105
     AUDIO_SOURCE_RASPI = 2
107 106
 
108
-    def __init__(self, mqtt_client):
107
+    def __init__(self, mqtt_client, pd, vd):
108
+        roo = props.ROO_DIR
109 109
         #
110 110
         # Device initialisation
111 111
         #
112 112
         # http://shelly1l-3C6105E44F27
113
-        self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY)
114
-        self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE)
115
-        self.powerplug_common = devices.my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG)
116
-        self.desk_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE)
117
-        self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
118
-        self.remote_amplifier = devices.remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
119
-        self.spotify_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_SPOTIFY)
120
-        self.mpd_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_MPD)
121
-        self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)
122
-        super().__init__(mqtt_client)
113
+        # main light
114
+        self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
115
+        self.main_light_tradfri = pd.get(props.STG_ZGW, loc, roo, props.FUN_MAL)
116
+        # powerplug
117
+        self.powerplug_common = pd.get(props.STG_MYA, loc, roo, props.FUN_MPP)
118
+        self.KEY_POWERPLUG_AMPLIFIER = self.powerplug_common.KEY_OUTPUT_0
119
+        self.KEY_POWERPLUG_DESK_LIGHT = self.powerplug_common.KEY_OUTPUT_1
120
+        self.KEY_POWERPLUG_CD_PLAYER = self.powerplug_common.KEY_OUTPUT_2
121
+        self.KEY_POWERPLUG_PC_DOCK = self.powerplug_common.KEY_OUTPUT_3
122
+        # desk light
123
+        self.desk_light_tradfri = pd.get(props.STG_ZGW, loc, roo, props.FUN_DEL)
124
+        # button
125
+        self.button_tradfri = pd.get(props.STG_ZGW, loc, roo, props.FUN_INP)
126
+        # hifi
127
+        self.remote_amplifier = pd.get(props.STG_MYA, loc, roo, props.FUN_RCA)
128
+        self.spotify_state = pd.get(props.STG_MYA, loc, roo, props.FUN_ASS)
129
+        self.mpd_state = pd.get(props.STG_MYA, loc, roo, props.FUN_ASM)
130
+        # heating function
131
+        self.heating_valve = pd.get(props.STG_ZGW, loc, roo, props.FUN_HEA)
132
+        super().__init__(mqtt_client, pd, vd)
123 133
         #
124 134
         # Functionality initialisation
125 135
         #
126 136
         # Button - Brightness functionality
127 137
         self.brightness_functions = brightness_choose_n_action(self.button_tradfri)
128
-        self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
138
+        self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0)
129 139
         self.brightness_functions.add(self.desk_light_tradfri, self.powerplug_common, self.KEY_POWERPLUG_DESK_LIGHT)
130 140
         self.brightness_functions.add(self.remote_amplifier, self.powerplug_common, self.KEY_POWERPLUG_AMPLIFIER)
131 141
         # Button - Main light
132
-        self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_TOGGLE,
142
+        self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_TOGGLE,
133 143
                                          self.main_light_shelly.toggle_output_0_mcb)
134 144
         # Button - Desk light
135
-        self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT,
145
+        self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_RIGHT,
136 146
                                          self.powerplug_common.toggle_output_1_mcb)
137 147
         # Button - Amplifier
138
-        self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT_LONG,
148
+        self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_LEFT_LONG,
139 149
                                          self.powerplug_common.toggle_output_0_mcb)
140 150
         # Button - CD player
141
-        self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG,
151
+        self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_RIGHT_LONG,
142 152
                                          self.powerplug_common.toggle_output_2_mcb)
143 153
         # Button - PC dock
144
-        self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
154
+        self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_LEFT,
145 155
                                          self.powerplug_common.toggle_output_3_mcb)
146 156
 
147 157
         # Mediaplayer - Amplifier auto on
148 158
         self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.powerplug_common.set_output_0_mcb, True)
149
-        self.spotify_state.add_callback(devices.audio_status.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True)
150
-        self.mpd_state.add_callback(devices.audio_status.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True)
159
+        self.spotify_state.add_callback(self.spotify_state.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True)
160
+        self.mpd_state.add_callback(self.mpd_state.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True)
151 161
         # Mediaplayer - Audio source selection
152 162
         self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, True, self.audio_source_selector, True)
153 163
         self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, True, self.audio_source_selector, True)
154
-        self.spotify_state.add_callback(devices.audio_status.KEY_STATE, True, self.audio_source_selector, True)
155
-        self.mpd_state.add_callback(devices.audio_status.KEY_STATE, True, self.audio_source_selector, True)
164
+        self.spotify_state.add_callback(self.spotify_state.KEY_STATE, True, self.audio_source_selector, True)
165
+        self.mpd_state.add_callback(self.mpd_state.KEY_STATE, True, self.audio_source_selector, True)
156 166
         self.audio_source = self.AUDIO_SOURCE_PC
157 167
 
158 168
         # heating function
159 169
         self.heating_function = heating_function(
160 170
             self.heating_valve,
161
-            config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
171
+            config.DEFAULT_TEMPERATURE,
162 172
             **get_radiator_data(self.heating_valve.topic)
163 173
         )
164 174
         self.heating_function.add_callback(None, None, set_radiator_data, True)
@@ -168,15 +178,15 @@ class ground_floor_west_dirk(room):
168 178
         #
169 179
         self.main_light_videv = videv_switch_brightness_color_temp(
170 180
             mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_VIDEV,
171
-            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
172
-            self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
173
-            self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
181
+            self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
182
+            self.main_light_tradfri, self.main_light_tradfri.KEY_BRIGHTNESS,
183
+            self.main_light_tradfri, self.main_light_tradfri.KEY_COLOR_TEMP
174 184
         )
175 185
         self.desk_light_videv = videv_switch_brightness_color_temp(
176 186
             mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_VIDEV,
177 187
             self.powerplug_common, self.KEY_POWERPLUG_DESK_LIGHT,
178
-            self.desk_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
179
-            self.desk_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
188
+            self.desk_light_tradfri, self.desk_light_tradfri.KEY_BRIGHTNESS,
189
+            self.desk_light_tradfri, self.desk_light_tradfri.KEY_COLOR_TEMP
180 190
         )
181 191
         self.amplifier_videv = videv_switching(
182 192
             mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_VIDEV,

+ 3
- 3
function/modules.py View File

@@ -27,7 +27,7 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
27 27
 
28 28
 class switched_light(object):
29 29
     def __init__(self, sw_device, sw_key, li_device):
30
-        sw_device.add_callback(devices.shelly.KEY_OUTPUT_0, True, li_device.request_data, True)
30
+        sw_device.add_callback(sw_device.KEY_OUTPUT_0, True, li_device.request_data, True)
31 31
 
32 32
 
33 33
 class brightness_choose_n_action(common_base):
@@ -275,8 +275,8 @@ class motion_sensor_light(common_base):
275 275
         self.motion_sensors = args
276 276
         self.timer_reload_value = timer_value
277 277
         #
278
-        sw_device.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.reload_timer, True)
279
-        sw_device.add_callback(devices.shelly.KEY_OUTPUT_0, False, self.reset_timer, True)
278
+        sw_device.add_callback(devices.shelly_sw1.KEY_OUTPUT_0, True, self.reload_timer, True)
279
+        sw_device.add_callback(devices.shelly_sw1.KEY_OUTPUT_0, False, self.reset_timer, True)
280 280
         for motion_sensor in args:
281 281
             motion_sensor.add_callback(motion_sensor.KEY_OCCUPANCY, None, self.set_motion_detected, True)
282 282
         #

+ 6
- 2
function/rooms.py View File

@@ -13,8 +13,10 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
13 13
 
14 14
 
15 15
 class room(object):
16
-    def __init__(self, mqtt_client):
16
+    def __init__(self, mqtt_client, pd, vd):
17 17
         self.mqtt_client = mqtt_client
18
+        self.pd = pd
19
+        self.vd = vd
18 20
 
19 21
     def all_off(self, device=None, key=None, data=None):
20 22
         logger.info("Switching all off \"%s\"", type(self).__name__)
@@ -29,8 +31,10 @@ class room(object):
29 31
 class room_collection(object):
30 32
     ALLOWED_CLASSES = ("room", "room_collection")
31 33
 
32
-    def __init__(self, mqtt_client):
34
+    def __init__(self, mqtt_client, pd, vd):
33 35
         self.mqtt_client = mqtt_client
36
+        self.pd = pd
37
+        self.vd = vd
34 38
 
35 39
     def all_off(self, device=None, key=None, data=None):
36 40
         logger.info("Switching all off \"%s\"", type(self).__name__)

+ 12
- 10
function/stairway.py View File

@@ -3,7 +3,7 @@
3 3
 #
4 4
 
5 5
 import config
6
-import devices
6
+from devdi import props
7 7
 import logging
8 8
 from function.modules import motion_sensor_light
9 9
 from function.rooms import room, room_collection
@@ -15,23 +15,25 @@ except ImportError:
15 15
     ROOT_LOGGER_NAME = 'root'
16 16
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
17 17
 
18
+loc = props.LOC_STW
19
+
18 20
 
19 21
 class stairway(room_collection):
20
-    def __init__(self, mqtt_client):
21
-        super().__init__(mqtt_client)
22
-        self.stairway = stairway_stairway(mqtt_client)
22
+    def __init__(self, mqtt_client, pd, vd):
23
+        super().__init__(mqtt_client, pd, vd)
24
+        self.stairway = stairway_stairway(mqtt_client, pd, vd)
23 25
 
24 26
 
25 27
 class stairway_stairway(room):
26
-    def __init__(self, mqtt_client):
28
+    def __init__(self, mqtt_client, pd, vd):
27 29
         #
28 30
         # Device initialisation
29 31
         #
30 32
         # http://shelly1-3494546A9364
31
-        self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY)
32
-        self.motion_sensor_gf = devices.silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF)
33
-        self.motion_sensor_ff = devices.silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF)
34
-        super().__init__(mqtt_client)
33
+        self.main_light_shelly = pd.get(props.STG_SHE, loc, props.ROO_STF, props.FUN_MAL)
34
+        self.motion_sensor_ff = pd.get(props.STG_ZFE, loc, props.ROO_STF, props.FUN_MSE)
35
+        self.motion_sensor_gf = pd.get(props.STG_ZGW, loc, props.ROO_STG, props.FUN_MSE)
36
+        super().__init__(mqtt_client, pd, vd)
35 37
 
36 38
         #
37 39
         # Functionality initialisation
@@ -47,6 +49,6 @@ class stairway_stairway(room):
47 49
         #
48 50
         self.main_light_videv = videv_switching_motion(
49 51
             mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV,
50
-            self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
52
+            self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
51 53
             self.motion_sensor_light
52 54
         )

+ 21
- 1
smart_brain.py View File

@@ -1,4 +1,5 @@
1 1
 import config
2
+import devdi
2 3
 import function
3 4
 import json
4 5
 import logging
@@ -38,17 +39,36 @@ def __info_publisher__(client, userdata, message):
38 39
 
39 40
 
40 41
 if __name__ == "__main__":
42
+    #
43
+    # Logging
44
+    #
41 45
     if config.DEBUG:
42 46
         report.appLoggingConfigure(None, 'stdout', ((config.APP_NAME, logging.DEBUG), ),
43 47
                                    target_level=logging.WARNING, fmt=report.SHORT_FMT, host='localhost', port=19996)
44 48
     else:
45 49
         report.stdoutLoggingConfigure(((config.APP_NAME, logging.WARNING), ), report.SHORT_FMT)
50
+
51
+    #
52
+    # MQTT Client
46 53
     #
47 54
     mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
48 55
                           password=config.MQTT_PASSWORD, name=config.APP_NAME)
49 56
     mc.add_callback(INFO_TOPIC, __info_publisher__)
50 57
 
51
-    func = function.all_functions(mc)
58
+    #
59
+    # Smarthome physical Devices
60
+    #
61
+    pd = devdi.physical_devices(mc)
62
+
63
+    #
64
+    # Smarthome physical Devices
65
+    #
66
+    vd = devdi.videv_devices(mc)
67
+
68
+    #
69
+    # Smart Home Functionality
70
+    #
71
+    func = function.all_functions(mc, pd, vd)
52 72
 
53 73
     while (True):
54 74
         time.sleep(1)

+ 0
- 47
topics.py View File

@@ -5,115 +5,68 @@ TOPIC_WARNINGS = "videv/warnings"
5 5
 TOPIC_ALL_OFF_VIDEV = "videv/off"
6 6
 # ground floor west
7 7
 # floor
8
-TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY = "shellies/gfw/floor/main_light"
9 8
 TOPIC_GFW_FLOOR_MAIN_LIGHT_VIDEV = "videv/gfw/floor/main_light"
10
-TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE = "zigbee/gfw/floor/main_light_%d"
11 9
 
12 10
 # marion
13
-TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY = "shellies/gfw/marion/main_light"
14 11
 TOPIC_GFW_MARION_MAIN_LIGHT_VIDEV = "videv/gfw/marion/main_light"
15
-TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE = "zigbee/gfw/marion/heating_valve"
16 12
 TOPIC_GFW_MARION_HEATING_VALVE_VIDEV = "videv/gfw/marion/heating_valve"
17 13
 
18 14
 # dirk
19
-TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY = "shellies/gfw/dirk/main_light"
20 15
 TOPIC_GFW_DIRK_MAIN_LIGHT_VIDEV = "videv/gfw/dirk/main_light"
21
-TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE = "zigbee/gfw/dirk/main_light"
22
-TOPIC_GFW_DIRK_INPUT_DEVICE = "zigbee/gfw/dirk/input_device"
23
-TOPIC_GFW_DIRK_POWERPLUG = "my_apps/gfw/dirk/powerplug"
24
-TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE = "zigbee/gfw/dirk/desk_light"
25 16
 TOPIC_GFW_DIRK_DESK_LIGHT_VIDEV = "videv/gfw/dirk/desk_light"
26 17
 TOPIC_GFW_DIRK_AMPLIFIER_VIDEV = "videv/gfw/dirk/amplifier"
27 18
 TOPIC_GFW_DIRK_CD_PLAYER_VIDEV = "videv/gfw/dirk/cd_player"
28 19
 TOPIC_GFW_DIRK_PC_DOCK_VIDEV = "videv/gfw/dirk/pc_dock"
29
-TOPIC_GFW_DIRK_AMPLIFIER_REMOTE = "my_apps/gfw/dirk/remote/RAS5"
30 20
 TOPIC_GFW_DIRK_ACTIVE_BRIGHTNESS_DEVICE_VIDEV = "videv/gfw/dirk/active_brightness_device"
31
-TOPIC_GFW_DIRK_SPOTIFY = "my_apps/gfw/dirk/hifi/spotify"
32
-TOPIC_GFW_DIRK_MPD = "my_apps/gfw/dirk/hifi/mpd"
33 21
 TOPIC_GFW_DIRK_AUDIO_PLAYER_VIDEV = "videv/gfw/dirk/audio_player"
34
-TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE = "zigbee/gfw/dirk/heating_valve"
35 22
 TOPIC_GFW_DIRK_HEATING_VALVE_VIDEV = "videv/gfw/dirk/heating_valve"
36 23
 
37 24
 
38 25
 # first floor west
39 26
 # julian
40
-TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY = "shellies/ffw/julian/main_light"
41 27
 TOPIC_FFW_JULIAN_MAIN_LIGHT_VIDEV = "videv/ffw/julian/main_light"
42
-TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE = "zigbee/ffw/julian/main_light"
43
-TOPIC_FFW_JULIAN_HEATING_VALVE_ZIGBEE = "zigbee/ffw/julian/heating_valve"
44 28
 TOPIC_FFW_JULIAN_HEATING_VALVE_VIDEV = "videv/ffw/julian/heating_valve"
45 29
 
46 30
 # bath
47
-TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE = "zigbee/ffw/bath/heating_valve"
48 31
 TOPIC_FFW_BATH_HEATING_VALVE_VIDEV = "videv/ffw/bath/heating_valve"
49 32
 
50 33
 # livingroom
51
-TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY = "shellies/ffw/livingroom/main_light"
52 34
 TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_VIDEV = "videv/ffw/livingroom/main_light"
53
-TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE = "zigbee/ffw/livingroom/main_light"
54
-# TOPIC_FFW_LIVINGROOM_HEATING_VALVE_ZIGBEE = "zigbee/ffw/livingroom/heating_valve"
55
-# TOPIC_FFW_LIVINGROOM_HEATING_VALVE_VIDEV = "videv/ffw/livingroom/heating_valve"
56 35
 
57 36
 # sleep
58
-TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY = "shellies/ffw/sleep/main_light"
59 37
 TOPIC_FFW_SLEEP_MAIN_LIGHT_VIDEV = "videv/ffw/sleep/main_light"
60
-TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE = "zigbee/ffw/sleep/main_light"
61
-TOPIC_FFW_SLEEP_HEATING_VALVE_ZIGBEE = "zigbee/ffw/sleep/heating_valve"
62 38
 TOPIC_FFW_SLEEP_HEATING_VALVE_VIDEV = "videv/ffw/sleep/heating_valve"
63 39
 
64 40
 
65 41
 # first floor east
66 42
 # floor
67
-TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY = "shellies/ffe/floor/main_light"
68 43
 TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV = "videv/ffe/floor/main_light"
69 44
 
70 45
 # kitchen
71
-TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY = "shellies/ffe/kitchen/main_light"
72 46
 TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV = "videv/ffe/kitchen/main_light"
73
-TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY = "shellies/ffe/kitchen/circulation_pump"
74 47
 TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV = "videv/ffe/kitchen/circulation_pump"
75
-TOPIC_FFE_KITCHEN_HEATING_VALVE_ZIGBEE = "zigbee/ffe/kitchen/heating_valve"
76 48
 TOPIC_FFE_KITCHEN_HEATING_VALVE_VIDEV = "videv/ffe/kitchen/heating_valve"
77 49
 
78 50
 # diningroom
79
-TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY = "shellies/ffe/diningroom/main_light"
80 51
 TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV = "videv/ffe/diningroom/main_light"
81
-TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG = "zigbee/ffe/diningroom/powerplug_floorlamp"
82 52
 TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV = "videv/ffe/diningroom/floorlamp"
83
-TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG = "zigbee/ffe/diningroom/garland"
84 53
 TOPIC_FFE_DININGROOM_GARLAND_VIDEV = "videv/ffe/diningroom/garland"
85
-TOPIC_FFE_DININGROOM_HEATING_VALVE_ZIGBEE = "zigbee/ffe/diningroom/heating_valve"
86 54
 TOPIC_FFE_DININGROOM_HEATING_VALVE_VIDEV = "videv/ffe/diningroom/heating_valve"
87 55
 
88 56
 # sleep
89
-TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY = "shellies/ffe/sleep/main_light"
90 57
 TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV = "videv/ffe/sleep/main_light"
91
-TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE = "zigbee/ffe/sleep/main_light"
92
-TOPIC_FFE_SLEEP_INPUT_DEVICE = "zigbee/ffe/sleep/input_device"
93
-TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE = "zigbee/ffe/sleep/bed_light_di"
94 58
 TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV = "videv/ffe/sleep/bed_light_di"
95
-TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG = "zigbee/ffe/sleep/bed_light_ma"
96 59
 TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV = "videv/ffe/sleep/bed_light_ma"
97 60
 TOPIC_FFE_SLEEP_ACTIVE_BRIGHTNESS_DEVICE_VIDEV = "videv/ffe/sleep/active_brightness_device"
98
-TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE = "zigbee/ffe/sleep/heating_valve"
99 61
 TOPIC_FFE_SLEEP_HEATING_VALVE_VIDEV = "videv/ffe/sleep/heating_valve"
100 62
 
101 63
 # livingroom
102
-TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY = "shellies/ffe/livingroom/main_light"
103 64
 TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV = "videv/ffe/livingroom/main_light"
104
-TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE = "zigbee/ffe/livingroom/main_light"
105
-TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE = "zigbee/ffe/livingroom/floorlamp_%d"
106 65
 TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV = "videv/ffe/livingroom/floorlamp"
107
-TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG = "zigbee/ffe/livingroom/powerplug_xmas-tree"
108 66
 TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV = "videv/ffe/livingroom/xmas_tree"
109
-TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG = "zigbee/ffe/livingroom/powerplug_xmas-star"
110
-TOPIC_FFE_LIVINGROOM_HEATING_VALVE_ZIGBEE = "zigbee/ffe/livingroom/heating_valve"
111 67
 TOPIC_FFE_LIVINGROOM_HEATING_VALVE_VIDEV = "videv/ffe/livingroom/heating_valve"
112 68
 
113 69
 
114 70
 # first floor east
115 71
 # floor
116
-TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY = "shellies/stw/stairway/main_light"
117 72
 TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV = "videv/stw/stairway/main_light"
118
-TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF = "zigbee/ffe/stairway/motion_sensor_ff"
119
-TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF = "zigbee/gfw/stairway/motion_sensor_gf"

Loading…
Cancel
Save