Browse Source

Global Summer and Winter Mode

master
Dirk Alders 8 months ago
parent
commit
d613c1db5c
4 changed files with 42 additions and 1 deletions
  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 View File

@@ -9,7 +9,7 @@ from function.ground_floor_west import ground_floor_west
9 9
 from function.first_floor_west import first_floor_west
10 10
 from function.first_floor_east import first_floor_east
11 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 13
 import logging
14 14
 
15 15
 try:
@@ -42,6 +42,8 @@ class all_functions(room_collection):
42 42
         self.init_cross_room_interactions()
43 43
         # Off Buttons
44 44
         self.init_off_functionality()
45
+        # Summer / Winter mode
46
+        self.init_sumer_winter_mode()
45 47
 
46 48
     def init_cross_room_interactions(self):
47 49
         # shelly dirk input 1
@@ -69,6 +71,14 @@ class all_functions(room_collection):
69 71
         # FFE ALL OFF - Long push input device
70 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 82
     def gfw_dirk_input_1(self, device, key, data):
73 83
         if self.last_gfw_dirk_input_1 is not None:
74 84
             if self.last_gfw_dirk_input_1 != data:

+ 15
- 0
function/rooms.py View File

@@ -27,6 +27,12 @@ class room(object):
27 27
             except AttributeError:
28 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 37
 class room_collection(object):
32 38
     ALLOWED_CLASSES = ("room", "room_collection")
@@ -45,6 +51,15 @@ class room_collection(object):
45 51
                 if sub.__class__.__bases__[0].__name__ in self.ALLOWED_CLASSES:
46 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 63
     def all_devices(self, object_to_analyse=None, depth=0):
49 64
         target = object_to_analyse or self
50 65
         #

+ 14
- 0
function/videv.py View File

@@ -20,6 +20,20 @@ except ImportError:
20 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 37
 class videv_switching(videv_base):
24 38
     KEY_STATE = 'state'
25 39
 

+ 2
- 0
topics.py View File

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

Loading…
Cancel
Save