Преглед на файлове

Initial version of device definition and initialisation

master
Dirk Alders преди 1 година
родител
ревизия
a5a55a1580
променени са 2 файла, в които са добавени 374 реда и са изтрити 0 реда
  1. 189
    0
      __init__.py
  2. 185
    0
      props.py

+ 189
- 0
__init__.py Целия файл

@@ -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

+ 185
- 0
props.py Целия файл

@@ -0,0 +1,185 @@
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
+def loc_repr(loc):
83
+    return {
84
+        LOC_GFW: 'gfw',
85
+        LOC_GFE: 'gfe',
86
+        LOC_STW: 'stw',
87
+        LOC_FFW: 'ffw',
88
+        LOC_FFE: 'ffe',
89
+    }.get(loc)
90
+
91
+#
92
+# ROOms
93
+#
94
+ROO_DIN = 1
95
+""" Diningroom """
96
+ROO_KIT = 2
97
+""" Kitchen """
98
+ROO_LIV = 3
99
+""" Livingroom """
100
+ROO_FLO = 4
101
+""" Floor """
102
+ROO_SLP = 5
103
+""" Sleep """
104
+ROO_BAT = 6
105
+""" Bath """
106
+ROO_DIR = 7
107
+""" Dirk """
108
+ROO_MAR = 8
109
+""" Marion """
110
+ROO_JUL = 9
111
+""" Julian """
112
+ROO_STW = 10
113
+""" Stairway """
114
+def roo_repr(roo):
115
+    return {
116
+        ROO_DIN: 'diningroom',
117
+        ROO_KIT: 'kitchen',
118
+        ROO_LIV: 'livingroom',
119
+        ROO_FLO: 'floor',
120
+        ROO_SLP: 'sleep',
121
+        ROO_BAT: 'bath',
122
+        ROO_DIR: 'dirk',
123
+        ROO_MAR: 'marion',
124
+        ROO_JUL: 'julian',
125
+        ROO_STW: 'stairway',
126
+    }.get(roo)
127
+
128
+#
129
+# FUNctions
130
+#
131
+FUN_MAL = 1
132
+""" Main Light """
133
+FUN_DEL = 2
134
+""" Desk Light """
135
+FUN_FLL = 3
136
+""" Floor Light """
137
+FUN_BLD = 4
138
+""" Bed Light Dirk """
139
+FUN_BLM = 5
140
+""" Bed Light Marion """
141
+FUN_HEA = 6
142
+""" Heating """
143
+FUN_MPP = 7
144
+""" Multiple Powerplugs """
145
+FUN_CTR = 8
146
+""" Control """
147
+FUN_CIR = 9
148
+""" Circulation Pump """
149
+FUN_GAR = 10
150
+""" Garland """
151
+FUN_XTR = 11
152
+""" X-Mas Tree """
153
+FUN_XST = 12
154
+""" X-Mas Star """
155
+FUN_MSE = 13
156
+""" Motion Sensor """
157
+FUN_RCA = 14
158
+""" Remote Control Amplifier """
159
+FUN_RCC = 15
160
+""" Remote Control CD-Player """
161
+FUN_ASS = 16
162
+""" Audio status spotify """
163
+FUN_ASM = 17
164
+""" Audio status mpd """
165
+
166
+def fun_repr(fun):
167
+    return {
168
+        FUN_MAL: 'main_light',
169
+        FUN_DEL: 'desk_light',
170
+        FUN_FLL: 'floorlamp',     # TODO: -> floor_light
171
+        FUN_BLD: 'bed_light_di',
172
+        FUN_BLM: 'bed_light_ma',
173
+        FUN_HEA: 'heating_valve',   # TODO: -> heating
174
+        FUN_MPP: 'powerplug',
175
+        FUN_CTR: 'input_device',
176
+        FUN_CIR: 'circulation_pump',
177
+        FUN_GAR: 'garland',
178
+        FUN_XTR: 'xmas-tree',
179
+        FUN_XST: 'xmas-star',
180
+        FUN_MSE: 'motion_sensor',
181
+        FUN_RCA: 'remote_ctrl_amp',
182
+        FUN_RCC: 'remote_ctrl_cd',
183
+        FUN_ASS: 'audio_status_spotify',
184
+        FUN_ASM: 'audio_status_mpd',
185
+    }.get(fun)

Loading…
Отказ
Запис