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