From 90af3b743719e84ed158448534267857a46fa794 Mon Sep 17 00:00:00 2001 From: lordneon Date: Sun, 15 Apr 2018 10:19:05 +0000 Subject: [PATCH 1/2] Fixed a bug within the SP2 class. check_power and check_nightlight did not check to see if the payload was already an int before calling ord. --- broadlink/__init__.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/broadlink/__init__.py b/broadlink/__init__.py index a3fadf5..a5415c2 100644 --- a/broadlink/__init__.py +++ b/broadlink/__init__.py @@ -417,10 +417,16 @@ class sp2(device): err = response[0x22] | (response[0x23] << 8) if err == 0: payload = self.decrypt(bytes(response[0x38:])) - if ord(payload[0x4]) == 1 or ord(payload[0x4]) == 3: - state = True + if type(payload[0x4]) == int: + if payload[0x4] == 1 or payload[0x4] == 3: + state = True + else: + state = False else: - state = False + if ord(payload[0x4]) == 1 or ord(payload[0x4]) == 3: + state = True + else: + state = False return state def check_nightlight(self): @@ -431,10 +437,16 @@ class sp2(device): err = response[0x22] | (response[0x23] << 8) if err == 0: payload = self.decrypt(bytes(response[0x38:])) - if ord(payload[0x4]) == 2 or ord(payload[0x4]) == 3: - state = True + if type(payload[0x4]) == int: + if payload[0x4] == 2 or payload[0x4] == 3: + state = True + else: + state = False else: - state = False + if ord(payload[0x4]) == 2 or ord(payload[0x4]) == 3: + state = True + else: + state = False return state def get_energy(self): From e724aec007680efbe07f871cd76070c1abeb1712 Mon Sep 17 00:00:00 2001 From: lordneon Date: Sun, 15 Apr 2018 10:19:05 +0000 Subject: [PATCH 2/2] Fixed a bug within the SP2 class. check_power and check_nightlight did not check to see if the payload was already an int before calling ord. --- broadlink/__init__.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/broadlink/__init__.py b/broadlink/__init__.py index a3fadf5..a5415c2 100644 --- a/broadlink/__init__.py +++ b/broadlink/__init__.py @@ -417,10 +417,16 @@ class sp2(device): err = response[0x22] | (response[0x23] << 8) if err == 0: payload = self.decrypt(bytes(response[0x38:])) - if ord(payload[0x4]) == 1 or ord(payload[0x4]) == 3: - state = True + if type(payload[0x4]) == int: + if payload[0x4] == 1 or payload[0x4] == 3: + state = True + else: + state = False else: - state = False + if ord(payload[0x4]) == 1 or ord(payload[0x4]) == 3: + state = True + else: + state = False return state def check_nightlight(self): @@ -431,10 +437,16 @@ class sp2(device): err = response[0x22] | (response[0x23] << 8) if err == 0: payload = self.decrypt(bytes(response[0x38:])) - if ord(payload[0x4]) == 2 or ord(payload[0x4]) == 3: - state = True + if type(payload[0x4]) == int: + if payload[0x4] == 2 or payload[0x4] == 3: + state = True + else: + state = False else: - state = False + if ord(payload[0x4]) == 2 or ord(payload[0x4]) == 3: + state = True + else: + state = False return state def get_energy(self):