|
@@ -1,11 +1,14 @@
|
1
|
1
|
#!/usr/bin/env python
|
2
|
2
|
# -*- coding: utf-8 -*-
|
3
|
3
|
#
|
|
4
|
+import config
|
4
|
5
|
import devices
|
5
|
6
|
from function.stairway import stairway
|
6
|
|
-from function.ground_floor_west import ground_floor_west_floor, ground_floor_west_marion, ground_floor_west_dirk
|
7
|
|
-from function.first_floor_west import first_floor_west_julian, first_floor_west_living, first_floor_west_bath, first_floor_west_sleep
|
8
|
|
-from function.first_floor_east import first_floor_east_floor, first_floor_east_kitchen, first_floor_east_dining, first_floor_east_sleep, first_floor_east_living
|
|
7
|
+from function.ground_floor_west import ground_floor_west
|
|
8
|
+from function.first_floor_west import first_floor_west
|
|
9
|
+from function.first_floor_east import first_floor_east
|
|
10
|
+from function.rooms import room_collection
|
|
11
|
+from function.videv import all_off
|
9
|
12
|
import inspect
|
10
|
13
|
import logging
|
11
|
14
|
|
|
@@ -19,31 +22,20 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
19
|
22
|
# TODO: implement warning message
|
20
|
23
|
|
21
|
24
|
|
22
|
|
-class all_functions(object):
|
|
25
|
+class all_functions(room_collection):
|
23
|
26
|
def __init__(self, mqtt_client):
|
24
|
|
- self.mqtt_client = mqtt_client
|
25
|
|
- #
|
26
|
|
- self.__devices__ = None
|
|
27
|
+ super().__init__(mqtt_client)
|
27
|
28
|
#
|
28
|
29
|
# Rooms
|
29
|
30
|
#
|
30
|
31
|
# stairway
|
31
|
|
- self.stw_stairway = stairway(self.mqtt_client)
|
|
32
|
+ self.stw = stairway(self.mqtt_client)
|
32
|
33
|
# ground floor west
|
33
|
|
- self.gfw_floor = ground_floor_west_floor(self.mqtt_client)
|
34
|
|
- self.gfw_marion = ground_floor_west_marion(self.mqtt_client)
|
35
|
|
- self.gfw_dirk = ground_floor_west_dirk(self.mqtt_client)
|
|
34
|
+ self.gfw = ground_floor_west(self.mqtt_client)
|
36
|
35
|
# first floor west
|
37
|
|
- self.ffw_julian = first_floor_west_julian(self.mqtt_client)
|
38
|
|
- self.ffw_bath = first_floor_west_bath(self.mqtt_client)
|
39
|
|
- self.ffw_living = first_floor_west_living(self.mqtt_client)
|
40
|
|
- self.ffw_sleep = first_floor_west_sleep(self.mqtt_client)
|
|
36
|
+ self.ffw = first_floor_west(self.mqtt_client)
|
41
|
37
|
# first floor east
|
42
|
|
- self.ffe_floor = first_floor_east_floor(self.mqtt_client)
|
43
|
|
- self.ffe_kitchen = first_floor_east_kitchen(self.mqtt_client)
|
44
|
|
- self.ffe_dining = first_floor_east_dining(self.mqtt_client)
|
45
|
|
- self.ffe_sleep = first_floor_east_sleep(self.mqtt_client)
|
46
|
|
- self.ffe_living = first_floor_east_living(self.mqtt_client)
|
|
38
|
+ self.ffe = first_floor_east(self.mqtt_client)
|
47
|
39
|
#
|
48
|
40
|
# Interactions
|
49
|
41
|
#
|
|
@@ -55,71 +47,28 @@ class all_functions(object):
|
55
|
47
|
def init_cross_room_interactions(self):
|
56
|
48
|
# shelly dirk input 1
|
57
|
49
|
self.last_gfw_dirk_input_1 = None
|
58
|
|
- self.gfw_dirk.main_light_shelly.add_callback(devices.shelly.KEY_INPUT_1, None, self.gfw_dirk_input_1)
|
|
50
|
+ self.gfw.dirk.main_light_shelly.add_callback(devices.shelly.KEY_INPUT_1, None, self.gfw_dirk_input_1)
|
59
|
51
|
# tradfri button ffe_sleep right click
|
60
|
|
- self.ffe_sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
|
61
|
|
- devices.tradfri_button.ACTION_RIGHT, self.ffe_floor.main_light_shelly.toggle_output_0_mcb)
|
|
52
|
+ self.ffe.sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
|
|
53
|
+ devices.tradfri_button.ACTION_RIGHT, self.ffe.floor.main_light_shelly.toggle_output_0_mcb)
|
62
|
54
|
|
63
|
55
|
def init_off_functionality(self):
|
64
|
|
- ##### TEMPORARY ###################################################################################################################
|
65
|
|
- # # Off Buttons
|
66
|
|
- # self.gui_button_all_off = devices.nodered_gui_button(self.mqtt_client, "gui/all/common/off/button")
|
67
|
|
- # self.gui_button_gfw_off = devices.nodered_gui_button(self.mqtt_client, "gui/gfw/common/off/button")
|
68
|
|
- # self.gui_button_ffw_off = devices.nodered_gui_button(self.mqtt_client, "gui/ffw/common/off/button")
|
69
|
|
- # self.gui_button_ffe_off = devices.nodered_gui_button(self.mqtt_client, "gui/ffe/common/off/button")
|
70
|
|
- # #
|
71
|
|
- # self.gui_button_all_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.all_off)
|
72
|
|
- # self.gui_button_gfw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.gfw_off)
|
73
|
|
- # self.gui_button_ffw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffw_off)
|
74
|
|
- # self.gui_button_ffe_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffe_off)
|
75
|
|
- ##### TEMPORARY ###################################################################################################################
|
|
56
|
+ # ALL OFF - Virtual device
|
|
57
|
+ self.videv_all_off = all_off(self.mqtt_client, config.TOPIC_ALL_OFF_VIDEV, self)
|
76
|
58
|
|
77
|
59
|
# ALL OFF - Long push stairway
|
78
|
|
- self.stw_stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.stw_stairway.main_light_shelly.flash_0_mcb)
|
79
|
|
- self.stw_stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.all_off)
|
|
60
|
+ self.stw.stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.stw.stairway.main_light_shelly.flash_0_mcb)
|
|
61
|
+ self.stw.stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.all_off)
|
80
|
62
|
|
81
|
63
|
# FFE ALL OFF - Long push ffe_floor
|
82
|
|
- self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_floor.main_light_shelly.flash_0_mcb)
|
83
|
|
- self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_off)
|
|
64
|
+ self.ffe.floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe.floor.main_light_shelly.flash_0_mcb)
|
|
65
|
+ self.ffe.floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe.all_off)
|
84
|
66
|
|
85
|
67
|
# FFE ALL OFF - Long push input device
|
86
|
|
- self.ffe_sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe_off)
|
|
68
|
+ self.ffe.sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe.all_off)
|
87
|
69
|
|
88
|
70
|
def gfw_dirk_input_1(self, device, key, data):
|
89
|
71
|
if self.last_gfw_dirk_input_1 is not None:
|
90
|
72
|
if self.last_gfw_dirk_input_1 != data:
|
91
|
|
- self.gfw_floor.main_light_shelly.toggle_output_0_mcb(device, key, data)
|
|
73
|
+ self.gfw.floor.main_light_shelly.toggle_output_0_mcb(device, key, data)
|
92
|
74
|
self.last_gfw_dirk_input_1 = data
|
93
|
|
-
|
94
|
|
- def getmembers(self, prefix):
|
95
|
|
- rv = []
|
96
|
|
- for name, obj in inspect.getmembers(self):
|
97
|
|
- if name.startswith(prefix) and obj.__module__.split('.')[0] == 'function' and len(obj.__module__.split('.')) == 2:
|
98
|
|
- rv.append(obj)
|
99
|
|
- return rv
|
100
|
|
-
|
101
|
|
- def gfw_off(self, device=None, key=None, data=None):
|
102
|
|
- logger.info("Switching \"ground floor west\" off.")
|
103
|
|
- for gfw in self.getmembers('gfw'):
|
104
|
|
- gfw.all_off()
|
105
|
|
-
|
106
|
|
- def ffw_off(self, device=None, key=None, data=None):
|
107
|
|
- logger.info("Switching \"first floor west\" off.")
|
108
|
|
- for ffw in self.getmembers('ffw'):
|
109
|
|
- ffw.all_off()
|
110
|
|
-
|
111
|
|
- def ffe_off(self, device=None, key=None, data=None):
|
112
|
|
- logger.info("Switching \"first floor east\" off.")
|
113
|
|
- for ffe in self.getmembers('ffe'):
|
114
|
|
- ffe.all_off()
|
115
|
|
-
|
116
|
|
- def stw_off(self, device=None, key=None, data=None):
|
117
|
|
- logger.info("Switching \"stairway\" off.")
|
118
|
|
- for stw in self.getmembers('stw'):
|
119
|
|
- stw.all_off()
|
120
|
|
-
|
121
|
|
- def all_off(self, device=None, key=None, data=None):
|
122
|
|
- for name, obj in inspect.getmembers(self):
|
123
|
|
- parent_name = obj.__class__.__base__.__name__
|
124
|
|
- if parent_name == "room":
|
125
|
|
- obj.all_off()
|