Przeglądaj źródła

Global Summer and Winter Mode

master
Dirk Alders 8 miesięcy temu
rodzic
commit
d613c1db5c
4 zmienionych plików z 42 dodań i 1 usunięć
  1. 11
    1
      function/__init__.py
  2. 15
    0
      function/rooms.py
  3. 14
    0
      function/videv.py
  4. 2
    0
      topics.py

+ 11
- 1
function/__init__.py Wyświetl plik

9
 from function.first_floor_west import first_floor_west
9
 from function.first_floor_west import first_floor_west
10
 from function.first_floor_east import first_floor_east
10
 from function.first_floor_east import first_floor_east
11
 from function.rooms import room_collection
11
 from function.rooms import room_collection
12
-from function.videv import all_off
12
+from function.videv import all_off, videv_pure_switch
13
 import logging
13
 import logging
14
 
14
 
15
 try:
15
 try:
42
         self.init_cross_room_interactions()
42
         self.init_cross_room_interactions()
43
         # Off Buttons
43
         # Off Buttons
44
         self.init_off_functionality()
44
         self.init_off_functionality()
45
+        # Summer / Winter mode
46
+        self.init_sumer_winter_mode()
45
 
47
 
46
     def init_cross_room_interactions(self):
48
     def init_cross_room_interactions(self):
47
         # shelly dirk input 1
49
         # shelly dirk input 1
69
         # FFE ALL OFF - Long push input device
71
         # FFE ALL OFF - Long push input device
70
         self.ffe.sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe.all_off)
72
         self.ffe.sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe.all_off)
71
 
73
 
74
+    def init_sumer_winter_mode(self):
75
+        # ALL summer/winter mode
76
+        self.videv_summer_mode = videv_pure_switch(self.mqtt_client, config.TOPIC_ALL_SUMMER_WINTER_MODE)
77
+
78
+        self.videv_summer_mode.add_callback(self.videv_summer_mode.KEY_STATE, None, self.gfw.summer_mode)
79
+        self.videv_summer_mode.add_callback(self.videv_summer_mode.KEY_STATE, None, self.ffw.summer_mode)
80
+        self.videv_summer_mode.add_callback(self.videv_summer_mode.KEY_STATE, None, self.ffe.summer_mode)
81
+
72
     def gfw_dirk_input_1(self, device, key, data):
82
     def gfw_dirk_input_1(self, device, key, data):
73
         if self.last_gfw_dirk_input_1 is not None:
83
         if self.last_gfw_dirk_input_1 is not None:
74
             if self.last_gfw_dirk_input_1 != data:
84
             if self.last_gfw_dirk_input_1 != data:

+ 15
- 0
function/rooms.py Wyświetl plik

27
             except AttributeError:
27
             except AttributeError:
28
                 pass    # not a module or has no method all_off
28
                 pass    # not a module or has no method all_off
29
 
29
 
30
+    def summer_mode(self, enable):
31
+        for name, obj in inspect.getmembers(self):
32
+            if obj.__class__.__name__ == 'heating_function':
33
+                if obj.__module__ == 'function.modules':
34
+                    obj.set(obj.KEY_SUMMER_MODE, enable)
35
+
30
 
36
 
31
 class room_collection(object):
37
 class room_collection(object):
32
     ALLOWED_CLASSES = ("room", "room_collection")
38
     ALLOWED_CLASSES = ("room", "room_collection")
45
                 if sub.__class__.__bases__[0].__name__ in self.ALLOWED_CLASSES:
51
                 if sub.__class__.__bases__[0].__name__ in self.ALLOWED_CLASSES:
46
                     sub.all_off()
52
                     sub.all_off()
47
 
53
 
54
+    def summer_mode(self, device=None, key=None, data=None):
55
+        logger.info("Changing to %s \"%s\"", "summer mode" if data else "winter_mode", type(self).__name__)
56
+        for sub_name in dir(self):
57
+            # attribute name is not private
58
+            if not sub_name.startswith("__"):
59
+                sub = getattr(self, sub_name)
60
+                if sub.__class__.__bases__[0].__name__ in self.ALLOWED_CLASSES:
61
+                    sub.summer_mode(data)
62
+
48
     def all_devices(self, object_to_analyse=None, depth=0):
63
     def all_devices(self, object_to_analyse=None, depth=0):
49
         target = object_to_analyse or self
64
         target = object_to_analyse or self
50
         #
65
         #

+ 14
- 0
function/videv.py Wyświetl plik

20
     ROOT_LOGGER_NAME = 'root'
20
     ROOT_LOGGER_NAME = 'root'
21
 
21
 
22
 
22
 
23
+class videv_pure_switch(videv_base):
24
+    KEY_STATE = 'state'
25
+
26
+    def __init__(self, mqtt_client, topic):
27
+        super().__init__(mqtt_client, topic)
28
+        self[self.KEY_STATE] = False
29
+        #
30
+        self.mqtt_client.add_callback(self.topic + '/state/set', self.state)
31
+
32
+    def state(self, mqtt_client, tbd, message):
33
+        self.set(self.KEY_STATE, message.payload == b'true')
34
+        self.__tx__(self.KEY_STATE, message.payload == b'true')
35
+
36
+
23
 class videv_switching(videv_base):
37
 class videv_switching(videv_base):
24
     KEY_STATE = 'state'
38
     KEY_STATE = 'state'
25
 
39
 

+ 2
- 0
topics.py Wyświetl plik

3
 #
3
 #
4
 TOPIC_WARNINGS = "videv/warnings"
4
 TOPIC_WARNINGS = "videv/warnings"
5
 TOPIC_ALL_OFF_VIDEV = "videv/off"
5
 TOPIC_ALL_OFF_VIDEV = "videv/off"
6
+TOPIC_ALL_SUMMER_WINTER_MODE = "videv/summer_mode"
7
+
6
 # ground floor west
8
 # ground floor west
7
 # floor
9
 # floor
8
 TOPIC_GFW_FLOOR_MAIN_LIGHT_VIDEV = "videv/gfw/floor/main_light"
10
 TOPIC_GFW_FLOOR_MAIN_LIGHT_VIDEV = "videv/gfw/floor/main_light"

Ładowanie…
Anuluj
Zapisz