mirror of
https://github.com/mjg59/python-broadlink.git
synced 2024-11-13 03:00:11 +01:00
Fix python 2 compatibility
Ugly but appears to work
This commit is contained in:
parent
31cd077165
commit
d10a43531c
@ -238,7 +238,7 @@ class device:
|
||||
if (time.time() - starttime) < self.timeout:
|
||||
pass
|
||||
raise
|
||||
return bytes(response[0])
|
||||
return bytearray(response[0])
|
||||
|
||||
|
||||
class sp1(device):
|
||||
@ -289,9 +289,18 @@ class a1(device):
|
||||
data = {}
|
||||
aes = AES.new(bytes(self.key), AES.MODE_CBC, bytes(self.iv))
|
||||
payload = aes.decrypt(bytes(response[0x38:]))
|
||||
data['temperature'] = (payload[0x4] * 10 + payload[0x5]) / 10.0
|
||||
data['humidity'] = (payload[0x6] * 10 + payload[0x7]) / 10.0
|
||||
light = payload[0x8]
|
||||
if type(payload[0x4]) == int:
|
||||
data['temperature'] = (payload[0x4] * 10 + payload[0x5]) / 10.0
|
||||
data['humidity'] = (payload[0x6] * 10 + payload[0x7]) / 10.0
|
||||
light = payload[0x8]
|
||||
air_quality = payload[0x0a]
|
||||
noise = payload[0xc]
|
||||
else:
|
||||
data['temperature'] = (ord(payload[0x4]) * 10 + ord(payload[0x5])) / 10.0
|
||||
data['humidity'] = (ord(payload[0x6]) * 10 + ord(payload[0x7])) / 10.0
|
||||
light = ord(payload[0x8])
|
||||
air_quality = ord(payload[0x0a])
|
||||
noise = ord(payload[0xc])
|
||||
if light == 0:
|
||||
data['light'] = 'dark'
|
||||
elif light == 1:
|
||||
@ -302,7 +311,6 @@ class a1(device):
|
||||
data['light'] = 'bright'
|
||||
else:
|
||||
data['light'] = 'unknown'
|
||||
air_quality = payload[0x0a]
|
||||
if air_quality == 0:
|
||||
data['air_quality'] = 'excellent'
|
||||
elif air_quality == 1:
|
||||
@ -313,7 +321,6 @@ class a1(device):
|
||||
data['air_quality'] = 'bad'
|
||||
else:
|
||||
data['air_quality'] = 'unknown'
|
||||
noise = payload[0xc]
|
||||
if noise == 0:
|
||||
data['noise'] = 'quiet'
|
||||
elif noise == 1:
|
||||
@ -358,7 +365,10 @@ class rm(device):
|
||||
if err == 0:
|
||||
aes = AES.new(bytes(self.key), AES.MODE_CBC, bytes(self.iv))
|
||||
payload = aes.decrypt(bytes(response[0x38:]))
|
||||
temp = (payload[0x4] * 10 + payload[0x5]) / 10.0
|
||||
if type(payload[0x4]) == int:
|
||||
temp = (payload[0x4] * 10 + payload[0x5]) / 10.0
|
||||
else:
|
||||
temp = (ord(payload[0x4]) * 10 + ord(payload[0x5])) / 10.0
|
||||
return temp
|
||||
|
||||
# For legay compatibility - don't use this
|
||||
|
Loading…
Reference in New Issue
Block a user