Service Netatmo

I asked Claude, and according to him, there are two issues:

  1. A likely broken OAuth refresh since the undici migration (Bearer on an expired token, bug introduced in this PR: fix: Netatmo service to replace axios with undici for HTTP requests by Terdious · Pull Request #2256 · GladysAssistant/Gladys · GitHub).
  2. A « wipe everything » policy as soon as a refresh fails, turning any temporary error into a lasting disconnection.

@Terdious I’m at your disposal if you need help fixing it :slight_smile:

Thanks to everyone for your feedback!

It was 12:30 AM on my end.

Hello everyone!

Same for me!

Sorry for the delay, I haven’t touched the PC for 2 weeks, my parents are at home. And I sprained my thumb and index finger at the beginning of the week. :face_with_peeking_eye::face_with_peeking_eye:

I’ll try to look at it this weekend.

Thanks @pierre-gilles for the initial analysis… and sorry for introducing the bug

No worries @Terdious, no rush…

Get well soon!

Oh no! Do you want me to make a PR on Monday? I won’t be able to test, but I can run Claude on the topic :joy:

Hello!

I’m on it.

I noticed, especially on HA, that there should be no Authorization header on /oauth2/token. I’m also taking this opportunity to improve the user info feedback on the front end during a reconnection on the setup page.

PR created here:

I took the opportunity to create a second PR to improve the existing feedback as well. In some error cases, the integration wasn’t detected as disconnected and remained visually as « Connected » even if it wasn’t the case (e.g., failed discover). So I’m taking the opportunity to reuse the automatic reconnection function. PR2:

Thanks @Terdious!

That works for me, I’ve merged the first PR. Thanks for taking the time to review and suggest the corrections :folded_hands:

For the second PR, since it’s based on the first, there are now some conflicts. Could you rebase master to resolve them?

Thanks! :grinning_face_with_smiling_eyes:

You’re welcome, it’s normal!

It’s fine for me on the second PR, it’s rebased.

For info, the evolution also triggers the automatic reconnection cycle when Netatmo rejects the access token. Without this, clicking on « Refresh » on the Discovery page or retrieving values when the Netatmo application is disabled did not trigger any error message.

We now have clear information about the reconnection status on all integration pages. The retry cycles are: 30s → 60s → 120s → 300s, then 300s recurring indefinitely.



That’s good for me, it’s merged and it will go out in the next version of Gladys :slight_smile:

Thanks for all these fixes :raising_hands:

The fixes are available in Gladys Assistant 4.80:

Thanks @Terdious for the fixes :slight_smile:

Hello everyone! :waving_hand:

The Netatmo project is back on track! Before resuming the development of the camera integration (the old PR #2032, automatically closed for inactivity — a new dedicated topic is coming very soon), we decided to start by cleaning up the current service: a complete audit of the service history, followed by a series of targeted fixes.

Result: 4 PRs, all tested and validated in real conditions on my installation (thermostat, about ten valves, relays, weather station and its modules — including several devices intentionally powered off, which actually revealed a nice bug :grinning_face_with_smiling_eyes:).

The 4 PRs (in the recommended merge order)

1. #2620 — Discovery of powered-off devices :red_circle: to be merged first
A single module powered off in your home (e.g., the relay of a heat pump turned off outside the heating season) was enough to completely freeze the discovery page (page reload required), with a device named « undefined ». These modules are now properly rebuilt from the API (name, room), displayed with an explicit message « Unreachable device… (code: 6) », marked offline, and remain recordable — their values will be reported as soon as they are powered back on.

2. #2617 — Zero values are no longer lost
0 mm of rain, 0 °C, wind from the north sector (0°), gusts at 0 km/h… were treated as « missing » values (replaced by potentially different fallback data, or emitted as empty states). This is fixed: zero is a real value, and no ghost states are recorded when the data is actually absent.

3. #2618 — Connection robustness

  • a thermostat setpoint that fails no longer crashes the service silently: the failure is now properly propagated and traced (server logs + service status visible on the integration pages). Note: the Gladys dashboard does not yet display command failures — this is a general limitation of Gladys’ core (asynchronous architecture of actions), this PR lays the groundwork for future visual feedback to be possible;
  • the access token is refreshed at 80% of its lifetime (before: right at expiration, with a window of dead token);
  • device values are retrieved immediately after OAuth connection (before: up to 2 minutes wait);
  • end of features named « Minimum in undefined » for modules without a room.

4. #2619 — Internal refactor (based on #2617)
The 8 duplicated update files are replaced by a single declarative table: -370 lines of code, zero behavior change (the entire test suite passes without modifying a single expected value). This is mainly the foundation that will make adding future device types — the cameras! — much simpler.

Quality

100% test coverage on all affected code, checklists completed, CodeRabbit remarks addressed (3 fixed, the rest dismissed with justification).

@pierre-gilles everything is ready for review :slightly_smiling_face: Recommended merge order: #2620#2617#2618#2619 (PR #2620 is included in the other three branches as it is essential for testing; once merged, their diffs will be reduced accordingly. PR #2619 is stacked on PR #2617).

To be continued in the next episode: the resumption of Netatmo cameras, with a dedicated topic :video_camera:

Excellent !!! Thanks @Terdious for the monster job you do :star_struck:

Thanks @mutmut,

I must admit that today less than before actually… I mostly do driving and AI prompting. Proofreading during coding, testing on the fly, feedback and reflection/validation!^^ Then complete testing, and indicating directions to take, especially, I do a lot of forum and GitHub research to always tell the AI to refer to discussions already made, to past development experiences, to design decisions.

For Netatmo, I was able to give it many past sources, reviews from Pierre-Gilles, my own mistakes, etc., so as not to repeat them or take the wrong path. It seems to be working well! But only the reviews reveal it ^^ Because it still makes mistakes :sweat_smile: and especially, my fault, I miss some. But less than when I was coding entirely.

Awesome, thanks for these PRs! I’ll let you know as soon as I’ve had a look :slight_smile: