|
@@ -1,100 +1,93 @@
|
1
|
1
|
import config
|
2
|
|
-import devices
|
|
2
|
+import devdi
|
|
3
|
+import devdi.props as props
|
|
4
|
+#import function
|
|
5
|
+#import json
|
3
|
6
|
import logging
|
4
|
7
|
import mqtt
|
|
8
|
+import os
|
5
|
9
|
import report
|
|
10
|
+#import subprocess
|
6
|
11
|
import time
|
7
|
12
|
|
|
13
|
+logger = logging.getLogger(config.APP_NAME)
|
8
|
14
|
|
9
|
|
-class device_creator(dict):
|
10
|
|
- def __init__(self, mqtt_client):
|
11
|
|
- self.mqtt_client = mqtt_client
|
12
|
|
- #
|
13
|
|
- # ground floor west
|
14
|
|
- # floor
|
15
|
|
- l1 = self.add_device(devices.livarno.sw_br_ct, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 1)
|
16
|
|
- l2 = self.add_device(devices.livarno.sw_br_ct, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 2)
|
17
|
|
- self.add_device(devices.shelly.sw_plain, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY, cd_r0=[l1, l2])
|
18
|
|
-
|
19
|
|
- # marion
|
20
|
|
- self.add_device(devices.shelly.sw_plain, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY)
|
21
|
|
- self.add_device(devices.null, config.TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE)
|
22
|
|
-
|
23
|
|
- # dirk
|
24
|
|
- l = self.add_device(devices.tradfri.sw_br_ct, config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE)
|
25
|
|
- self.add_device(devices.shelly.sw_plain, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY, cd_r0=[l])
|
26
|
|
- self.add_device(devices.null, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
|
27
|
|
- self.add_device(devices.null, config.TOPIC_GFW_DIRK_POWERPLUG)
|
28
|
|
- self.add_device(devices.tradfri.sw_br_ct, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE)
|
29
|
|
- self.add_device(devices.null, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)
|
30
|
|
-
|
31
|
|
- # first floor west
|
32
|
|
- # julian
|
33
|
|
- l = self.add_device(devices.tradfri.sw_br_ct, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE)
|
34
|
|
- self.add_device(devices.shelly.sw_plain, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, cd_r0=[l])
|
35
|
|
-
|
36
|
|
- # bath
|
37
|
|
- self.add_device(devices.null, config.TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE)
|
38
|
|
-
|
39
|
|
- # livingroom
|
40
|
|
- l = self.add_device(devices.tradfri.sw_br_ct, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE)
|
41
|
|
- self.add_device(devices.shelly.sw_plain, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY, cd_r0=[l])
|
42
|
|
-
|
43
|
|
- # sleep
|
44
|
|
- l = self.add_device(devices.tradfri.sw_br, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE)
|
45
|
|
- self.add_device(devices.shelly.sw_plain, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY, cd_r0=[l])
|
46
|
|
-
|
47
|
|
-
|
48
|
|
- # first floor east
|
49
|
|
- # floor
|
50
|
|
- self.add_device(devices.shelly.sw_plain, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY)
|
51
|
|
-
|
52
|
|
- # kitchen
|
53
|
|
- self.add_device(devices.shelly.sw_plain, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY)
|
54
|
|
- self.add_device(devices.null, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY)
|
55
|
|
-
|
56
|
|
- # diningroom
|
57
|
|
- self.add_device(devices.shelly.sw_plain, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY)
|
58
|
|
- self.add_device(devices.null, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
|
59
|
|
- self.add_device(devices.null, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
|
60
|
|
-
|
61
|
|
- # sleep
|
62
|
|
- l = self.add_device(devices.tradfri.sw_br_ct, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE)
|
63
|
|
- self.add_device(devices.shelly.sw_plain, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY, cd_r0=[l])
|
64
|
|
- self.add_device(devices.null, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
|
65
|
|
- self.add_device(devices.tradfri.sw_br, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE)
|
66
|
|
- self.add_device(devices.null, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)
|
67
|
|
- self.add_device(devices.null, config.TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE)
|
68
|
|
-
|
69
|
|
- # livingroom
|
70
|
|
- l = self.add_device(devices.tradfri.sw_br_ct, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE)
|
71
|
|
- self.add_device(devices.shelly.sw_plain, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY, cd_r0=[l])
|
72
|
|
- for i in range(1,7):
|
73
|
|
- self.add_device(devices.tradfri.sw_br_ct, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i)
|
74
|
|
- self.add_device(devices.null, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
|
75
|
|
- self.add_device(devices.null, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
|
76
|
|
-
|
77
|
|
-
|
78
|
|
- # first floor east
|
79
|
|
- # floor
|
80
|
|
- self.add_device(devices.shelly.sw_plain, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY)
|
81
|
|
- self.add_device(devices.null, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF)
|
82
|
|
- self.add_device(devices.null, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF)
|
83
|
|
-
|
84
|
|
- def add_device(self, deviceclass, topic, **kwargs):
|
85
|
|
- self[topic] = deviceclass(self.mqtt_client, topic, **kwargs)
|
86
|
|
- return self[topic]
|
87
|
15
|
|
88
|
16
|
if __name__ == "__main__":
|
89
|
|
- report.stdoutLoggingConfigure((
|
90
|
|
- (config.APP_NAME, logging.DEBUG),
|
91
|
|
- ('devices', logging.DEBUG),
|
92
|
|
- ), report.SHORT_FMT)
|
93
|
|
-
|
|
17
|
+ #
|
|
18
|
+ # Logging
|
|
19
|
+ #
|
|
20
|
+ if config.DEBUG:
|
|
21
|
+ report.appLoggingConfigure(None, 'stdout', ((config.APP_NAME, logging.DEBUG), ),
|
|
22
|
+ target_level=logging.WARNING, fmt=report.SHORT_FMT, host='localhost', port=19996)
|
|
23
|
+ else:
|
|
24
|
+ report.stdoutLoggingConfigure(((config.APP_NAME, logging.WARNING), ), report.SHORT_FMT)
|
|
25
|
+
|
|
26
|
+ #
|
|
27
|
+ # MQTT Client
|
|
28
|
+ #
|
94
|
29
|
mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
|
95
|
|
- password=config.MQTT_PASSWORD, name='home_emulation')
|
96
|
|
-
|
97
|
|
- device_dict = device_creator(mc)
|
|
30
|
+ password=config.MQTT_PASSWORD, name=config.APP_NAME)
|
|
31
|
+
|
|
32
|
+ #
|
|
33
|
+ # Smarthome Devices
|
|
34
|
+ #
|
|
35
|
+ ddi = devdi.devices(mc)
|
|
36
|
+
|
|
37
|
+ #
|
|
38
|
+ # Smart Home Functionality
|
|
39
|
+ #
|
|
40
|
+ #######
|
|
41
|
+ # GFW #
|
|
42
|
+ #######
|
|
43
|
+ loc = props.LOC_GFW
|
|
44
|
+ # DIRK
|
|
45
|
+ roo = props.ROO_DIR
|
|
46
|
+ sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
|
|
47
|
+ tml = ddi.get(props.STG_ZGW, loc, roo, props.FUN_MAL)
|
|
48
|
+ sml.register_power_on_instance(tml)
|
|
49
|
+ # FLOOR
|
|
50
|
+ roo = props.ROO_FLO
|
|
51
|
+ sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
|
|
52
|
+ tml = ddi.get(props.STG_ZGW, loc, roo, props.FUN_MAL, 1)
|
|
53
|
+ sml.register_power_on_instance(tml)
|
|
54
|
+ tml = ddi.get(props.STG_ZGW, loc, roo, props.FUN_MAL, 2)
|
|
55
|
+ sml.register_power_on_instance(tml)
|
|
56
|
+
|
|
57
|
+ #######
|
|
58
|
+ # FFW #
|
|
59
|
+ #######
|
|
60
|
+ loc = props.LOC_FFW
|
|
61
|
+ # JULIAN
|
|
62
|
+ roo = props.ROO_JUL
|
|
63
|
+ sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
|
|
64
|
+ tml = ddi.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
|
|
65
|
+ sml.register_power_on_instance(tml)
|
|
66
|
+ # LIVINGROOM
|
|
67
|
+ roo = props.ROO_LIV
|
|
68
|
+ sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
|
|
69
|
+ tml = ddi.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
|
|
70
|
+ sml.register_power_on_instance(tml)
|
|
71
|
+ # SLEEP
|
|
72
|
+ roo = props.ROO_SLP
|
|
73
|
+ sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
|
|
74
|
+ tml = ddi.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
|
|
75
|
+ sml.register_power_on_instance(tml)
|
|
76
|
+
|
|
77
|
+ #######
|
|
78
|
+ # FFE #
|
|
79
|
+ #######
|
|
80
|
+ loc = props.LOC_FFE
|
|
81
|
+ # LIVINGROOM
|
|
82
|
+ roo = props.ROO_LIV
|
|
83
|
+ sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
|
|
84
|
+ tml = ddi.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
|
|
85
|
+ sml.register_power_on_instance(tml)
|
|
86
|
+ # SLEEP
|
|
87
|
+ roo = props.ROO_SLP
|
|
88
|
+ sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
|
|
89
|
+ tml = ddi.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
|
|
90
|
+ sml.register_power_on_instance(tml)
|
98
|
91
|
|
99
|
92
|
while (True):
|
100
|
93
|
time.sleep(1)
|