Ich habe eine eher einfache Szene erstellt, die schon seit einiger Zeit funktioniert.
Aber ich habe gestern oder vorgestern bemerkt, dass die Szene nichts mehr macht.
Ich habe eine Nachricht hinzugefügt, um zu sehen, ob sie sich auslöst, und bestätige, dass sie sich auslöst.
Dann habe ich „Invertieren“ durch „Gerät steuern“ ersetzt und die Steckdose auf „Ein“ gesetzt, und jetzt funktioniert es.
Ich denke, dass die Aktion „Invertieren“ irgendwo einen Bug hat, aber ich habe keine Informationen in den Logs.
Hat jemand dieses Problem schon einmal gehabt?
Vielen Dank im Voraus für die Hilfe beim Debuggen ^^
Hallo zusammen!
Dieses Thema ist nun in Entwicklung .
Ein Pull Request wurde eröffnet, um die Umkehrung der Steckdosen zu beheben, die nicht mehr dem tatsächlichen Zustand des Geräts entsprach:
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.
Zögert nicht, dem PR zu folgen, zu testen (optional, vor allem bei kleinen Anfragen) und euer Feedback hier zu hinterlassen, falls nötig.