bisand / tibber-api

Tibber API node module
MIT License
32 stars 6 forks source link

Breaking change in Tibber API websockets #22

Closed toini closed 1 year ago

toini commented 1 year ago

Hi!

I would like to thank you for contributing to the community of Tibber users! We've added you to the list of people we respect! https://developer.tibber.com/respect

In order to improve the API resilience we are making a breaking change for websocket communication. Please see details at developer site. Would you be able to adjust the implementation accordingly?

Also, note that recommended format for setting user agent header would be to include both the platform version and driver version for example like this: MyHomeAutomationDevice/1.2.3 bisand/4.1.0'

We're trying to collect best practices here

Let us know if in need of any assistance!

Br, Toni Tibber

bisand commented 1 year ago

Hi!

I would like to thank you for contributing to the community of Tibber users! We've added you to the list of people we respect! https://developer.tibber.com/respect

In order to improve the API resilience we are making a breaking change for websocket communication. Please see details at developer site. Would you be able to adjust the implementation accordingly?

Also, note that recommended format for setting user agent header would be to include both the platform version and driver version for example like this: MyHomeAutomationDevice/1.2.3 bisand/4.1.0'

We're trying to collect best practices here

Let us know if in need of any assistance!

Br, Toni Tibber

Hi, and thanks for the heads up. I will go through the documentation and see if I am able to make the changes before the deadline in December. I will report back here on the progress.

Thanks!

toini commented 1 year ago

Awesome, thanks!

bisand commented 1 year ago

@toini do you have a test endpoint that has already implemented the breaking changes? It would be nice to test the changes before publishing a new version.

toini commented 1 year ago

@bisand production does already support the breaking changes. You can try that for example at https://developer.tibber.com/explorer

toini commented 1 year ago

Hi @bisand, I'm looking through the logs and I'm seeing a lot of reconnects for user agent bisand/tibber-api/5.0.0-beta.6. 101099 of them during the past 4 days. And, for example, during the past 24 hours one user reconnected 12 000 times.

What kind of reconnection logic do you have in place? Are you reconnecting if there is no data for x seconds, for example?

bisand commented 1 year ago

Hi @bisand, I'm looking through the logs and I'm seeing a lot of reconnects for user agent bisand/tibber-api/5.0.0-beta.6. 101099 of them during the past 4 days. And, for example, during the past 24 hours one user reconnected 12 000 times.

What kind of reconnection logic do you have in place? Are you reconnecting if there is no data for x seconds, for example?

Hi @toini I see that I have a default reconnect timeout if no data is received for 30 seconds. This can also be changed by the user. After reading a bit more on your documentation, I see that I will have to improve the reconnect logic. I will do some work the next few days to try to improve the logic.

toini commented 1 year ago

Thanks a lot @bisand! Exponential back off combined with checking whether a real time enabled device still exists would improve things a lot. Sounds like one user reconnecting 12 000 times a day has either tweaked reconnect interval a lot more frequent (once per 30 seconds would yield 2880 per day) or there could be something else going wrong triggering an immediate reconnect?

bisand commented 1 year ago

Hi @toini A new version of tibber-api is released which should address the connection issues. I have implemented exponential backoff with jitter and a check if real time subscription is enabled. Hopefully all consumers of the API will upgrade as soon as possible. I will also deprecate all older versions on NPM for better communication. If the problem remains, you can try to block problematic user agent versions. The user agent is automatically generated with correct version number during build, so it could make it easier for you to filter out potential bad versions in the future. Please let me know if you see any other potential improvements

toini commented 1 year ago

Nice work! Is the newest version bisand/tibber-api/5.1.6? Ones with many reconnects seem to be running bisand/tibber-api/5.0.0-beta.6.

bisand commented 1 year ago

Yes, the newest version is bisand/tibber-api/5.1.6. All previous versions have been deprecated in the NPM registry.

toini commented 1 year ago

I noticed one user is repeatedly going to error apparently when sending invalid homeId:

2023-01-11T00:43:01.412+02:00   2023-01-10T22:43:01.412Z ERROR [websocket] on error (onNext); userId 87cfcf24-a306-4c9b-x-x; userIp 51.175.x.x; userAgent bisand/tibber-api/5.0.0-beta.6; errors Invalid homeId
2023-01-11T00:46:02.864+02:00   2023-01-10T22:46:02.864Z ERROR [websocket] on error (onNext); userId 87cfcf24-a306-4c9b-x-x; userIp 51.175.x.x; userAgent bisand/tibber-api/5.0.0-beta.6; errors Invalid homeId
2023-01-11T00:47:03.339+02:00   2023-01-10T22:47:03.338Z ERROR [websocket] on error (onNext); userId 87cfcf24-a306-4c9b-x-x; userIp 51.175.x.x; userAgent bisand/tibber-api/5.0.0-beta.6; errors Invalid homeId

I'll start requiring the latest version.

bisand commented 1 year ago

Closing.