Skip to content

Commit e724aec

Browse files
committed
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.
1 parent 3b6b55a commit e724aec

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

broadlink/__init__.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,16 @@ def check_power(self):
417417
err = response[0x22] | (response[0x23] << 8)
418418
if err == 0:
419419
payload = self.decrypt(bytes(response[0x38:]))
420-
if ord(payload[0x4]) == 1 or ord(payload[0x4]) == 3:
421-
state = True
420+
if type(payload[0x4]) == int:
421+
if payload[0x4] == 1 or payload[0x4] == 3:
422+
state = True
423+
else:
424+
state = False
422425
else:
423-
state = False
426+
if ord(payload[0x4]) == 1 or ord(payload[0x4]) == 3:
427+
state = True
428+
else:
429+
state = False
424430
return state
425431

426432
def check_nightlight(self):
@@ -431,10 +437,16 @@ def check_nightlight(self):
431437
err = response[0x22] | (response[0x23] << 8)
432438
if err == 0:
433439
payload = self.decrypt(bytes(response[0x38:]))
434-
if ord(payload[0x4]) == 2 or ord(payload[0x4]) == 3:
435-
state = True
440+
if type(payload[0x4]) == int:
441+
if payload[0x4] == 2 or payload[0x4] == 3:
442+
state = True
443+
else:
444+
state = False
436445
else:
437-
state = False
446+
if ord(payload[0x4]) == 2 or ord(payload[0x4]) == 3:
447+
state = True
448+
else:
449+
state = False
438450
return state
439451

440452
def get_energy(self):

0 commit comments

Comments
 (0)