Hice una escena bastante simple que ha funcionado durante mucho tiempo.
Pero me he dado cuenta desde ayer o antes de ayer que la escena ya no hace nada.
Añadí un mensaje para ver si se activaba correctamente y confirmo que se activa.
Luego cambié invertido por controlar un dispositivo y puse el enchufe en on y así funciona.
Creo que la acción invertida debe tener un error en algún lugar, pero no tengo información en los registros.
¿Alguien ha tenido este tipo de problema?
Gracias de antemano por ayudarme a depurar ^^
¡Hola a todos!
Este tema ahora está en desarrollo .
Se ha abierto una PR para corregir la inversión de los enchufes que ya no seguía el estado real del dispositivo:
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.
No duden en seguir la PR, probar (opcional, especialmente para pequeñas solicitudes) y dar sus comentarios aquí si es necesario.