about summary refs log tree commit diff
path: root/broadlink/__init__.py
diff options
context:
space:
mode:
authorSergey Prilukin <spriluki@tibco.com>2018-11-25T22·21+0200
committerSergey Prilukin <spriluki@tibco.com>2018-11-25T22·21+0200
commit2b4e6d91ff0643e1bfd9cf14360f60bb79ceb4a9 (patch)
tree0c8fdc7aacc7a55ae9ad7f0ab69084cb03ad606d /broadlink/__init__.py
parent1cceae73eb4f936283c6eaf9eed99f365a37d467 (diff)
parent694b4423b50cc55f9a48d14a41f1615799342c43 (diff)
Merge branch 'rf_experiment' into rf_experiment_v0.9
# Conflicts:
#	README.md
#	broadlink/__init__.py
#	cli/broadlink_cli
Diffstat (limited to 'broadlink/__init__.py')
-rw-r--r--broadlink/__init__.py54
1 files changed, 43 insertions, 11 deletions
diff --git a/broadlink/__init__.py b/broadlink/__init__.py
index 02a8e2a8e40f..33bf5e8f879b 100644
--- a/broadlink/__init__.py
+++ b/broadlink/__init__.py
@@ -545,6 +545,38 @@ class rm(device):
     packet[0] = 3
     self.send_packet(0x6a, packet)
 
+  def sweep_frequency(self):
+    packet = bytearray(16)
+    packet[0] = 0x19
+    self.send_packet(0x6a, packet)
+
+  def cancel_sweep_frequency(self):
+    packet = bytearray(16)
+    packet[0] = 0x1e
+    self.send_packet(0x6a, packet)
+
+  def check_frequency(self):
+    packet = bytearray(16)
+    packet[0] = 0x1a
+    response = self.send_packet(0x6a, packet)
+    err = response[0x22] | (response[0x23] << 8)
+    if err == 0:
+      payload = self.decrypt(bytes(response[0x38:]))
+      if payload[0x04] == 1:
+          return True
+    return False
+
+  def find_rf_packet(self):
+    packet = bytearray(16)
+    packet[0] = 0x1b
+    response = self.send_packet(0x6a, packet)
+    err = response[0x22] | (response[0x23] << 8)
+    if err == 0:
+      payload = self.decrypt(bytes(response[0x38:]))
+      if payload[0x04] == 1:
+          return True
+    return False
+
   def check_temperature(self):
     packet = bytearray(16)
     packet[0] = 1
@@ -576,19 +608,19 @@ class hysen(device):
     self.type = "Hysen heating controller"
 
   # Send a request
-  # input_payload should be a bytearray, usually 6 bytes, e.g. bytearray([0x01,0x06,0x00,0x02,0x10,0x00]) 
+  # input_payload should be a bytearray, usually 6 bytes, e.g. bytearray([0x01,0x06,0x00,0x02,0x10,0x00])
   # Returns decrypted payload
   # New behaviour: raises a ValueError if the device response indicates an error or CRC check fails
   # The function prepends length (2 bytes) and appends CRC
   def send_request(self,input_payload):
-    
+
     from PyCRC.CRC16 import CRC16
     crc = CRC16(modbus_flag=True).calculate(bytes(input_payload))
 
     # first byte is length, +2 for CRC16
     request_payload = bytearray([len(input_payload) + 2,0x00])
     request_payload.extend(input_payload)
-    
+
     # append CRC
     request_payload.append(crc & 0xFF)
     request_payload.append((crc >> 8) & 0xFF)
@@ -598,9 +630,9 @@ class hysen(device):
 
     # check for error
     err = response[0x22] | (response[0x23] << 8)
-    if err: 
+    if err:
       raise ValueError('broadlink_response_error',err)
-    
+
     response_payload = bytearray(self.decrypt(bytes(response[0x38:])))
 
     # experimental check on CRC in response (first 2 bytes are len, and trailing bytes are crc)
@@ -610,9 +642,9 @@ class hysen(device):
     crc = CRC16(modbus_flag=True).calculate(bytes(response_payload[2:response_payload_len]))
     if (response_payload[response_payload_len] == crc & 0xFF) and (response_payload[response_payload_len+1] == (crc >> 8) & 0xFF):
       return response_payload[2:response_payload_len]
-    else: 
+    else:
       raise ValueError('hysen_response_error','CRC check on response failed')
-      
+
 
   # Get current room temperature in degrees celsius
   def get_temp(self):
@@ -626,7 +658,7 @@ class hysen(device):
 
   # Get full status (including timer schedule)
   def get_full_status(self):
-    payload = self.send_request(bytearray([0x01,0x03,0x00,0x00,0x00,0x16]))    
+    payload = self.send_request(bytearray([0x01,0x03,0x00,0x00,0x00,0x16]))
     data = {}
     data['remote_lock'] =  payload[3] & 1
     data['power'] =  payload[4] & 1
@@ -652,11 +684,11 @@ class hysen(device):
     data['min'] =  payload[20]
     data['sec'] =  payload[21]
     data['dayofweek'] =  payload[22]
-    
+
     weekday = []
     for i in range(0, 6):
       weekday.append({'start_hour':payload[2*i + 23], 'start_minute':payload[2*i + 24],'temp':payload[i + 39]/2.0})
-    
+
     data['weekday'] = weekday
     weekend = []
     for i in range(6, 8):
@@ -693,7 +725,7 @@ class hysen(device):
   # For backwards compatibility only.  Prefer calling set_mode directly.  Note this function invokes loop_mode=0 and sensor=0.
   def switch_to_auto(self):
     self.set_mode(auto_mode=1, loop_mode=0)
-  
+
   def switch_to_manual(self):
     self.set_mode(auto_mode=0, loop_mode=0)