Repository navigation
Store capability value before firing "changed" flow triggers - #306
Merged
Merged
Conversation
Capability listeners fired their "<capability> changed" flow trigger right after sending the command to the HVAC, before the new value was stored. Homey only stores the value after the listener resolves (and triggerCapabilityListener() from our action cards does not store it at all), so flows started by the trigger evaluated conditions such as "Power save mode is On" against the previous value and took the wrong branch. Store the value first, then fire the trigger, via a shared helper. A rejected trigger is now logged instead of becoming an unhandled rejection. Refs #305 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aivus
enabled auto-merge (squash)
November 21, 2026 18:17
aivus
added a commit
that referenced
this pull request
Nov 21, 2026
Resolved package-lock.json by taking master's and re-running npm install, so the tree carries master's dependency bumps (homey 4.6.3, jest 30.5.2) plus mqtt. package.json merged cleanly. Mirrors #306 into the cloud driver: its capability listeners fired the "<capability> changed" trigger before the new value was stored, so flows started by the trigger read the previous value. The cloud device.js is a deliberate copy of the local capability bridge (see CLAUDE.md), so the fix has to be applied to both -- it gains the same _setCapabilityValueAndTrigger helper and two tests covering the ordering and a rejecting trigger. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #305
Problem
Every capability listener (fan speed, turbo, 8°C heating, lights, X-Fan, vertical/horizontal swing, quiet, health, power save, sleep, fresh air) fired its
<capability> changedflow trigger right after sending the command to the HVAC, before the new value was stored:triggerCapabilityListener(), which only runs the listener;app.jsstores the value after it resolves.So a flow started by e.g. "Power save mode changed" that checks "Power save mode is On" read the previous value and took the wrong branch, which matches the symptom in #305. The device-polling path already stored the value first and wasn't affected.
Change
_setCapabilityValueAndTrigger()helper indevice.js:await setCapabilityValue(), then fire the trigger. All 12 listeners use it.this.errorinstead of becoming an unhandled rejection.setCapabilityValue/promise-returning triggers; added regression tests for the ordering and for a rejecting trigger.Notes
Refsrather thanFixes: the reporter says Health mode works although it had the same ordering. That's likely down to the race between the trigger and the value write, but it should be confirmed by the reporter on a test build. Mode restrictions on the unit (e.g. power save only in Cool) may also play a part.app.jsstill callsetCapabilityValue()after the listener; that's now a redundant but harmless second write, left as-is to keep this change focused.Testing
npm test(eslint + Jest): 119 passed. Not yet tested on a real device.🤖 Generated with Claude Code