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

[tesla] Adapt binding to changed API from Tesla backend #14922

Merged
merged 2 commits into from
May 2, 2023

Conversation

kaikreuzer
Copy link
Member

Fixes #14894

The Tesla API has removed most endpoints that the binding was using for querying vehicle data.
The only one left is an aggregated call to fetch all data at once.

This PR does the necessary changes.
In my tests, all seems to work well. If enough people report that it works for them as well, this would be a candidate to backport to 3.4.x.

@kaikreuzer kaikreuzer added bug An unexpected problem or unintended behavior of an add-on critical labels May 2, 2023
@kaikreuzer kaikreuzer requested a review from kgoderis as a code owner May 2, 2023 14:50
@kaikreuzer kaikreuzer changed the title Adapt binding to changed API from Tesla backend [tesla] Adapt binding to changed API from Tesla backend May 2, 2023
Signed-off-by: Kai Kreuzer <[email protected]>
@kaikreuzer kaikreuzer requested a review from a team May 2, 2023 15:08
Copy link
Contributor

@jlaur jlaur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking care of this!

There are some compiler and SAT warnings introduced, you could have a look at https://ci.openhab.org/job/PR-openHAB-Addons/15443/Static_20Code_20Analysis_20Report/summary_report.html#org.openhab.binding.tesla.internal.protocol.VehicleData.java for example.

For the particular DTO class, you can fix most of them by using the @SerializedName annotation and camelCasing the variables. The missing @NonNullByDefault can be ignored for now, or you could move all the classes to a dto directory to have them excluded from the check.

Most of the compiler warnings are because of changed code lines that already lacked proper null handling, so you can choose to ignore them for now.

Otherwise LGTM!

@kaikreuzer
Copy link
Member Author

@jlaur I intentionally created the new DTO in the same way as the others as I didn't want to introduce a mix of variable naming styles in the same package.
I'd rather suggest to do a clean-up refactoring as an independent PR that then covers all of the DTOs. But in order to have a chance to backport this PR here, I prefer to keep the changes as small as possible.

@jlaur
Copy link
Contributor

jlaur commented May 2, 2023

I'd rather suggest to do a clean-up refactoring as an independent PR that then covers all of the DTOs. But in order to have a chance to backport this PR here, I prefer to keep the changes as small as possible.

That's sounds sensible.

@jlaur jlaur merged commit f607dde into openhab:main May 2, 2023
@jlaur jlaur added this to the 4.0 milestone May 2, 2023
@hlemmens
Copy link

hlemmens commented May 2, 2023

Probably stupid from my side, but when I install the 4.0.0 SNAPSHOT .jar file, I get a "ERROR:HANDLER" and "HANDLER_MISSING_ERROR" on the Tesla bridge. Should I and how should I install a new handler?

@kaikreuzer kaikreuzer deleted the teslaapi branch May 3, 2023 07:00
@kaikreuzer
Copy link
Member Author

@hlemmens I'd suggest to simply update your openHAB to the latest 4.0.0-SNAPSHOT instance - the fixed binding is then a part of it and you do not need to install it manually.

@theater
Copy link
Contributor

theater commented May 3, 2023

Not sure if you need any feedback Kai, but I tested today and the fix works just fine on 4.0.0.
Cheers,
K.

@kaikreuzer
Copy link
Member Author

@theater Thanks, feedback is always welcome!

@hlemmens
Copy link

hlemmens commented May 3, 2023

@kaikreuzer. Many thanks for the fix and the hint. I managed to install the 3.4.4 Snapshot.jar and it works. The old issue [Tesla] Binding going offline #14435 is popping up again. In the 3.4.2 version it was fixed with the commit thijslemmens@24b74c5. Can this fix be integrated as well? Is it already done in the 4.0.0 SNAPSHOT version?

@kaikreuzer
Copy link
Member Author

In the 3.4.2 version it was fixed

Any fix that was in 3.4.2 should also have been done in 4.0.0, since we always only backport fixes, but never only fix things on older releases.

@hlemmens
Copy link

hlemmens commented May 4, 2023

I’m afraid the issue with the access token renewal was not fixed in 3.4.2. . The commit I mentioned in previous comment has not been accepted and integrated as far as I know.

@jlaur
Copy link
Contributor

jlaur commented May 4, 2023

@hlemmens - I don't see any pull requests from you, did you mean to create one?

@kaikreuzer
Copy link
Member Author

If you are referring to this "solution", I would say that it anyhow isn't something to merge, since recreating the http client all the time does not look like a proper way to fix it.

@hlemmens
Copy link

hlemmens commented May 5, 2023

This solution Is to my knowledge the only one that seems to work. Since I installed the fix for the changed Tesla API, every 8 hours I lose the connection with the car:
2023-05-05 07:28:40.348 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - Exchanging SSO refresh token for API access token
2023-05-05 07:28:40.380 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - An exception occurred while invoking a HTTP request: 'java.io.EOFException: HttpConnectionOverHTTP@d326f5::DecryptedEndPoint@1aa7a86{l=/my internal ip:39516,r=auth.tesla.com/23.55.96.81:443,OPEN,fill=-,flush=-,to=28816900/0}'

Happy to see a better solution than the existing one.

tb4jc pushed a commit to tb4jc/openhab-addons that referenced this pull request Jun 19, 2023
* Adapt binding to changed API from Tesla backend

Signed-off-by: Kai Kreuzer <[email protected]>
Signed-off-by: Thomas Burri <[email protected]>
matchews pushed a commit to matchews/openhab-addons that referenced this pull request Aug 9, 2023
* Adapt binding to changed API from Tesla backend

Signed-off-by: Kai Kreuzer <[email protected]>
Signed-off-by: Matt Myers <[email protected]>
austvik pushed a commit to austvik/openhab-addons that referenced this pull request Mar 27, 2024
* Adapt binding to changed API from Tesla backend

Signed-off-by: Kai Kreuzer <[email protected]>
Signed-off-by: Jørgen Austvik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on critical
Projects
None yet
4 participants