Просмотр исходного кода

split topic and devices

master
Dirk Alders 1 год назад
Родитель
Сommit
05f0f26141
4 измененных файлов: 460 добавлений и 535 удалений
  1. 0
    344
      __init__.py
  2. 230
    0
      devices.py
  3. 0
    191
      props.py
  4. 230
    0
      topic.py

+ 0
- 344
__init__.py Просмотреть файл

@@ -1,344 +0,0 @@
1
-
2
-#!/usr/bin/env python
3
-# -*- coding: utf-8 -*-
4
-#
5
-from devdi import props
6
-from devices import group
7
-import logging
8
-import sys
9
-
10
-try:
11
-    from config import APP_NAME as ROOT_LOGGER_NAME
12
-except ImportError:
13
-    ROOT_LOGGER_NAME = 'root'
14
-logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
15
-
16
-
17
-class base(dict):
18
-    def __init__(self, mqtt_client):
19
-        super().__init__(self)
20
-
21
-    def add(self, mqtt_client, stg, loc, roo, fun, dty, num=None, ot=None):
22
-        """Method to initilise a device
23
-
24
-        Args:
25
-            stg (numeric): Source transmittion group (see SIS_* in props)
26
-            loc (numeric): Location (see LOC_* in props)
27
-            roo (numeric): Room (see ROO_* in props)
28
-            fun (numeric): Function (see FUN_* in props)
29
-            dty (numeric): Device type (see DTP_* in props)
30
-            num (numeric): Device number in case of multiple devices
31
-        """
32
-        def get_device(dty, mqtt_client, topic, ot):
33
-            # Temporary to fit to current implementation
34
-            if ot != topic:
35
-                logger.error("Topic change for %s: Using this one: %s", topic, ot)
36
-                topic = ot
37
-            dev_class = props.dty_repr(dty)
38
-            if dev_class is None:
39
-                logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic)
40
-            else:
41
-                return dev_class(mqtt_client, topic)
42
-
43
-        topic = self.__topic__(stg, loc, roo, fun)
44
-        if num is None:
45
-            this_device = get_device(dty, mqtt_client, topic, ot)
46
-            if this_device is None:
47
-                logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic)
48
-            else:
49
-                self[topic] = this_device
50
-        else:
51
-            dg = []
52
-            for i in num:
53
-                device_topic = self.__topic__(stg, loc, roo, fun) + '_%d' % i
54
-                dg.append(get_device(dty, mqtt_client, device_topic, ot=ot % i))
55
-            self[topic] = group(*dg)
56
-
57
-    def get(self, stg, loc, roo, fun):
58
-        """Method to get a device
59
-
60
-        Args:
61
-            stg (numeric): Source transmittion group (see SIS_* in props)
62
-            loc (numeric): Location (see LOC_* in props)
63
-            roo (numeric): Room (see ROO_* in props)
64
-            fun (numeric): Function (see FUN_* in props)
65
-            num (numeric): Device number in case of multiple devices
66
-        """
67
-        topic = self.__topic__(stg, loc, roo, fun)
68
-        return self[topic]
69
-
70
-    def __topic__(self, stg, loc, roo, fun):
71
-        if stg in [props.STG_ZFE, props.STG_ZFW, props.STG_ZGW]:
72
-            # Temporary to fit to current implementation
73
-            return '/'.join([
74
-                props.stg_repr(stg),
75
-                props.roo_repr(roo),
76
-                props.fun_repr(fun)
77
-            ])
78
-        else:
79
-            return '/'.join([
80
-                props.stg_repr(stg),
81
-                props.loc_repr(loc),
82
-                props.roo_repr(roo),
83
-                props.fun_repr(fun)
84
-            ])
85
-
86
-
87
-class physical_devices(base):
88
-    """
89
-    Class to create and store physical smarthome devices
90
-    """
91
-
92
-    def __init__(self, mqtt_client):
93
-        super().__init__(self)
94
-        self.__init_gfw__(mqtt_client)
95
-        self.__init_ffw__(mqtt_client)
96
-        self.__init_ffe__(mqtt_client)
97
-        self.__init_stw__(mqtt_client)
98
-
99
-    def __init_gfw__(self, mqtt_client):
100
-        loc = props.LOC_GFW
101
-
102
-        # MARION
103
-        roo = props.ROO_MAR
104
-        #
105
-        # Temporary to fit to current implementation ###################################################
106
-        TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY = "shellies/gfw/marion/main_light"
107
-        TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE = "zigbee/gfw/marion/heating_valve"
108
-        # Temporary to fit to current implementation ###################################################
109
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1,
110
-                 ot=TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY)            # Shelly Main Light
111
-        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx,
112
-                 ot=TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
113
-
114
-        # FLOOR
115
-        roo = props.ROO_FLO
116
-        #
117
-        # Temporary to fit to current implementation ###################################################
118
-        TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY = "shellies/gfw/floor/main_light"
119
-        TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE = "zigbee/gfw/floor/main_light_%d"
120
-        # Temporary to fit to current implementation ###################################################
121
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1,
122
-                 ot=TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY)            # Shelly Main Light
123
-        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_LLI_SBT,
124
-                 range(1, 3), ot=TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE)         # Tradfri Main Light
125
-
126
-        # DIRK
127
-        roo = props.ROO_DIR
128
-        #
129
-        # Temporary to fit to current implementation ###################################################
130
-        TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY = "shellies/gfw/dirk/main_light"
131
-        TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE = "zigbee/gfw/dirk/main_light"
132
-        TOPIC_GFW_DIRK_INPUT_DEVICE = "zigbee/gfw/dirk/input_device"
133
-        TOPIC_GFW_DIRK_POWERPLUG = "my_apps/gfw/dirk/powerplug"
134
-        TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE = "zigbee/gfw/dirk/desk_light"
135
-        TOPIC_GFW_DIRK_AMPLIFIER_REMOTE = "my_apps/gfw/dirk/remote/RAS5"
136
-        TOPIC_GFW_DIRK_SPOTIFY = "my_apps/gfw/dirk/hifi/spotify"
137
-        TOPIC_GFW_DIRK_MPD = "my_apps/gfw/dirk/hifi/mpd"
138
-        TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE = "zigbee/gfw/dirk/heating_valve"
139
-        # Temporary to fit to current implementation ###################################################
140
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1,
141
-                 ot=TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY)            # Shelly Main Light
142
-        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT,
143
-                 ot=TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE)            # Tradfri Main Light
144
-        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_INP, props.DTY_TIN_5xx,
145
-                 ot=TOPIC_GFW_DIRK_INPUT_DEVICE)            # Tradfri Input Device 5 Buttons
146
-        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_MPP, props.DTY_MPP_4xx, ot=TOPIC_GFW_DIRK_POWERPLUG)            # My 4 port Powerplug
147
-        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_DEL, props.DTY_TLI_SBT, ot=TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE),  # Tradfri Desklight
148
-        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_RCA, props.DTY_MRE_xxx,
149
-                 ot=TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)            # Remote Control IR Amplifier
150
-        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASS, props.DTY_MAS_xxx, ot=TOPIC_GFW_DIRK_SPOTIFY)            # Audio status Spotify
151
-        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASM, props.DTY_MAS_xxx, ot=TOPIC_GFW_DIRK_MPD)            # Audio status MPD
152
-        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx,
153
-                 ot=TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
154
-
155
-    def __init_ffw__(self, mqtt_client):
156
-        loc = props.LOC_FFW
157
-        # JULIAN
158
-        roo = props.ROO_JUL
159
-        #
160
-        # Temporary to fit to current implementation ###################################################
161
-        TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY = "shellies/ffw/julian/main_light"
162
-        TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE = "zigbee/ffw/julian/main_light"
163
-        TOPIC_FFW_JULIAN_HEATING_VALVE_ZIGBEE = "zigbee/ffw/julian/heating_valve"
164
-        # Temporary to fit to current implementation ###################################################
165
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1,
166
-                 ot=TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY)            # Shelly Main Light
167
-        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT,
168
-                 ot=TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE)            # Tradfri Main Light
169
-        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx,
170
-                 ot=TOPIC_FFW_JULIAN_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
171
-
172
-        # BATH
173
-        roo = props.ROO_BAT
174
-        #
175
-        # Temporary to fit to current implementation
176
-        # Temporary to fit to current implementation ###################################################
177
-        TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE = "zigbee/ffw/bath/heating_valve"
178
-        # Temporary to fit to current implementation ###################################################
179
-        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx,
180
-                 ot=TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
181
-
182
-        # LIVINGROOM
183
-        roo = props.ROO_LIV
184
-        #
185
-        # Temporary to fit to current implementation ###################################################
186
-        TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY = "shellies/ffw/livingroom/main_light"
187
-        TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE = "zigbee/ffw/livingroom/main_light"
188
-        # Temporary to fit to current implementation ###################################################
189
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1,
190
-                 ot=TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY)            # Shelly Main Light
191
-        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT,
192
-                 ot=TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE)            # Tradfri Main Light
193
-
194
-        # SLEEP
195
-        roo = props.ROO_SLP
196
-        #
197
-        # Temporary to fit to current implementation ###################################################
198
-        TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY = "shellies/ffw/sleep/main_light"
199
-        TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE = "zigbee/ffw/sleep/main_light"
200
-        TOPIC_FFW_SLEEP_HEATING_VALVE_ZIGBEE = "zigbee/ffw/sleep/heating_valve"
201
-        # Temporary to fit to current implementation ###################################################
202
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1,
203
-                 ot=TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY)            # Shelly Main Light
204
-        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBx,
205
-                 ot=TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE)            # Tradfri Main Light
206
-        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx,
207
-                 ot=TOPIC_FFW_SLEEP_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
208
-
209
-    def __init_ffe__(self, mqtt_client):
210
-        loc = props.LOC_FFE
211
-        # FLOOR
212
-        roo = props.ROO_FLO
213
-        #
214
-        # Temporary to fit to current implementation ###################################################
215
-        TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY = "shellies/ffe/floor/main_light"
216
-        # Temporary to fit to current implementation ###################################################
217
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1,
218
-                 ot=TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY)            # Shelly Main Light
219
-
220
-        # KITCHEN
221
-        roo = props.ROO_KIT
222
-        #
223
-        # Temporary to fit to current implementation ###################################################
224
-        TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY = "shellies/ffe/kitchen/main_light"
225
-        TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY = "shellies/ffe/kitchen/circulation_pump"
226
-        TOPIC_FFE_KITCHEN_HEATING_VALVE_ZIGBEE = "zigbee/ffe/kitchen/heating_valve"
227
-        # Temporary to fit to current implementation ###################################################
228
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1,
229
-                 ot=TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY)            # Shelly Main Light
230
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_CIR, props.DTY_SHY_SW1,
231
-                 ot=TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY)            # Shelly Main Light
232
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx,
233
-                 ot=TOPIC_FFE_KITCHEN_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
234
-
235
-        # DININGROOM
236
-        roo = props.ROO_DIN
237
-        #
238
-        # Temporary to fit to current implementation ###################################################
239
-        TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY = "shellies/ffe/diningroom/main_light"
240
-        TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG = "zigbee/ffe/diningroom/powerplug_floorlamp"
241
-        TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG = "zigbee/ffe/diningroom/garland"
242
-        TOPIC_FFE_DININGROOM_HEATING_VALVE_ZIGBEE = "zigbee/ffe/diningroom/heating_valve"
243
-        # Temporary to fit to current implementation ###################################################
244
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1,
245
-                 ot=TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY)            # Shelly Main Light
246
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_SPP_SW1,
247
-                 ot=TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)            # Powerplug Floor Light
248
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_GAR, props.DTY_SPP_SW1,
249
-                 ot=TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)            # Powerplug Garland
250
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx,
251
-                 ot=TOPIC_FFE_DININGROOM_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
252
-
253
-        # SLEEP
254
-        roo = props.ROO_SLP
255
-        #
256
-        # Temporary to fit to current implementation ###################################################
257
-        TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY = "shellies/ffe/sleep/main_light"
258
-        TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE = "zigbee/ffe/sleep/main_light"
259
-        TOPIC_FFE_SLEEP_INPUT_DEVICE = "zigbee/ffe/sleep/input_device"
260
-        TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE = "zigbee/ffe/sleep/bed_light_di"
261
-        TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG = "zigbee/ffe/sleep/bed_light_ma"
262
-        TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE = "zigbee/ffe/sleep/heating_valve"
263
-        # Temporary to fit to current implementation ###################################################
264
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1,
265
-                 ot=TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY)            # Shelly Main Light
266
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT,
267
-                 ot=TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE)            # Tradfri Main Light
268
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_INP, props.DTY_TIN_5xx,
269
-                 ot=TOPIC_FFE_SLEEP_INPUT_DEVICE)            # Tradfri Input Device 5 Buttons
270
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLD, props.DTY_TLI_SBx,
271
-                 ot=TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE)            # Tradfri Bed Light Dirk
272
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLM, props.DTY_SPP_SW1,
273
-                 ot=TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)            # Powerplug Bed Light Marion
274
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx,
275
-                 ot=TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
276
-
277
-        # LIVINGROOM
278
-        roo = props.ROO_LIV
279
-        #
280
-        # Temporary to fit to current implementation ###################################################
281
-        TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY = "shellies/ffe/livingroom/main_light"
282
-        TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE = "zigbee/ffe/livingroom/main_light"
283
-        TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE = "zigbee/ffe/livingroom/floorlamp_%d"
284
-        TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG = "zigbee/ffe/livingroom/powerplug_xmas-tree"
285
-        TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG = "zigbee/ffe/livingroom/powerplug_xmas-star"
286
-        TOPIC_FFE_LIVINGROOM_HEATING_VALVE_ZIGBEE = "zigbee/ffe/livingroom/heating_valve"
287
-        # Temporary to fit to current implementation ###################################################
288
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1,
289
-                 ot=TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY)                 # Shelly Main Light
290
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT,
291
-                 ot=TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE)                 # Tradfri Main Light
292
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_TLI_SBT,
293
-                 range(1, 7), ot=TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE)    # Tradfri Main Light
294
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XTR, props.DTY_SPP_SW1,
295
-                 ot=TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)               # Tradfri Main Light
296
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XST, props.DTY_SPP_SW1,
297
-                 ot=TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)               # Tradfri Main Light
298
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx,
299
-                 ot=TOPIC_FFE_LIVINGROOM_HEATING_VALVE_ZIGBEE)              # Brennenstuhl Heatingvalve
300
-
301
-    def __init_stw__(self, mqtt_client):
302
-        loc = props.LOC_STW
303
-        # FLOOR
304
-        #
305
-        # Temporary to fit to current implementation ###################################################
306
-        TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY = "shellies/stw/stairway/main_light"
307
-        TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF = "zigbee/ffe/stairway/motion_sensor_ff"
308
-        TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF = "zigbee/gfw/stairway/motion_sensor_gf"
309
-        # Temporary to fit to current implementation ###################################################
310
-        self.add(mqtt_client, props.STG_SHE, loc, props.ROO_STF, props.FUN_MAL, props.DTY_SHY_SW1,
311
-                 ot=TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY)            # Shelly Main Light
312
-        self.add(mqtt_client, props.STG_ZFE, loc, props.ROO_STF, props.FUN_MSE, props.DTY_SMS_xxx,
313
-                 ot=TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF)    # Motion Sensor First Floor
314
-        self.add(mqtt_client, props.STG_ZGW, loc, props.ROO_STG, props.FUN_MSE, props.DTY_SMS_xxx,
315
-                 ot=TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF)            # Motion Sensor Ground Floor
316
-
317
-
318
-class videv_devices(base):
319
-    """
320
-    Class to create and store videv smarthome devices
321
-    """
322
-
323
-    def __init__(self, mqtt_client):
324
-        super().__init__(self)
325
-        self.__init_gfw__(mqtt_client)
326
-        self.__init_ffw__(mqtt_client)
327
-        self.__init_ffe__(mqtt_client)
328
-        self.__init_stw__(mqtt_client)
329
-
330
-    def __init_gfw__(self, mqtt_client):
331
-        loc = props.LOC_GFW
332
-        # TODO: Add devices
333
-
334
-    def __init_ffw__(self, mqtt_client):
335
-        loc = props.LOC_FFW
336
-        # TODO: Add devices
337
-
338
-    def __init_ffe__(self, mqtt_client):
339
-        loc = props.LOC_FFE
340
-        # TODO: Add devices
341
-
342
-    def __init_stw__(self, mqtt_client):
343
-        loc = props.LOC_STW
344
-        # TODO: Add devices

+ 230
- 0
devices.py Просмотреть файл

@@ -0,0 +1,230 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#
4
+from devdi import topic as props
5
+from devdi.topic import topic_by_props
6
+import devices
7
+import logging
8
+import sys
9
+
10
+try:
11
+    from config import APP_NAME as ROOT_LOGGER_NAME
12
+except ImportError:
13
+    ROOT_LOGGER_NAME = 'root'
14
+logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
15
+
16
+
17
+class base(dict):
18
+    def __init__(self, mqtt_client):
19
+        super().__init__(self)
20
+
21
+    def __dty_repr__(self, dty):
22
+        return {
23
+            props.DTY_SHY_SW1: devices.shelly_sw1,
24
+            props.DTY_TLI_Sxx: devices.tradfri_sw,
25
+            props.DTY_TLI_SBx: devices.tradfri_sw_br,
26
+            props.DTY_TLI_SBT: devices.tradfri_sw_br_ct,
27
+            props.DTY_TIN_5xx: devices.tradfri_button,
28
+            props.DTY_LLI_SBT: devices.livarno_sw_br_ct,
29
+            props.DTY_BVL_xxx: devices.brennenstuhl_heatingvalve,
30
+            props.DTY_SPP_SW1: devices.silvercrest_powerplug,
31
+            props.DTY_SMS_xxx: devices.silvercrest_motion_sensor,
32
+            props.DTY_MPP_4xx: devices.my_powerplug,
33
+            props.DTY_MAS_xxx: devices.audio_status,
34
+            props.DTY_MRE_xxx: devices.remote,
35
+        }.get(dty)
36
+
37
+    def add(self, mqtt_client, stg, loc, roo, fun, dty, num=None):
38
+        """Method to initilise a device
39
+
40
+        Args:
41
+            stg (numeric): Source transmittion group (see SIS_* in props)
42
+            loc (numeric): Location (see LOC_* in props)
43
+            roo (numeric): Room (see ROO_* in props)
44
+            fun (numeric): Function (see FUN_* in props)
45
+            dty (numeric): Device type (see DTP_* in props)
46
+            num (numeric): Device number in case of multiple devices
47
+        """
48
+        def get_device(dty, mqtt_client, topic):
49
+            dev_class = self.__dty_repr__(dty)
50
+            if dev_class is None:
51
+                logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic)
52
+            else:
53
+                return dev_class(mqtt_client, topic)
54
+
55
+        topic = str(topic_by_props(stg, loc, roo, fun))
56
+        if num is None:
57
+            this_device = get_device(dty, mqtt_client, topic)
58
+            if this_device is None:
59
+                logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic)
60
+            else:
61
+                self[topic] = this_device
62
+        else:
63
+            dg = []
64
+            for i in num:
65
+                device_topic = topic + '_%d' % i
66
+                dg.append(get_device(dty, mqtt_client, device_topic))
67
+            self[topic] = devices.group(*dg)
68
+
69
+    def get(self, stg, loc, roo, fun):
70
+        """Method to get a device
71
+
72
+        Args:
73
+            stg (numeric): Source transmittion group (see SIS_* in props)
74
+            loc (numeric): Location (see LOC_* in props)
75
+            roo (numeric): Room (see ROO_* in props)
76
+            fun (numeric): Function (see FUN_* in props)
77
+            num (numeric): Device number in case of multiple devices
78
+        """
79
+        topic = self.__topic__(stg, loc, roo, fun)
80
+        return self[topic]
81
+
82
+
83
+class physical_devices(base):
84
+    """
85
+    Class to create and store physical smarthome devices
86
+    """
87
+
88
+    def __init__(self, mqtt_client):
89
+        super().__init__(self)
90
+        self.__init_gfw__(mqtt_client)
91
+        self.__init_ffw__(mqtt_client)
92
+        self.__init_ffe__(mqtt_client)
93
+        self.__init_stw__(mqtt_client)
94
+
95
+    def __init_gfw__(self, mqtt_client):
96
+        loc = props.LOC_GFW
97
+
98
+        # MARION
99
+        roo = props.ROO_MAR
100
+        #
101
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
102
+        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
103
+
104
+        # FLOOR
105
+        roo = props.ROO_FLO
106
+        #
107
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
108
+        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_LLI_SBT)            # Tradfri Main Light
109
+
110
+        # DIRK
111
+        roo = props.ROO_DIR
112
+        #
113
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
114
+        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT)            # Tradfri Main Light
115
+        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_INP, props.DTY_TIN_5xx)            # Tradfri Input Device 5 Buttons
116
+        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_MPP, props.DTY_MPP_4xx)            # My 4 port Powerplug
117
+        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_DEL, props.DTY_TLI_SBT)            # Tradfri Desklight
118
+        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_RCA, props.DTY_MRE_xxx)            # Remote Control IR Amplifier
119
+        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASS, props.DTY_MAS_xxx)            # Audio status Spotify
120
+        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASM, props.DTY_MAS_xxx)            # Audio status MPD
121
+        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
122
+
123
+        # GARDEN
124
+        self.add(mqtt_client, props.STG_ZGW, props.LOC_GAR, props.ROO_GAR, props.FUN_GAR, props.DTY_SPP_SW1)
125
+
126
+    def __init_ffw__(self, mqtt_client):
127
+        loc = props.LOC_FFW
128
+        # JULIAN
129
+        roo = props.ROO_JUL
130
+        #
131
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
132
+        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT)            # Tradfri Main Light
133
+        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
134
+
135
+        # BATH
136
+        roo = props.ROO_BAT
137
+        #
138
+        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
139
+
140
+        # LIVINGROOM
141
+        roo = props.ROO_LIV
142
+        #
143
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
144
+        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT)            # Tradfri Main Light
145
+
146
+        # SLEEP
147
+        roo = props.ROO_SLP
148
+        #
149
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
150
+        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBx)            # Tradfri Main Light
151
+        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
152
+
153
+    def __init_ffe__(self, mqtt_client):
154
+        loc = props.LOC_FFE
155
+        # FLOOR
156
+        roo = props.ROO_FLO
157
+        #
158
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
159
+
160
+        # KITCHEN
161
+        roo = props.ROO_KIT
162
+        #
163
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
164
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_CIR, props.DTY_SHY_SW1)            # Shelly Main Light
165
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
166
+
167
+        # DININGROOM
168
+        roo = props.ROO_DIN
169
+        #
170
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
171
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_SPP_SW1)            # Powerplug Floor Light
172
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_GAR, props.DTY_SPP_SW1)            # Powerplug Garland
173
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
174
+
175
+        # SLEEP
176
+        roo = props.ROO_SLP
177
+        #
178
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
179
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT)            # Tradfri Main Light
180
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_INP, props.DTY_TIN_5xx)            # Tradfri Input Device 5 Buttons
181
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLD, props.DTY_TLI_SBx)            # Tradfri Bed Light Dirk
182
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLM, props.DTY_SPP_SW1)            # Powerplug Bed Light Marion
183
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
184
+
185
+        # LIVINGROOM
186
+        roo = props.ROO_LIV
187
+        #
188
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
189
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT)            # Tradfri Main Light
190
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_TLI_SBT)            # Tradfri Main Light
191
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XTR, props.DTY_SPP_SW1)            # Tradfri Main Light
192
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XST, props.DTY_SPP_SW1)            # Tradfri Main Light
193
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
194
+
195
+    def __init_stw__(self, mqtt_client):
196
+        loc = props.LOC_STW
197
+        # FLOOR
198
+        #
199
+        self.add(mqtt_client, props.STG_SHE, loc, props.ROO_STF, props.FUN_MAL, props.DTY_SHY_SW1)  # Shelly Main Light
200
+        self.add(mqtt_client, props.STG_ZFE, loc, props.ROO_STF, props.FUN_MSE, props.DTY_SMS_xxx)  # Motion Sensor First Floor
201
+        self.add(mqtt_client, props.STG_ZGW, loc, props.ROO_STG, props.FUN_MSE, props.DTY_SMS_xxx)  # Motion Sensor Ground Floor
202
+
203
+
204
+class videv_devices(base):
205
+    """
206
+    Class to create and store videv smarthome devices
207
+    """
208
+
209
+    def __init__(self, mqtt_client):
210
+        super().__init__(self)
211
+        self.__init_gfw__(mqtt_client)
212
+        self.__init_ffw__(mqtt_client)
213
+        self.__init_ffe__(mqtt_client)
214
+        self.__init_stw__(mqtt_client)
215
+
216
+    def __init_gfw__(self, mqtt_client):
217
+        loc = props.LOC_GFW
218
+        # TODO: Add devices
219
+
220
+    def __init_ffw__(self, mqtt_client):
221
+        loc = props.LOC_FFW
222
+        # TODO: Add devices
223
+
224
+    def __init_ffe__(self, mqtt_client):
225
+        loc = props.LOC_FFE
226
+        # TODO: Add devices
227
+
228
+    def __init_stw__(self, mqtt_client):
229
+        loc = props.LOC_STW
230
+        # TODO: Add devices

+ 0
- 191
props.py Просмотреть файл

@@ -1,191 +0,0 @@
1
-import devices
2
-
3
-
4
-#
5
-# Device TYpe definitions
6
-#
7
-DTY_SHY_SW1 = 1
8
-""" Shelly """
9
-DTY_TLI_Sxx = 2
10
-""" Tradfri Light (Switching only) """
11
-DTY_TLI_SBx = 3
12
-""" Tradfri Light (Switching and Brightnes) """
13
-DTY_TLI_SBT = 4
14
-""" Tradfri Light (Switching, Brightnes and Colortemperature) """
15
-DTY_TIN_5xx = 5
16
-""" Tradfri Input Device (5 Buttons) """
17
-DTY_LLI_SBT = 6
18
-""" Livarno Light (Switching, Brightnes and Colortemperature) """
19
-DTY_BVL_xxx = 7
20
-""" Brennenstuhl Heatingvalve """
21
-DTY_SPP_SW1 = 8
22
-""" Silvercrest Powerplug """
23
-DTY_SMS_xxx = 9
24
-""" Silvercrest Motion Sensor """
25
-DTY_MPP_4xx = 10
26
-""" My Powerplug (4 plugs) """
27
-DTY_MAS_xxx = 11
28
-""" My Audio status (MPD) """
29
-DTY_MRE_xxx = 12
30
-""" My Remote control """
31
-def dty_repr(dty):
32
-    return {
33
-        DTY_SHY_SW1: devices.shelly_sw1,
34
-        DTY_TLI_Sxx: devices.tradfri_sw,
35
-        DTY_TLI_SBx: devices.tradfri_sw_br,
36
-        DTY_TLI_SBT: devices.tradfri_sw_br_ct,
37
-        DTY_TIN_5xx: devices.tradfri_button,
38
-        DTY_LLI_SBT: devices.livarno_sw_br_ct,
39
-        DTY_BVL_xxx: devices.brennenstuhl_heatingvalve,
40
-        DTY_SPP_SW1: devices.silvercrest_powerplug,
41
-        DTY_SMS_xxx: devices.silvercrest_motion_sensor,
42
-        DTY_MPP_4xx: devices.my_powerplug,
43
-        DTY_MAS_xxx: devices.audio_status,
44
-        DTY_MRE_xxx: devices.remote,
45
-    }.get(dty)
46
-
47
-#
48
-# Source Transmission Group
49
-#
50
-STG_ZGW = 1
51
-""" Zigbee ground floor west """
52
-STG_ZFW = 2
53
-""" Zigbee first floor west """
54
-STG_ZFE = 3
55
-""" Zigbee first floor east """
56
-STG_SHE = 4
57
-""" Shellies """
58
-STG_MYA = 5
59
-""" My Applications """
60
-def stg_repr(stg):
61
-    return {
62
-        STG_ZGW: 'zigbee/gfw',  # TODO: -> zigbee_gfw
63
-        STG_ZFW: 'zigbee/ffw',  # TODO: -> zigbee_ffw
64
-        STG_ZFE: 'zigbee/ffe',  # TODO: -> zigbee_ffe
65
-        STG_SHE: 'shellies',
66
-        STG_MYA: 'my_apps',
67
-    }.get(stg)
68
-
69
-#
70
-# LOCation
71
-#
72
-LOC_GFW = 1
73
-""" Grounf floor west """
74
-LOC_GFE = 2
75
-""" Ground floor east """
76
-LOC_STW = 3
77
-""" Stairway """
78
-LOC_FFW = 4
79
-""" First floor west """
80
-LOC_FFE = 5
81
-""" First floor east """
82
-LOC_STW = 6
83
-""" Stairways """
84
-def loc_repr(loc):
85
-    return {
86
-        LOC_GFW: 'gfw',
87
-        LOC_GFE: 'gfe',
88
-        LOC_STW: 'stw',
89
-        LOC_FFW: 'ffw',
90
-        LOC_FFE: 'ffe',
91
-        LOC_STW: 'stw',
92
-    }.get(loc)
93
-
94
-#
95
-# ROOms
96
-#
97
-ROO_DIN = 1
98
-""" Diningroom """
99
-ROO_KIT = 2
100
-""" Kitchen """
101
-ROO_LIV = 3
102
-""" Livingroom """
103
-ROO_FLO = 4
104
-""" Floor """
105
-ROO_SLP = 5
106
-""" Sleep """
107
-ROO_BAT = 6
108
-""" Bath """
109
-ROO_DIR = 7
110
-""" Dirk """
111
-ROO_MAR = 8
112
-""" Marion """
113
-ROO_JUL = 9
114
-""" Julian """
115
-ROO_STG = 10
116
-""" ground floor """
117
-ROO_STF = 11
118
-""" first floor """
119
-def roo_repr(roo):
120
-    return {
121
-        ROO_DIN: 'diningroom',
122
-        ROO_KIT: 'kitchen',
123
-        ROO_LIV: 'livingroom',
124
-        ROO_FLO: 'floor',
125
-        ROO_SLP: 'sleep',
126
-        ROO_BAT: 'bath',
127
-        ROO_DIR: 'dirk',
128
-        ROO_MAR: 'marion',
129
-        ROO_JUL: 'julian',
130
-        ROO_STG: 'groundfloor',
131
-        ROO_STF: 'firstfloor'
132
-    }.get(roo)
133
-
134
-#
135
-# FUNctions
136
-#
137
-FUN_MAL = 1
138
-""" Main Light """
139
-FUN_DEL = 2
140
-""" Desk Light """
141
-FUN_FLL = 3
142
-""" Floor Light """
143
-FUN_BLD = 4
144
-""" Bed Light Dirk """
145
-FUN_BLM = 5
146
-""" Bed Light Marion """
147
-FUN_HEA = 6
148
-""" Heating """
149
-FUN_MPP = 7
150
-""" Multiple Powerplugs """
151
-FUN_INP = 8
152
-""" Input Device """
153
-FUN_CIR = 9
154
-""" Circulation Pump """
155
-FUN_GAR = 10
156
-""" Garland """
157
-FUN_XTR = 11
158
-""" X-Mas Tree """
159
-FUN_XST = 12
160
-""" X-Mas Star """
161
-FUN_MSE = 13
162
-""" Motion Sensor """
163
-FUN_RCA = 14
164
-""" Remote Control Amplifier """
165
-FUN_RCC = 15
166
-""" Remote Control CD-Player """
167
-FUN_ASS = 16
168
-""" Audio status spotify """
169
-FUN_ASM = 17
170
-""" Audio status mpd """
171
-
172
-def fun_repr(fun):
173
-    return {
174
-        FUN_MAL: 'main_light',
175
-        FUN_DEL: 'desk_light',
176
-        FUN_FLL: 'floor_light',
177
-        FUN_BLD: 'bed_light_di',
178
-        FUN_BLM: 'bed_light_ma',
179
-        FUN_HEA: 'heating_valve',
180
-        FUN_MPP: 'powerplug',
181
-        FUN_INP: 'input_device',
182
-        FUN_CIR: 'circulation_pump',
183
-        FUN_GAR: 'garland',
184
-        FUN_XTR: 'xmas-tree',
185
-        FUN_XST: 'xmas-star',
186
-        FUN_MSE: 'motion_sensor',
187
-        FUN_RCA: 'remote_ctrl_amp',
188
-        FUN_RCC: 'remote_ctrl_cd',
189
-        FUN_ASS: 'audio_status_spotify',
190
-        FUN_ASM: 'audio_status_mpd',
191
-    }.get(fun)

+ 230
- 0
topic.py Просмотреть файл

@@ -0,0 +1,230 @@
1
+from collections import UserString
2
+
3
+#
4
+# Device TYpe definitions
5
+#
6
+DTY_SHY_SW1 = 1
7
+""" Shelly """
8
+DTY_TLI_Sxx = 2
9
+""" Tradfri Light (Switching only) """
10
+DTY_TLI_SBx = 3
11
+""" Tradfri Light (Switching and Brightnes) """
12
+DTY_TLI_SBT = 4
13
+""" Tradfri Light (Switching, Brightnes and Colortemperature) """
14
+DTY_TIN_5xx = 5
15
+""" Tradfri Input Device (5 Buttons) """
16
+DTY_LLI_SBT = 6
17
+""" Livarno Light (Switching, Brightnes and Colortemperature) """
18
+DTY_BVL_xxx = 7
19
+""" Brennenstuhl Heatingvalve """
20
+DTY_SPP_SW1 = 8
21
+""" Silvercrest Powerplug """
22
+DTY_SMS_xxx = 9
23
+""" Silvercrest Motion Sensor """
24
+DTY_MPP_4xx = 10
25
+""" My Powerplug (4 plugs) """
26
+DTY_MAS_xxx = 11
27
+""" My Audio status (MPD) """
28
+DTY_MRE_xxx = 12
29
+""" My Remote control """
30
+
31
+
32
+#
33
+# Source Transmission Group
34
+#
35
+STG_ZGW = 1
36
+""" Zigbee ground floor west """
37
+STG_ZFW = 2
38
+""" Zigbee first floor west """
39
+STG_ZFE = 3
40
+""" Zigbee first floor east """
41
+STG_SHE = 4
42
+""" Shellies """
43
+STG_MYA = 5
44
+""" My Applications """
45
+
46
+
47
+#
48
+# LOCation
49
+#
50
+LOC_GFW = 1
51
+""" Grounf floor west """
52
+LOC_GFE = 2
53
+""" Ground floor east """
54
+LOC_STW = 3
55
+""" Stairway """
56
+LOC_FFW = 4
57
+""" First floor west """
58
+LOC_FFE = 5
59
+""" First floor east """
60
+LOC_STW = 6
61
+""" Stairways """
62
+LOC_GAR = 7
63
+
64
+
65
+#
66
+# ROOms
67
+#
68
+ROO_DIN = 1
69
+""" Diningroom """
70
+ROO_KIT = 2
71
+""" Kitchen """
72
+ROO_LIV = 3
73
+""" Livingroom """
74
+ROO_FLO = 4
75
+""" Floor """
76
+ROO_SLP = 5
77
+""" Sleep """
78
+ROO_BAT = 6
79
+""" Bath """
80
+ROO_DIR = 7
81
+""" Dirk """
82
+ROO_MAR = 8
83
+""" Marion """
84
+ROO_JUL = 9
85
+""" Julian """
86
+ROO_STG = 10
87
+""" ground floor """
88
+ROO_STF = 11
89
+""" first floor """
90
+ROO_GAR = 12
91
+""" garden """
92
+
93
+
94
+#
95
+# FUNctions
96
+#
97
+FUN_MAL = 1
98
+""" Main Light """
99
+FUN_DEL = 2
100
+""" Desk Light """
101
+FUN_FLL = 3
102
+""" Floor Light """
103
+FUN_BLD = 4
104
+""" Bed Light Dirk """
105
+FUN_BLM = 5
106
+""" Bed Light Marion """
107
+FUN_HEA = 6
108
+""" Heating """
109
+FUN_MPP = 7
110
+""" Multiple Powerplugs """
111
+FUN_INP = 8
112
+""" Input Device """
113
+FUN_CIR = 9
114
+""" Circulation Pump """
115
+FUN_GAR = 10
116
+""" Garland """
117
+FUN_XTR = 11
118
+""" X-Mas Tree """
119
+FUN_XST = 12
120
+""" X-Mas Star """
121
+FUN_MSE = 13
122
+""" Motion Sensor """
123
+FUN_RCA = 14
124
+""" Remote Control Amplifier """
125
+FUN_RCC = 15
126
+""" Remote Control CD-Player """
127
+FUN_ASS = 16
128
+""" Audio status spotify """
129
+FUN_ASM = 17
130
+""" Audio status mpd """
131
+
132
+
133
+class topic_by_props(UserString):
134
+    def __init__(self, stg, loc, roo, fun):
135
+        if stg in [STG_ZFE, STG_ZFW, STG_ZGW]:
136
+            # TODO: Temporary to fit to current implementation
137
+            topic = '/'.join([
138
+                self.__stg_repr__(stg),
139
+                self.__roo_repr__(roo),
140
+                self.__fun_repr__(fun)
141
+            ])
142
+        else:
143
+            topic = '/'.join([
144
+                self.__stg_repr__(stg),
145
+                self.__loc_repr__(loc),
146
+                self.__roo_repr__(roo),
147
+                self.__fun_repr__(fun)
148
+            ])
149
+
150
+        UserString.__init__(self, self.__tmp_old_topics__(stg, loc, roo, fun) or topic)
151
+
152
+    def __tmp_old_topics__(self, stg, loc, roo, fun):
153
+        # TODO: Temporary to fit to current implementation
154
+        if stg == STG_MYA and loc == LOC_GFW and roo == ROO_DIR and fun == FUN_RCA:
155
+            return "my_apps/gfw/dirk/remote/RAS5"
156
+        elif stg == STG_MYA and loc == LOC_GFW and roo == ROO_DIR and fun == FUN_ASS:
157
+            return "my_apps/gfw/dirk/hifi/spotify"
158
+        elif stg == STG_MYA and loc == LOC_GFW and roo == ROO_DIR and fun == FUN_ASM:
159
+            return "my_apps/gfw/dirk/hifi/mpd"
160
+        elif stg == STG_ZFE and loc == LOC_FFE and roo == ROO_DIN and fun == FUN_FLL:
161
+            return "zigbee/ffe/diningroom/powerplug_floorlamp"
162
+        elif stg == STG_ZFE and loc == LOC_FFE and roo == ROO_LIV and fun == FUN_FLL:
163
+            return "zigbee/ffe/livingroom/floorlamp"
164
+        elif stg == STG_ZFE and loc == LOC_FFE and roo == ROO_LIV and fun == FUN_XTR:
165
+            return "zigbee/ffe/livingroom/powerplug_xmas-tree"
166
+        elif stg == STG_ZFE and loc == LOC_FFE and roo == ROO_LIV and fun == FUN_XST:
167
+            return "zigbee/ffe/livingroom/powerplug_xmas-star"
168
+        elif stg == STG_SHE and loc == LOC_STW and roo == ROO_STF and fun == FUN_MAL:
169
+            return "shellies/stw/stairway/main_light"
170
+        elif stg == STG_ZFE and loc == LOC_STW and roo == ROO_STF and fun == FUN_MSE:
171
+            return "zigbee/ffe/stairway/motion_sensor_ff"
172
+        elif stg == STG_ZGW and loc == LOC_STW and roo == ROO_STG and fun == FUN_MSE:
173
+            return "zigbee/gfw/stairway/motion_sensor_gf"
174
+
175
+    def __stg_repr__(self, stg):
176
+        return {
177
+            STG_ZGW: 'zigbee/gfw',  # TODO: -> zigbee_gfw
178
+            STG_ZFW: 'zigbee/ffw',  # TODO: -> zigbee_ffw
179
+            STG_ZFE: 'zigbee/ffe',  # TODO: -> zigbee_ffe
180
+            STG_SHE: 'shellies',
181
+            STG_MYA: 'my_apps',
182
+        }.get(stg)
183
+
184
+    def __loc_repr__(self, loc):
185
+        return {
186
+            LOC_GFW: 'gfw',
187
+            LOC_GFE: 'gfe',
188
+            LOC_STW: 'stw',
189
+            LOC_FFW: 'ffw',
190
+            LOC_FFE: 'ffe',
191
+            LOC_STW: 'stw',
192
+            LOC_GAR: 'gar',
193
+        }.get(loc)
194
+
195
+    def __roo_repr__(self, roo):
196
+        return {
197
+            ROO_DIN: 'diningroom',
198
+            ROO_KIT: 'kitchen',
199
+            ROO_LIV: 'livingroom',
200
+            ROO_FLO: 'floor',
201
+            ROO_SLP: 'sleep',
202
+            ROO_BAT: 'bath',
203
+            ROO_DIR: 'dirk',
204
+            ROO_MAR: 'marion',
205
+            ROO_JUL: 'julian',
206
+            ROO_STG: 'groundfloor',
207
+            ROO_STF: 'firstfloor',
208
+            ROO_GAR: 'garden',
209
+        }.get(roo)
210
+
211
+    def __fun_repr__(self, fun):
212
+        return {
213
+            FUN_MAL: 'main_light',
214
+            FUN_DEL: 'desk_light',
215
+            FUN_FLL: 'floor_light',
216
+            FUN_BLD: 'bed_light_di',
217
+            FUN_BLM: 'bed_light_ma',
218
+            FUN_HEA: 'heating_valve',
219
+            FUN_MPP: 'powerplug',
220
+            FUN_INP: 'input_device',
221
+            FUN_CIR: 'circulation_pump',
222
+            FUN_GAR: 'garland',
223
+            FUN_XTR: 'xmas-tree',
224
+            FUN_XST: 'xmas-star',
225
+            FUN_MSE: 'motion_sensor',
226
+            FUN_RCA: 'remote_ctrl_amp',
227
+            FUN_RCC: 'remote_ctrl_cd',
228
+            FUN_ASS: 'audio_status_spotify',
229
+            FUN_ASM: 'audio_status_mpd',
230
+        }.get(fun)

Загрузка…
Отмена
Сохранить