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] Add event stream & handling post new authentication process #13116

Merged
merged 1 commit into from
Sep 21, 2022

Conversation

kgoderis
Copy link
Contributor

[Tesla] Add event stream & handling post new authentication process by Tesla

Signed-Off-By: Karel Goderis karel.goderis@me.com

@kgoderis kgoderis added the enhancement An enhancement or new feature for an existing add-on label Jul 12, 2022
@kgoderis kgoderis requested a review from wborn July 15, 2022 11:59
Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

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

I am getting a

08:59:53.057 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.initialize()' on 'org.openhab.binding.tesla.internal.handler.TeslaVehicleHandler@58e4ad2d': null
java.lang.NullPointerException: null
	at org.openhab.binding.tesla.internal.handler.TeslaVehicleHandler.initialize(TeslaVehicleHandler.java:156) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [org.openhab.core-3.4.0-SNAPSHOT.jar:?]
	at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [org.openhab.core-3.4.0-SNAPSHOT.jar:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:834) [?:?]

which seems to be due to the fact that you missed to add the new parameter to the config descriptions in the OH-INF/thing thing desciption files.

@kgoderis kgoderis force-pushed the tesla-events branch 2 times, most recently from e7e9bd0 to 1546111 Compare July 30, 2022 15:47
…y Tesla

Signed-Off-By: Karel Goderis <karel.goderis@me.com>
@kgoderis
Copy link
Contributor Author

@kaikreuzer Done.

@kaikreuzer
Copy link
Member

Thanks @kgoderis!

I just tested it and have some issues, where I'd need your input:

  1. When switching new the configuration parameter on and saving the Thing, I get this in my log:
20:47:25.020 [WARN ] [internal.handler.TeslaVehicleHandler] - Exception occurred in slowStateRunnable
java.util.ConcurrentModificationException: null
	at java.util.ArrayList.sort(ArrayList.java:1751) ~[?:?]
	at org.apache.cxf.jaxrs.provider.ProviderFactory.sortReaders(ProviderFactory.java:734) ~[?:?]
	at org.apache.cxf.jaxrs.provider.ProviderFactory.setCommonProviders(ProviderFactory.java:662) ~[?:?]
	at org.apache.cxf.jaxrs.client.ClientProviderFactory.setProviders(ClientProviderFactory.java:73) ~[?:?]
	at org.apache.cxf.jaxrs.provider.ProviderFactory.setUserProviders(ProviderFactory.java:862) ~[?:?]
	at org.apache.cxf.jaxrs.client.spec.ClientImpl$WebTargetImpl.request(ClientImpl.java:282) ~[?:?]
	at org.apache.cxf.jaxrs.client.spec.ClientImpl$WebTargetImpl.request(ClientImpl.java:377) ~[?:?]
	at org.openhab.binding.tesla.internal.handler.TeslaVehicleHandler.queryVehicle(TeslaVehicleHandler.java:730) ~[?:?]
	at org.openhab.binding.tesla.internal.handler.TeslaVehicleHandler.queryVehicleAndUpdate(TeslaVehicleHandler.java:764) ~[?:?]
	at org.openhab.binding.tesla.internal.handler.TeslaVehicleHandler.lambda$0(TeslaVehicleHandler.java:969) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:834) [?:?]

I am not perfectly sure, if it is related to this PR or if it happens without it already, but I wonder if you can reproduce this?

  1. I seem to have correctly activated the events, since I see this in my log:
20:53:20.621 [DEBUG] [.internal.handler.TeslaEventEndpoint] - TeslaEventEndpoint-1 : The client to connect to wss://streaming.vn.teslamotors.com/streaming/ is already running
20:53:20.622 [DEBUG] [.internal.handler.TeslaEventEndpoint] - TeslaEventEndpoint-1 : Connecting to wss://streaming.vn.teslamotors.com/streaming/
20:53:20.745 [DEBUG] [.internal.handler.TeslaEventEndpoint] - TeslaEventEndpoint-1 : Connected to streaming.vn.teslamotors.com/52.210.104.4 with hash 1296744804

But after this, the only event I ever see is

20:53:20.745 [DEBUG] [internal.handler.TeslaVehicleHandler] - Event : Received hello

Changes of the vehicle state only come in through the regular polling, but I do not see any immediate events being sent for them.
Is there anything else that I'd need to enable/activate to receive such events?

@kgoderis
Copy link
Contributor Author

kgoderis commented Aug 3, 2022

Thanks @kgoderis!

I just tested it and have some issues, where I'd need your input:

  1. When switching new the configuration parameter on and saving the Thing, I get this in my log:
20:47:25.020 [WARN ] [internal.handler.TeslaVehicleHandler] - Exception occurred in slowStateRunnable
java.util.ConcurrentModificationException: null
	at java.util.ArrayList.sort(ArrayList.java:1751) ~[?:?]
	at org.apache.cxf.jaxrs.provider.ProviderFactory.sortReaders(ProviderFactory.java:734) ~[?:?]
	at org.apache.cxf.jaxrs.provider.ProviderFactory.setCommonProviders(ProviderFactory.java:662) ~[?:?]
	at org.apache.cxf.jaxrs.client.ClientProviderFactory.setProviders(ClientProviderFactory.java:73) ~[?:?]
	at org.apache.cxf.jaxrs.provider.ProviderFactory.setUserProviders(ProviderFactory.java:862) ~[?:?]
	at org.apache.cxf.jaxrs.client.spec.ClientImpl$WebTargetImpl.request(ClientImpl.java:282) ~[?:?]
	at org.apache.cxf.jaxrs.client.spec.ClientImpl$WebTargetImpl.request(ClientImpl.java:377) ~[?:?]
	at org.openhab.binding.tesla.internal.handler.TeslaVehicleHandler.queryVehicle(TeslaVehicleHandler.java:730) ~[?:?]
	at org.openhab.binding.tesla.internal.handler.TeslaVehicleHandler.queryVehicleAndUpdate(TeslaVehicleHandler.java:764) ~[?:?]
	at org.openhab.binding.tesla.internal.handler.TeslaVehicleHandler.lambda$0(TeslaVehicleHandler.java:969) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:834) [?:?]

I am not perfectly sure, if it is related to this PR or if it happens without it already, but I wonder if you can reproduce this?

This I have not observed, but I only tested the PR in Eclipse. I will check it

  1. I seem to have correctly activated the events, since I see this in my log:
20:53:20.621 [DEBUG] [.internal.handler.TeslaEventEndpoint] - TeslaEventEndpoint-1 : The client to connect to wss://streaming.vn.teslamotors.com/streaming/ is already running
20:53:20.622 [DEBUG] [.internal.handler.TeslaEventEndpoint] - TeslaEventEndpoint-1 : Connecting to wss://streaming.vn.teslamotors.com/streaming/
20:53:20.745 [DEBUG] [.internal.handler.TeslaEventEndpoint] - TeslaEventEndpoint-1 : Connected to streaming.vn.teslamotors.com/52.210.104.4 with hash 1296744804

But after this, the only event I ever see is

20:53:20.745 [DEBUG] [internal.handler.TeslaVehicleHandler] - Event : Received hello

Changes of the vehicle state only come in through the regular polling, but I do not see any immediate events being sent for them. Is there anything else that I'd need to enable/activate to receive such events?

Well, what I know is that if the vehicle is not moving, or does not have a reason to report data, the stream basically times out after 10 seconds or so. At least on my old Model S (yes, still driving that one after 7 years LOL) I do get the hello message, and exactly one regular event. Maybe things are different for the newer cars or other models. What I observe seems to be in line with timdorr/tesla-api#97 but I have not had the time yet to test things fully when actually driving with my laptop on my lap.

@kaikreuzer
Copy link
Member

This I have not observed, but I only tested the PR in Eclipse. I will check it

I actually saw this when testing in Eclipse.

if the vehicle is not moving, or does not have a reason to report data, the stream basically times out after 10 seconds or so.

Ok, I can try to test as well, once I am back home from vacation.

Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

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

I now had a chance to test it when my wife drove with the car - at least when I started openHAB while the car was in motion, I received events every second (mainly location updates). Once the car parked, the websocket was immediately closed again. Not sure if everything works to also recover the stream once the car moves again, I didn't see this.

But all in all, it didn't seem to cause any issues, so let's finally merge this PR!

@kaikreuzer kaikreuzer merged commit 062a7c1 into openhab:main Sep 21, 2022
@kaikreuzer kaikreuzer added this to the 3.4 milestone Sep 21, 2022
leifbladt pushed a commit to leifbladt/openhab-addons that referenced this pull request Oct 15, 2022
…y Tesla (openhab#13116)

Signed-Off-By: Karel Goderis <karel.goderis@me.com>
seime pushed a commit to seime/openhab2-addons that referenced this pull request Oct 16, 2022
…y Tesla (openhab#13116)

Signed-Off-By: Karel Goderis <karel.goderis@me.com>
andan67 pushed a commit to andan67/openhab-addons that referenced this pull request Nov 6, 2022
…y Tesla (openhab#13116)

Signed-Off-By: Karel Goderis <karel.goderis@me.com>
andrasU pushed a commit to andrasU/openhab-addons that referenced this pull request Nov 12, 2022
…y Tesla (openhab#13116)

Signed-Off-By: Karel Goderis <karel.goderis@me.com>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
@jirom
Copy link

jirom commented Dec 18, 2022

Does this still work as expected? In the logs, I never see the Event : Received an update.... line ever logged.
When the car is awake, the logs shows that it receives hello but never receives any other event.

2022-12-17 17:02:22.859 [TRACE] [internal.handler.TeslaVehicleHandler] - Event : Pinging the Tesla event stream infrastructure
2022-12-17 17:02:22.859 [TRACE] [.internal.handler.TeslaEventEndpoint] - TeslaEventEndpoint-3 : Received raw data '{"msg_type":"control:hello","connection_timeout":0}'
2022-12-17 17:02:22.859 [DEBUG] [internal.handler.TeslaVehicleHandler] - Event : Received hello
2022-12-17 17:02:22.871 [TRACE] [.internal.handler.TeslaEventEndpoint] - TeslaEventEndpoint-3 : Received a Pong with a roundtrip of 11 milliseconds
2022-12-17 17:02:34.860 [TRACE] [internal.handler.TeslaVehicleHandler] - Event : Pinging the Tesla event stream infrastructure
2022-12-17 17:02:34.872 [TRACE] [.internal.handler.TeslaEventEndpoint] - TeslaEventEndpoint-3 : Received a Pong with a roundtrip of 11 milliseconds
2022-12-17 17:02:46.861 [TRACE] [internal.handler.TeslaVehicleHandler] - Event : Pinging the Tesla event stream infrastructure
2022-12-17 17:02:46.873 [TRACE] [.internal.handler.TeslaEventEndpoint] - TeslaEventEndpoint-3 : Received a Pong with a roundtrip of 11 milliseconds
2022-12-17 17:02:58.862 [TRACE] [internal.handler.TeslaVehicleHandler] - Event : Pinging the Tesla event stream infrastructure
...

borazslo pushed a commit to borazslo/openhab-mideaac-addon that referenced this pull request Jan 8, 2023
…y Tesla (openhab#13116)

Signed-Off-By: Karel Goderis <karel.goderis@me.com>
psmedley pushed a commit to psmedley/openhab-addons that referenced this pull request Feb 23, 2023
…y Tesla (openhab#13116)

Signed-Off-By: Karel Goderis <karel.goderis@me.com>
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this pull request Feb 28, 2023
…y Tesla (openhab#13116)

Signed-Off-By: Karel Goderis <karel.goderis@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants