|
@@ -0,0 +1,189 @@
|
|
1
|
+
|
|
2
|
+#!/usr/bin/env python
|
|
3
|
+# -*- coding: utf-8 -*-
|
|
4
|
+#
|
|
5
|
+from devdi import props
|
|
6
|
+import logging
|
|
7
|
+import sys
|
|
8
|
+
|
|
9
|
+try:
|
|
10
|
+ from config import APP_NAME as ROOT_LOGGER_NAME
|
|
11
|
+except ImportError:
|
|
12
|
+ ROOT_LOGGER_NAME = 'root'
|
|
13
|
+logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+class devices(dict):
|
|
17
|
+ """
|
|
18
|
+ Class to select a device and hold the device information
|
|
19
|
+ """
|
|
20
|
+
|
|
21
|
+ def __init__(self, mqtt_client):
|
|
22
|
+ dict.__init__(self)
|
|
23
|
+ #######
|
|
24
|
+ # GFW #
|
|
25
|
+ #######
|
|
26
|
+ loc = props.LOC_GFW
|
|
27
|
+
|
|
28
|
+ # MARION
|
|
29
|
+ roo = props.ROO_MAR
|
|
30
|
+ #
|
|
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
|
|
33
|
+
|
|
34
|
+ # FLOOR
|
|
35
|
+ roo = props.ROO_FLO
|
|
36
|
+ #
|
|
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
|
|
40
|
+
|
|
41
|
+ # DIRK
|
|
42
|
+ roo = props.ROO_DIR
|
|
43
|
+ #
|
|
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
|
+ #######
|
|
58
|
+ loc = props.LOC_FFW
|
|
59
|
+ # JULIAN
|
|
60
|
+ roo = props.ROO_JUL
|
|
61
|
+ #
|
|
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
|
|
65
|
+
|
|
66
|
+ # BATH
|
|
67
|
+ roo = props.ROO_BAT
|
|
68
|
+ #
|
|
69
|
+ self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
|
|
70
|
+
|
|
71
|
+ # LIVINGROOM
|
|
72
|
+ roo = props.ROO_LIV
|
|
73
|
+ #
|
|
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
|
|
76
|
+
|
|
77
|
+ # SLEEP
|
|
78
|
+ roo = props.ROO_SLP
|
|
79
|
+ #
|
|
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
|
|
83
|
+
|
|
84
|
+ #######
|
|
85
|
+ # FFE #
|
|
86
|
+ #######
|
|
87
|
+ loc = props.LOC_FFE
|
|
88
|
+ # FLOOR
|
|
89
|
+ roo = props.ROO_FLO
|
|
90
|
+ #
|
|
91
|
+ self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
|
|
92
|
+
|
|
93
|
+ # KITCHEN
|
|
94
|
+ roo = props.ROO_KIT
|
|
95
|
+ #
|
|
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
|
|
99
|
+
|
|
100
|
+ # DININGROOM
|
|
101
|
+ roo = props.ROO_DIN
|
|
102
|
+ #
|
|
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
|
|
107
|
+
|
|
108
|
+ # SLEEP
|
|
109
|
+ roo = props.ROO_SLP
|
|
110
|
+ #
|
|
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
|
|
117
|
+
|
|
118
|
+ # LIVINGROOM
|
|
119
|
+ roo = props.ROO_LIV
|
|
120
|
+ #
|
|
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
|
+ #######
|
|
132
|
+ loc = props.LOC_STW
|
|
133
|
+ # FLOOR
|
|
134
|
+ roo = props.ROO_STW
|
|
135
|
+ #
|
|
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
|
|
139
|
+
|
|
140
|
+ def add(self, mqtt_client, stg, loc, roo, fun, dty, num=None):
|
|
141
|
+ """Method to initilise a device
|
|
142
|
+
|
|
143
|
+ Args:
|
|
144
|
+ stg (numeric): Source transmittion group (see SIS_* in props)
|
|
145
|
+ loc (numeric): Location (see LOC_* in props)
|
|
146
|
+ roo (numeric): Room (see ROO_* in props)
|
|
147
|
+ fun (numeric): Function (see FUN_* in props)
|
|
148
|
+ dty (numeric): Device type (see DTP_* in props)
|
|
149
|
+ num (numeric): Device number in case of multiple devices
|
|
150
|
+ """
|
|
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)
|
|
155
|
+ else:
|
|
156
|
+ self[topic] = dev_class(mqtt_client, topic)
|
|
157
|
+
|
|
158
|
+ def get(self, stg, loc, roo, fun, num=None):
|
|
159
|
+ """Method to get a device
|
|
160
|
+
|
|
161
|
+ Args:
|
|
162
|
+ stg (numeric): Source transmittion group (see SIS_* in props)
|
|
163
|
+ loc (numeric): Location (see LOC_* in props)
|
|
164
|
+ roo (numeric): Room (see ROO_* in props)
|
|
165
|
+ fun (numeric): Function (see FUN_* in props)
|
|
166
|
+ num (numeric): Device number in case of multiple devices
|
|
167
|
+ """
|
|
168
|
+ return self[self.__topic__(stg, loc, roo, fun, num)]
|
|
169
|
+
|
|
170
|
+ def __topic__(self, stg, loc, roo, fun, num):
|
|
171
|
+ if num is None:
|
|
172
|
+ postfix = ""
|
|
173
|
+ else:
|
|
174
|
+ postfix = "_%d" % num
|
|
175
|
+ #
|
|
176
|
+ if stg in [props.STG_ZFE, props.STG_ZFW, props.STG_ZGW]:
|
|
177
|
+ # Temporary to fit to current implementation
|
|
178
|
+ return '/'.join([
|
|
179
|
+ props.stg_repr(stg),
|
|
180
|
+ props.roo_repr(roo),
|
|
181
|
+ props.fun_repr(fun)
|
|
182
|
+ ]) + postfix
|
|
183
|
+ else:
|
|
184
|
+ return '/'.join([
|
|
185
|
+ props.stg_repr(stg),
|
|
186
|
+ props.loc_repr(loc),
|
|
187
|
+ props.roo_repr(roo),
|
|
188
|
+ props.fun_repr(fun)
|
|
189
|
+ ]) + postfix
|