New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create SP3S class and improve energy monitoring #483
Conversation
Hi Felipe, Thank you for continuing to test, unforunately this version loses the power attribute on the Neo Pro. |
get_energy() doesn't work? You said that this formula worked, so I added it here. Any idea of what's going on? |
Let me look into it a little more and I'll report back, my mind is on the turkey right now. Probably not until tonight/tomorrow. |
My mistake, I was looking at the prior version of the code. Just tested your changes and good to go, THANKS |
Thank you! |
Hello, im not sure if its related to this issue but get_energy() on my SP3S always returns like 30 watts more than in the IHC. |
Hi @Stormhand! Not the same thing. You need to open an issue an provide some data so we can understand what is going on. I would risk saying that it happens because we round up incoming data. |
Thank you, ill do it. BTW the change here is throwing:
|
@tottka Sorry to bother you again. Do the SP2 get_energy() values match the app exactly? If not, does this method work? def get_energy(self) -> float:
"""Return the energy state of the device."""
packet = bytearray(16)
packet[0] = 4
response = self.send_packet(0x6A, packet)
check_error(response[0x22:0x24])
payload = self.decrypt(response[0x38:])
return float("{:x}{:x}.{:x}".format(*payload[0x06:0x03:-1])) |
1st, The new version disabled ALL my Ankuoo devices in HA, even the ones that don't use wattage. I can't understand that line of code to even begin to offer any help. 2nd, I tested on both the kettle and a 60 watt bulb and neither matched the app. I could have sworn we had this working? If you make another change I'll keep testing, no problem |
Thank you! I have a few guesses on how this works. Could you help me with some captures so that I have more information to work with?
import broadlink as blk
d = blk.hello("192.168.0.16") # Example device
d.auth()
print(d.decrypt(d.send_packet(0x6a, bytes([4]))[0x38:]))
|
Lucky guess no 1: def get_energy(self) -> float:
"""Return the energy state of the device."""
packet = bytearray(16)
packet[0] = 4
response = self.send_packet(0x6A, packet)
check_error(response[0x22:0x24])
payload = self.decrypt(response[0x38:])
return int.from_bytes(payload[0x4:0x7], "little") / 1000 It matches the data you gave me. |
I am so over my head! Here's how I've been testing, I go to /srv/homeassistant/lib/python3.8/site-packages/broadlink/switch.py |
Sorry, there was a typo. Could you please try again? |
The APP & HA update on different cycles and electricity usage varies depending on the device. Kettle 60 watt bulb Air Cleaner on Low Air Cleaner on Med Air Cleaner on High |
Good! Thank you very much for the tests! |
Whatever you decide to do is fine by me. I only use it to tell if a device is currently running or not. |
d06834f
to
29bc6d1
Compare
Hi @Amir974. Sorry to bother you. I just remembered that you have a device that will be affected by this change. Do you mind helping me test how your SP2-IL respond to the new sp2.get_energy() method? I need this information to handle the exception correctly in Home Assistant. |
Hi @tottka. Yes, me again. Sorry. Mind checking how your Ankuoo NEO (0x2717) respond to sp2.get_energy()? I need this information to handle the exception correctly in Home Assistant. |
@felipediel with pleasure |
Would be glad to, but I don't know where to find your latest changes?
I have very limited GitHub skills, usually I just copy/paste what you provide.
…________________________________
From: Felipe Martins Diel <notifications@github.com>
Sent: Tuesday, December 22, 2020 5:39 PM
To: mjg59/python-broadlink <python-broadlink@noreply.github.com>
Cc: tottka <tottka@hotmail.com>; Mention <mention@noreply.github.com>
Subject: Re: [mjg59/python-broadlink] Create SP3S class and improve energy monitoring (#483)
Hi @tottka<https://github.com/tottka>. Yes, me again. Sorry. Mind checking how your Ankuoo NEO (0x2717) respond to sp2.get_energy()? I need this information to handle the exception correctly in Home Assistant.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#483 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ADHGXNF422ZVYN2LSTDQWZDSWE347ANCNFSM4UDIEW3A>.
|
I made a debug script to make it easier. Download the file, open the folder on a terminal and type: python3 sp2.py 192.168.0.16 # Example device You can do it on your PC. I need the output. |
@felipediel I might need some assistance to move forward I am getting the following:
|
It means you need to install git and add it to the PATH. You can avoid dependencies with that script above. It only needs Python 3 installed. |
@felipediel I hope I got it,
|
That's exactly what we were looking for! Thank you very much @Amir974! |
This is probably not what you are looking for? |
We were looking for the exception too. The devices are different, we need to handle the invalid request for both. Thank you very much @tottka! |
* Refactor the LB1 class * General improvements * Enumerate bulb color modes * Clean up encoder Co-authored-by: Felipe Martins Diel <felipe-diel@hotmail.com>
Closing to merge into the dev branch. |
Breaking change
Create a new SP3S class for these devices. Applications need to use the correct class to support get_energy().
The problem
Some SP2 devices (PID starting with 0x27) support get_energy(), but the firmware is different from SP3S, so we need to create another method.
From:
#413 (comment)
#200 (comment)
Proposed changes
Need help with tests
These smart plugs don't support energy monitoring. They respond to sp3s.get_energy() with CommandNotSupportedError and StorageError. This is the behavior we had in the past, so we were catching the exceptions eg here.
It would be interesting to see how they respond to this new sp2.get_energy() method before the code is merged. So, if anyone has the smart plugs on the list, please help to test this method.
On your PC:
Now let's see how the device respond to get_energy():
Thanks in advance!