Skip to content
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

Generate API key #336

Merged
merged 4 commits into from
Nov 8, 2024
Merged

Generate API key #336

merged 4 commits into from
Nov 8, 2024

Conversation

hrrrsn
Copy link
Contributor

@hrrrsn hrrrsn commented Nov 8, 2024

Fixes #331 , #333, #334

@sockless-coding
Copy link
Owner

I'm still getting the precondition failed

@hrrrsn
Copy link
Contributor Author

hrrrsn commented Nov 8, 2024

Hmm. I only had my units installed 3 days ago (post-API change - disappointing) so I'm using a fresh install/login if that makes a difference - they're working correctly, I have no errors.

One part I'm not entirely clear on is the cfc injection. The header you posted in the issue is missing it, but every request I've generated from iOS has it present.

@sockless-coding
Copy link
Owner

The android version has the cfc as well, could be some issue with something not getting encoded correctly maybe special chars in the token

@sockless-coding
Copy link
Owner

I did a replay of using the method:
Expected: 02230b977cfc86179cac19e48bd387062ed43222ded416377c87e0806ced8385206
Got: 7940423d8cfc47d6907152d7c445b5df85efd8629495fe95d060e172e0f787f866b

@hrrrsn
Copy link
Contributor Author

hrrrsn commented Nov 8, 2024

My Home Assistant container is running in UTC, so it's possible I'm tripping over timezones. Does that change anything for you?

@sockless-coding
Copy link
Owner

Yes, that's the issue converting the time to UTC before turning it into a timestamp fixes the issue

@sockless-coding
Copy link
Owner

I moved the utc conversion, since the timestamp sent by the client is the local time

@sockless-coding
Copy link
Owner

just to make it look like their requests

@sockless-coding sockless-coding merged commit f4065bd into sockless-coding:master Nov 8, 2024
@sockless-coding
Copy link
Owner

@hrrrsn great job!

@raczgy
Copy link

raczgy commented Nov 8, 2024

It works, thank you! I'm not sure who I should buy the coffee for. :)

@Garagoos
Copy link

Garagoos commented Nov 8, 2024

Absolutely fantastic work - thank you very much

I would like to buy more than one coffee - but I don't have a credit card

@hrrrsn @sockless-coding

Do you have a Paypal account? I think this work should be supported and honored!

@codyc1515
Copy link
Contributor

Would it not now be prudent to reduce the polling frequency or even just make that a toggle?

@sockless-coding
Copy link
Owner

@codyc1515 there are already options to set the polling rate separate for data and energy and a button to request new data.

@AnonymousRetard
Copy link

@hrrrsn Great job! Would you mind a short explanation of how you found this out? Was it by reverse engineering, and if so with what tools?

I'm currently at work after a good nights sleep but I remember seeing the "Bearer: ", "cfc" and some string manipulation starting at position 9 yesterday, but it would have taken me quite a few more hours to finally put it all together like this.

@notio-ca
Copy link

notio-ca commented Nov 8, 2024

@hrrrsn @sockless-coding You are genius and my hero, I have a 4 head Panasonic, I depend on this integration a lot.
Hope they don't change their API too often.
Cheers!

@codyc1515
Copy link
Contributor

I would also really enjoy seeing a write up or any pointers on how you did this. I’d like to do the same for BYD.

@sockless-coding
Copy link
Owner

@codyc1515 depending on how much of the code is located in a native lib, it might not be worth the effort. But you can always throw the lib at https://dogbolt.org/ and see what comes out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Precondition Failed
7 participants