mjg59 / python-broadlink

Python module for controlling Broadlink RM2/3 (Pro) remote controls, A1 sensor platforms and SP2/3 smartplugs
MIT License
1.39k stars 479 forks source link

check_power() on MP2 (detected as SP2) always returns True #51

Closed Paxy closed 3 years ago

Paxy commented 7 years ago

Example code:

import broadlink
mac="B827EB8183B9".decode('hex')
devices = broadlink.sp2(('172.16.1.170', 80),mac)
devices.auth()
print devices.check_power()

Always returns True desn't matter what is actual state. set_power(*) is working correctly.

eddyyanto commented 7 years ago

@Paxy I just tested my SP2 plug and I got the same issue as yours. I noticed that the return statement is missing something. Simply replace the return statement on broadlink/init.py line 355 and it should work: from return bool(payload[0x4]) to return bool(ord(payload[0x4]))

I have submitted a PR #52

vicfergar commented 7 years ago

@eddyyanto this change will break Python 3 compatibility. You should check the type of payload[0x4] before doing the casting to ord as is done in other devices (A1 or MP1).

johado commented 7 years ago

Hi, I recently bought 3 EU style SP2 for $10 each from aliexpress, and had the same issue. Aa @vicfergar pointed out it should probably be something like: payload = aes.decrypt(bytes(response[0x38:]))

When looking at the mp1 check_power_raw() code I noticed that type check is for offset 0x04 but it actually uses payload[0x0e] - is that intentional?

I have a patch lying around to read out the name of the device as well - not sure if that is valid for anything else than SP2 devices though.

eddyyanto commented 7 years ago

@vicfergar Ah, ok. Thanks for the info!

LordMyschkin commented 7 years ago

when testing the actual master branch, It seems this issue is still open.

persuader commented 7 years ago

Same issue here.

felipediel commented 3 years ago

Fixed with https://github.com/mjg59/python-broadlink/pull/72. Thank you!