J’ai fais une scene plutôt simple qui fonctionne depuis un bon moment.
Mais j’ai remarqué depuis hier ou avant hier que la scene ne fais plus rien.
J’ai ajouté un message pour voir si elle se déclenchait bien et je confirme qu’elle se déclenche.
J’ai alors remplacer inversé par controller un appareil et j’ai mis la prise sur on et la ça fonctionne.
Je pense que l’action inversé doit bug a un endroit mais j’ai aucune info dans les logs.
Quelqu’un a eu ce genre de problème ?
Merci par avance pour m’aider a débuguer ^^
Salut tout le monde !
Ce sujet est désormais en cours de développement .
Une PR a été ouverte pour corriger l’inversion des prises qui ne suivait plus l’état réel de l’appareil :
master ← claude/bug-inverse-prises-28peh7
ouvert 08:48AM - 04 Sep 26 UTC
### Description
A user reported on the forum that a scene using the **"Toggle s… witches"** (inverser) action stopped working on a plug, while replacing it with "Turn on switches" works. Nothing in the logs.
**Root cause.** Every store of the `StateManager` merges an update into the object it already holds (`Store.setState` does an `Object.assign`). When a device already loaded in RAM is saved again (edited in the UI, re-discovered by an integration, a feature added through `device.addFeature`...), `device.add` receives a fresh object from the DB:
- the `device` store merges it, so `device.features` now points to the **new** feature objects;
- the `deviceFeature` / `deviceFeatureById` / `deviceFeatureByExternalId` stores merge each new feature into the objects they held **from the first load**, and keep those.
From that moment the two views are different objects. `device.saveState` writes the new `last_value` only into the `deviceFeature` store, so anything reading a feature *through the device* (`stateManager.get('device', selector)` + `getDeviceFeature`) sees a `last_value` frozen at the time of the save, until the next restart. That is exactly what the scene toggle actions on switches and lights do (`last_value === 0 ? 1 : 0`): with a stale `last_value`, the toggle keeps sending the same value, and the plug never turns on. The voice switch/light commands and the blink action read the feature the same way.
**Fix.** `device.add` now merges each incoming feature into the object already in RAM (when there is one) and puts that object back into the device's `features` array, so every store shares a single object per feature. Nothing else changes: `device.create`, `device.init` and `device.addFeature` all go through `device.add`.
**Tests.** New `server/test/lib/device/device.add.test.js`: loads a device, adds it again from a fresh object, then simulates a new state as `device.saveState` stores it and checks the device seen from the `device` / `deviceById` stores reflects it (the test fails on `master`). It also covers a device re-added with its own objects and a brand new feature.
## Forum
Forum: https://community.gladysassistant.com/t/soucis-inverse-les-prises-ne-semble-pas-fonctionne/10790
### Checklist
- [x] Tests pass: `cd server && npm run coverage` (Codecov requires 100% coverage on changed lines) and Cypress (`npm run cypress:run`) if the UI changed
- [x] Linter and prettier pass on both front and server (`npm run eslint`, `npm run prettier`)
- [x] No undocumented breaking change
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01Qx6P7ZdwruxTUCnBAuC51T
---
_Generated by [Claude Code](https://claude.ai/code/session_01Qx6P7ZdwruxTUCnBAuC51T)_
## Summary by CodeRabbit
* **Bug Fixes**
* Improved device feature synchronization so updated feature values remain consistent across the device and feature stores.
* Preserved feature references when devices are re-added, preventing stale or mismatched state.
* Ensured newly added device features correctly receive subsequent state updates.
* **Tests**
* Added coverage for device and feature storage, indexing, re-adding devices, and state synchronization.
N’hésitez pas à suivre la PR, à tester (optionnel, surtout pour les petites demandes) et à faire vos retours ici si besoin.