1
1
import base64
2
2
import struct
3
+
3
4
from maxcube .device import \
4
5
MaxDevice , \
5
6
MAX_CUBE , \
@@ -26,10 +27,7 @@ def __init__(self, connection):
26
27
self .init ()
27
28
28
29
def init (self ):
29
- self .connection .connect ()
30
- response = self .connection .response
31
- self .parse_response (response )
32
- self .connection .disconnect ()
30
+ self .update ()
33
31
logger .info ('Cube (rf=%s, firmware=%s)' % (self .rf_address , self .firmware_version ))
34
32
for device in self .devices :
35
33
if self .is_thermostat (device ):
@@ -40,6 +38,12 @@ def init(self):
40
38
else :
41
39
logger .info ('Device (rf=%s, name=%s' % (device .rf_address , device .name ))
42
40
41
+ def update (self ):
42
+ self .connection .connect ()
43
+ response = self .connection .response
44
+ self .parse_response (response )
45
+ self .connection .disconnect ()
46
+
43
47
def device_by_rf (self , rf ):
44
48
for device in self .devices :
45
49
if device .rf_address == rf :
@@ -95,6 +99,7 @@ def parse_m_message(self, message):
95
99
device_rf_address = '' .join ("%X" % x for x in data [pos + 1 : pos + 1 + 3 ])
96
100
device_name_length = data [pos + 14 ]
97
101
device_name = data [pos + 15 :pos + 15 + device_name_length ].decode ('utf-8' )
102
+ room_id = data [pos + 15 + device_name_length ]
98
103
99
104
device = self .device_by_rf (device_rf_address )
100
105
@@ -108,6 +113,7 @@ def parse_m_message(self, message):
108
113
if device :
109
114
device .type = device_type
110
115
device .rf_address = device_rf_address
116
+ device .room_id = room_id
111
117
device .name = device_name
112
118
113
119
pos += 1 + 3 + 10 + device_name_length + 2
@@ -135,6 +141,26 @@ def parse_l_message(self, message):
135
141
device .target_temperature = (data [pos + 7 ] & 0x7F ) / 2
136
142
pos += length
137
143
144
+ def set_target_temperature (self , thermostat , temperature ):
145
+ rf_address = thermostat .rf_address
146
+ if len (rf_address ) < 6 :
147
+ rf_address = '0' + rf_address
148
+ room = str (thermostat .room_id )
149
+ if thermostat .room_id < 10 :
150
+ room = '0' + room
151
+ target_temperature = int (temperature * 2 )
152
+ target_temperature |= (1 << 6 )
153
+ target_temperature &= ~ (1 << 7 )
154
+
155
+ byte_cmd = '000440000000' + rf_address + room + hex (target_temperature )[2 :]
156
+ command = 's:' + base64 .b64encode (bytearray .fromhex (byte_cmd )).decode ('utf-8' ) + '\r \n '
157
+
158
+ self .connection .connect ()
159
+ self .connection .send (command )
160
+ self .connection .disconnect ()
161
+ thermostat .target_temperature = int (temperature * 2 )/ 2
162
+
163
+
138
164
@classmethod
139
165
def resolve_device_mode (cls , bits ):
140
166
if not bool (bits & 0x02 ) and not bool (bits & 0x01 ):
0 commit comments