about summary refs log tree commit diff
path: root/broadlink/__init__.py
diff options
context:
space:
mode:
authorgpenverne <gpenverne@gmail.com>2019-05-10T18·19+0200
committerMatthew Garrett <mjg59-github@srcf.ucam.org>2019-05-18T07·06-0700
commit77f11c8d49255d6f41c35f0aefb87d648af66cfd (patch)
tree9f938ee8ec627ee04a4f25b9d95989e4e78df677 /broadlink/__init__.py
parent1d6d8d2aee6e221aa3383e4078b19b7b95397f43 (diff)
Allow string mac address in constructor
Diffstat (limited to 'broadlink/__init__.py')
-rw-r--r--broadlink/__init__.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/broadlink/__init__.py b/broadlink/__init__.py
index 14c1a3bfa805..3d544147c8ec 100644
--- a/broadlink/__init__.py
+++ b/broadlink/__init__.py
@@ -143,7 +143,7 @@ def discover(timeout=None, local_ip_address=None):
 class device:
   def __init__(self, host, mac, devtype, timeout=10):
     self.host = host
-    self.mac = mac
+    self.mac = mac.encode() if isinstance(mac, str) else mac
     self.devtype = devtype
     self.timeout = timeout
     self.count = random.randrange(0xffff)
@@ -577,19 +577,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)
@@ -599,9 +599,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)
@@ -611,9 +611,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):
@@ -627,7 +627,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
@@ -653,11 +653,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):
@@ -694,7 +694,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)