ソースを参照

Adaption to support currently used topics

master
Dirk Alders 1年前
コミット
6d41c39ee3
2個のファイルの変更173行の追加87行の削除
  1. 159
    79
      __init__.py
  2. 14
    8
      props.py

+ 159
- 79
__init__.py ファイルの表示

@@ -3,6 +3,7 @@
3 3
 # -*- coding: utf-8 -*-
4 4
 #
5 5
 from devdi import props
6
+from devices import group
6 7
 import logging
7 8
 import sys
8 9
 
@@ -20,124 +21,189 @@ class devices(dict):
20 21
 
21 22
     def __init__(self, mqtt_client):
22 23
         dict.__init__(self)
23
-        #######
24
-        # GFW #
25
-        #######
24
+        self.__init_gfw__(mqtt_client)
25
+        self.__init_ffw__(mqtt_client)
26
+        self.__init_ffe__(mqtt_client)
27
+        self.__init_stw__(mqtt_client)
28
+    
29
+    def __init_gfw__(self, mqtt_client):
26 30
         loc = props.LOC_GFW
27 31
 
28 32
         # MARION
29 33
         roo = props.ROO_MAR
30 34
         #
31
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
32
-        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
35
+        # Temporary to fit to current implementation ###################################################
36
+        TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY = "shellies/gfw/marion/main_light"
37
+        TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE = "zigbee/gfw/marion/heating_valve"
38
+        # Temporary to fit to current implementation ###################################################
39
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, ot=TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY)            # Shelly Main Light
40
+        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, ot=TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
33 41
 
34 42
         # FLOOR
35 43
         roo = props.ROO_FLO
36 44
         #
37
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
38
-        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_LLI_SBT, 1)         # Tradfri Main Light
39
-        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_LLI_SBT, 2)         # Tradfri Main Light
45
+        # Temporary to fit to current implementation ###################################################
46
+        TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY = "shellies/gfw/floor/main_light"
47
+        TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE = "zigbee/gfw/floor/main_light_%d"
48
+        # Temporary to fit to current implementation ###################################################
49
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, ot=TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY)            # Shelly Main Light
50
+        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_LLI_SBT, range(1,3), ot=TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE)         # Tradfri Main Light
40 51
 
41 52
         # DIRK
42 53
         roo = props.ROO_DIR
43 54
         #
44
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
45
-        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT)            # Tradfri Main Light
46
-        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_CTR, props.DTY_TIN_5xx)            # Tradfri Input Device 5 Buttons
47
-        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_MPP, props.DTY_MPP_4xx)            # My 4 port Powerplug
48
-        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_DEL, props.DTY_TLI_SBT)         ,  # Tradfri Desklight
49
-        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_RCA, props.DTY_MRE_xxx)            # Remote Control IR Amplifier
50
-        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASS, props.DTY_MAS_xxx)            # Audio status Spotify
51
-        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASM, props.DTY_MAS_xxx)            # Audio status MPD
52
-        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
53
-
54
-
55
-        #######
56
-        # FFW #
57
-        #######
55
+        # Temporary to fit to current implementation ###################################################
56
+        TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY = "shellies/gfw/dirk/main_light"
57
+        TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE = "zigbee/gfw/dirk/main_light"
58
+        TOPIC_GFW_DIRK_INPUT_DEVICE = "zigbee/gfw/dirk/input_device"
59
+        TOPIC_GFW_DIRK_POWERPLUG = "my_apps/gfw/dirk/powerplug"
60
+        TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE = "zigbee/gfw/dirk/desk_light"
61
+        TOPIC_GFW_DIRK_AMPLIFIER_REMOTE = "my_apps/gfw/dirk/remote/RAS5"
62
+        TOPIC_GFW_DIRK_SPOTIFY = "my_apps/gfw/dirk/hifi/spotify"
63
+        TOPIC_GFW_DIRK_MPD = "my_apps/gfw/dirk/hifi/mpd"
64
+        TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE = "zigbee/gfw/dirk/heating_valve"
65
+        # Temporary to fit to current implementation ###################################################
66
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, ot=TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY)            # Shelly Main Light
67
+        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT, ot=TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE)            # Tradfri Main Light
68
+        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_INP, props.DTY_TIN_5xx, ot=TOPIC_GFW_DIRK_INPUT_DEVICE)            # Tradfri Input Device 5 Buttons
69
+        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
70
+        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
71
+        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_RCA, props.DTY_MRE_xxx, ot=TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)            # Remote Control IR Amplifier
72
+        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASS, props.DTY_MAS_xxx, ot=TOPIC_GFW_DIRK_SPOTIFY)            # Audio status Spotify
73
+        self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASM, props.DTY_MAS_xxx, ot=TOPIC_GFW_DIRK_MPD)            # Audio status MPD
74
+        self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, ot=TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
75
+
76
+    def __init_ffw__(self, mqtt_client):
58 77
         loc = props.LOC_FFW
59 78
         # JULIAN
60 79
         roo = props.ROO_JUL
61 80
         #
62
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
63
-        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT)            # Tradfri Main Light
64
-        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
81
+        # Temporary to fit to current implementation ###################################################
82
+        TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY = "shellies/ffw/julian/main_light"
83
+        TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE = "zigbee/ffw/julian/main_light"
84
+        TOPIC_FFW_JULIAN_HEATING_VALVE_ZIGBEE = "zigbee/ffw/julian/heating_valve"
85
+        # Temporary to fit to current implementation ###################################################
86
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, ot=TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY)            # Shelly Main Light
87
+        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT, ot=TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE)            # Tradfri Main Light
88
+        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, ot=TOPIC_FFW_JULIAN_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
65 89
 
66 90
         # BATH
67 91
         roo = props.ROO_BAT
68 92
         #
69
-        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
93
+        # Temporary to fit to current implementation
94
+        # Temporary to fit to current implementation ###################################################
95
+        TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE = "zigbee/ffw/bath/heating_valve"
96
+        # Temporary to fit to current implementation ###################################################
97
+        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, ot=TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
70 98
 
71 99
         # LIVINGROOM
72 100
         roo = props.ROO_LIV
73 101
         #
74
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
75
-        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT)            # Tradfri Main Light
102
+        # Temporary to fit to current implementation ###################################################
103
+        TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY = "shellies/ffw/livingroom/main_light"
104
+        TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE = "zigbee/ffw/livingroom/main_light"
105
+        # Temporary to fit to current implementation ###################################################
106
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, ot=TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY)            # Shelly Main Light
107
+        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT, ot=TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE)            # Tradfri Main Light
76 108
 
77 109
         # SLEEP
78 110
         roo = props.ROO_SLP
79 111
         #
80
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
81
-        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBx)            # Tradfri Main Light
82
-        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
112
+        # Temporary to fit to current implementation ###################################################
113
+        TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY = "shellies/ffw/sleep/main_light"
114
+        TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE = "zigbee/ffw/sleep/main_light"
115
+        TOPIC_FFW_SLEEP_HEATING_VALVE_ZIGBEE = "zigbee/ffw/sleep/heating_valve"
116
+        # Temporary to fit to current implementation ###################################################
117
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, ot=TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY)            # Shelly Main Light
118
+        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBx, ot=TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE)            # Tradfri Main Light
119
+        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, ot=TOPIC_FFW_SLEEP_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
83 120
 
84
-        #######
85
-        # FFE #
86
-        #######
121
+    def __init_ffe__(self, mqtt_client):
87 122
         loc = props.LOC_FFE
88 123
         # FLOOR
89 124
         roo = props.ROO_FLO
90 125
         #
91
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
126
+        # Temporary to fit to current implementation ###################################################
127
+        TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY = "shellies/ffe/floor/main_light"
128
+        # Temporary to fit to current implementation ###################################################
129
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, ot=TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY)            # Shelly Main Light
92 130
 
93 131
         # KITCHEN
94 132
         roo = props.ROO_KIT
95 133
         #
96
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
97
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_CIR, props.DTY_SHY_SW1)            # Shelly Main Light
98
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
134
+        # Temporary to fit to current implementation ###################################################
135
+        TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY = "shellies/ffe/kitchen/main_light"
136
+        TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY = "shellies/ffe/kitchen/circulation_pump"
137
+        TOPIC_FFE_KITCHEN_HEATING_VALVE_ZIGBEE = "zigbee/ffe/kitchen/heating_valve"
138
+        # Temporary to fit to current implementation ###################################################
139
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, ot=TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY)            # Shelly Main Light
140
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_CIR, props.DTY_SHY_SW1, ot=TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY)            # Shelly Main Light
141
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, ot=TOPIC_FFE_KITCHEN_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
99 142
 
100 143
         # DININGROOM
101 144
         roo = props.ROO_DIN
102 145
         #
103
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
104
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_SPP_SW1)            # Powerplug Floor Light
105
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_GAR, props.DTY_SPP_SW1)            # Powerplug Garland
106
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
146
+        # Temporary to fit to current implementation ###################################################
147
+        TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY = "shellies/ffe/diningroom/main_light"
148
+        TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG = "zigbee/ffe/diningroom/powerplug_floorlamp"
149
+        TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG = "zigbee/ffe/diningroom/garland"
150
+        TOPIC_FFE_DININGROOM_HEATING_VALVE_ZIGBEE = "zigbee/ffe/diningroom/heating_valve"
151
+        # Temporary to fit to current implementation ###################################################
152
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, ot=TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY)            # Shelly Main Light
153
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_SPP_SW1, ot=TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)            # Powerplug Floor Light
154
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_GAR, props.DTY_SPP_SW1, ot=TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)            # Powerplug Garland
155
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, ot=TOPIC_FFE_DININGROOM_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
107 156
 
108 157
         # SLEEP
109 158
         roo = props.ROO_SLP
110 159
         #
111
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
112
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT)            # Tradfri Main Light
113
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_CTR, props.DTY_TIN_5xx)            # Tradfri Input Device 5 Buttons
114
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLD, props.DTY_TLI_SBx)            # Tradfri Bed Light Dirk
115
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLM, props.DTY_SPP_SW1)            # Powerplug Bed Light Marion
116
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
160
+        # Temporary to fit to current implementation ###################################################
161
+        TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY = "shellies/ffe/sleep/main_light"
162
+        TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE = "zigbee/ffe/sleep/main_light"
163
+        TOPIC_FFE_SLEEP_INPUT_DEVICE = "zigbee/ffe/sleep/input_device"
164
+        TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE = "zigbee/ffe/sleep/bed_light_di"
165
+        TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG = "zigbee/ffe/sleep/bed_light_ma"
166
+        TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE = "zigbee/ffe/sleep/heating_valve"
167
+        # Temporary to fit to current implementation ###################################################
168
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, ot=TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY)            # Shelly Main Light
169
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT, ot=TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE)            # Tradfri Main Light
170
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_INP, props.DTY_TIN_5xx, ot=TOPIC_FFE_SLEEP_INPUT_DEVICE)            # Tradfri Input Device 5 Buttons
171
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLD, props.DTY_TLI_SBx, ot=TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE)            # Tradfri Bed Light Dirk
172
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLM, props.DTY_SPP_SW1, ot=TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)            # Powerplug Bed Light Marion
173
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, ot=TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE)            # Brennenstuhl Heatingvalve
117 174
 
118 175
         # LIVINGROOM
119 176
         roo = props.ROO_LIV
120 177
         #
121
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
122
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT)            # Tradfri Main Light
123
-        for i in range(1, 7):
124
-            self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_TLI_SBT, i)     # Tradfri Main Light
125
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XTR, props.DTY_SPP_SW1)            # Tradfri Main Light
126
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XST, props.DTY_SPP_SW1)            # Tradfri Main Light
127
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx)            # Brennenstuhl Heatingvalve
128
-
129
-        #######
130
-        # STW #
131
-        #######
178
+        # Temporary to fit to current implementation ###################################################
179
+        TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY = "shellies/ffe/livingroom/main_light"
180
+        TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE = "zigbee/ffe/livingroom/main_light"
181
+        TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE = "zigbee/ffe/livingroom/floorlamp_%d"
182
+        TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG = "zigbee/ffe/livingroom/powerplug_xmas-tree"
183
+        TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG = "zigbee/ffe/livingroom/powerplug_xmas-star"
184
+        TOPIC_FFE_LIVINGROOM_HEATING_VALVE_ZIGBEE = "zigbee/ffe/livingroom/heating_valve"
185
+        # Temporary to fit to current implementation ###################################################
186
+        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1, ot=TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY)                 # Shelly Main Light
187
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT, ot=TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE)                 # Tradfri Main Light
188
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_TLI_SBT, range(1, 7), ot=TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE)    # Tradfri Main Light
189
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XTR, props.DTY_SPP_SW1, ot=TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)               # Tradfri Main Light
190
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XST, props.DTY_SPP_SW1, ot=TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)               # Tradfri Main Light
191
+        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx, ot=TOPIC_FFE_LIVINGROOM_HEATING_VALVE_ZIGBEE)              # Brennenstuhl Heatingvalve
192
+
193
+    def __init_stw__(self, mqtt_client):
132 194
         loc = props.LOC_STW
133 195
         # FLOOR
134
-        roo = props.ROO_STW
135 196
         #
136
-        self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1)            # Shelly Main Light
137
-        self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MSE, props.DTY_SMS_xxx, 1)         # Motion Sensor Ground Floor
138
-        self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MSE, props.DTY_SMS_xxx, 2)         # Motion Sensor Ground Floor
197
+        # Temporary to fit to current implementation ###################################################
198
+        TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY = "shellies/stw/stairway/main_light"
199
+        TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF = "zigbee/ffe/stairway/motion_sensor_ff"
200
+        TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF = "zigbee/gfw/stairway/motion_sensor_gf"
201
+        # Temporary to fit to current implementation ###################################################
202
+        self.add(mqtt_client, props.STG_SHE, loc, props.ROO_STF, props.FUN_MAL, props.DTY_SHY_SW1, ot=TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY)            # Shelly Main Light
203
+        self.add(mqtt_client, props.STG_ZFE, loc, props.ROO_STF, props.FUN_MSE, props.DTY_SMS_xxx, ot=TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF)    # Motion Sensor First Floor
204
+        self.add(mqtt_client, props.STG_ZGW, loc, props.ROO_STG, props.FUN_MSE, props.DTY_SMS_xxx, ot=TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF)            # Motion Sensor Ground Floor
139 205
 
140
-    def add(self, mqtt_client, stg, loc, roo, fun, dty, num=None):
206
+    def add(self, mqtt_client, stg, loc, roo, fun, dty, num=None, ot=None):
141 207
         """Method to initilise a device
142 208
 
143 209
         Args:
@@ -148,14 +214,32 @@ class devices(dict):
148 214
             dty (numeric): Device type (see DTP_* in props)
149 215
             num (numeric): Device number in case of multiple devices
150 216
         """
151
-        topic = self.__topic__(stg, loc, roo, fun, num)
152
-        dev_class = props.dty_repr(dty)
153
-        if dev_class is None:
154
-            logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic)
217
+        def get_device(dty, mqtt_client, topic, ot):
218
+            # Temporary to fit to current implementation
219
+            if ot != topic:
220
+                logger.error("Topic change for %s: Using this one: %s", topic, ot)
221
+                topic = ot
222
+            dev_class = props.dty_repr(dty)
223
+            if dev_class is None:
224
+                logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic)
225
+            else:
226
+                return dev_class(mqtt_client, topic)
227
+
228
+        topic = self.__topic__(stg, loc, roo, fun)
229
+        if num is None:
230
+            this_device = get_device(dty, mqtt_client, topic, ot)
231
+            if this_device is None:
232
+                logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic)
233
+            else:
234
+                self[topic] = this_device
155 235
         else:
156
-            self[topic] = dev_class(mqtt_client, topic)
236
+            dg = []
237
+            for i in num:
238
+                device_topic = self.__topic__(stg, loc, roo, fun) + '_%d' % i
239
+                dg.append(get_device(dty, mqtt_client, device_topic, ot=ot % i))
240
+            self[topic] = group(*dg)
157 241
 
158
-    def get(self, stg, loc, roo, fun, num=None):
242
+    def get(self, stg, loc, roo, fun):
159 243
         """Method to get a device
160 244
 
161 245
         Args:
@@ -165,25 +249,21 @@ class devices(dict):
165 249
             fun (numeric): Function (see FUN_* in props)
166 250
             num (numeric): Device number in case of multiple devices
167 251
         """
168
-        return self[self.__topic__(stg, loc, roo, fun, num)]
252
+        topic = self.__topic__(stg, loc, roo, fun)
253
+        return self[topic]
169 254
 
170
-    def __topic__(self, stg, loc, roo, fun, num):
171
-        if num is None:
172
-            postfix = ""
173
-        else:
174
-            postfix = "_%d" % num
175
-        #
255
+    def __topic__(self, stg, loc, roo, fun):
176 256
         if stg in [props.STG_ZFE, props.STG_ZFW, props.STG_ZGW]:
177 257
             # Temporary to fit to current implementation
178 258
             return '/'.join([
179 259
                 props.stg_repr(stg),
180 260
                 props.roo_repr(roo),
181 261
                 props.fun_repr(fun)
182
-            ]) + postfix
262
+            ])
183 263
         else:
184 264
             return '/'.join([
185 265
                 props.stg_repr(stg),
186 266
                 props.loc_repr(loc),
187 267
                 props.roo_repr(roo),
188 268
                 props.fun_repr(fun)
189
-            ]) + postfix
269
+            ])

+ 14
- 8
props.py ファイルの表示

@@ -79,6 +79,8 @@ LOC_FFW = 4
79 79
 """ First floor west """
80 80
 LOC_FFE = 5
81 81
 """ First floor east """
82
+LOC_STW = 6
83
+""" Stairways """
82 84
 def loc_repr(loc):
83 85
     return {
84 86
         LOC_GFW: 'gfw',
@@ -86,6 +88,7 @@ def loc_repr(loc):
86 88
         LOC_STW: 'stw',
87 89
         LOC_FFW: 'ffw',
88 90
         LOC_FFE: 'ffe',
91
+        LOC_STW: 'stw',
89 92
     }.get(loc)
90 93
 
91 94
 #
@@ -109,8 +112,10 @@ ROO_MAR = 8
109 112
 """ Marion """
110 113
 ROO_JUL = 9
111 114
 """ Julian """
112
-ROO_STW = 10
113
-""" Stairway """
115
+ROO_STG = 10
116
+""" ground floor """
117
+ROO_STF = 11
118
+""" first floor """
114 119
 def roo_repr(roo):
115 120
     return {
116 121
         ROO_DIN: 'diningroom',
@@ -122,7 +127,8 @@ def roo_repr(roo):
122 127
         ROO_DIR: 'dirk',
123 128
         ROO_MAR: 'marion',
124 129
         ROO_JUL: 'julian',
125
-        ROO_STW: 'stairway',
130
+        ROO_STG: 'groundfloor',
131
+        ROO_STF: 'firstfloor'
126 132
     }.get(roo)
127 133
 
128 134
 #
@@ -142,8 +148,8 @@ FUN_HEA = 6
142 148
 """ Heating """
143 149
 FUN_MPP = 7
144 150
 """ Multiple Powerplugs """
145
-FUN_CTR = 8
146
-""" Control """
151
+FUN_INP = 8
152
+""" Input Device """
147 153
 FUN_CIR = 9
148 154
 """ Circulation Pump """
149 155
 FUN_GAR = 10
@@ -167,12 +173,12 @@ def fun_repr(fun):
167 173
     return {
168 174
         FUN_MAL: 'main_light',
169 175
         FUN_DEL: 'desk_light',
170
-        FUN_FLL: 'floorlamp',     # TODO: -> floor_light
176
+        FUN_FLL: 'floor_light',
171 177
         FUN_BLD: 'bed_light_di',
172 178
         FUN_BLM: 'bed_light_ma',
173
-        FUN_HEA: 'heating_valve',   # TODO: -> heating
179
+        FUN_HEA: 'heating_valve',
174 180
         FUN_MPP: 'powerplug',
175
-        FUN_CTR: 'input_device',
181
+        FUN_INP: 'input_device',
176 182
         FUN_CIR: 'circulation_pump',
177 183
         FUN_GAR: 'garland',
178 184
         FUN_XTR: 'xmas-tree',

読み込み中…
キャンセル
保存