Fall back to gray when matching state has no color + document JSON schema#30
Open
robmarcer wants to merge 1 commit into
Open
Fall back to gray when matching state has no color + document JSON schema#30robmarcer wants to merge 1 commit into
robmarcer wants to merge 1 commit into
Conversation
…hema When a `state` matches the incoming `msg.payload` but its `color` field is missing, the computed `color` is `undefined`. That ends up in the inline style as the literal string `--ui-led-color: undefined;`, which is an invalid CSS value, so `background-color: var(--ui-led-color)` resolves to nothing and the bulb becomes invisible — no warning, no fallback. This is easy to hit when: - a flow is built by hand or generated by tooling (LLMs, scripts) and the author uses the wrong field name (e.g. `colorForValue`) or forgets `color` on a state entry, - the editor's defaults are kept (the schema's default `states` array has entries without `color`), and a deploy happens before the engineer opens the Values dialog, - a flow is imported from another instance where the `color` was stripped (some Dashboard editors normalise default-equal fields out). This change preserves the existing "no matching state -> gray" fallback and extends it to "matching state with no color -> gray". The LED is never silently invisible again; at worst it renders gray. Also restructures the match check into a single `matched` predicate to keep the two output points (color resolution) in one place. README: - Add a JSON-config section documenting the underlying `states` field name (the editor labels it "Values" but the node property is `states`, and several users have been caught by this when hand-editing flow JSON). - Reword the "If a value is provided that it doesn't recognise" bullet to also cover the missing-color fallback. No behaviour change for correctly-configured LEDs.
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.
Problem
When
msg.payloadmatches a configured state but that state has nocolorset, the computedcolorisundefined. That value is interpolated into the inline style as the literal string--ui-led-color: undefined;, which is an invalid CSS value, sobackground-color: var(--ui-led-color)resolves to nothing and the bulb becomes invisible — no warning in the console, no fallback color, just a label with empty space where the LED should be.This is easy to hit in a few real scenarios:
colorForValue,colours, etc.) instead of the correctstates. The widget then has zero rules, theforloop doesn't iterate, and the fallback'gray'kicks in — that case already works. BUT if they get the field name right but forgetcoloron a state entry, the result is invisible.statesentries ({value: false, valueType: 'bool'}and{value: true, valueType: 'bool'}) with nocolorfield. An engineer who deploys without opening the Values dialog gets invisible LEDs.colorwas stripped (some flow editors / migration tools normalise default-equal fields out of stored JSON).In all three cases the LED is silently invisible. We hit it on a customer engagement; the only diagnosis path was reading the Vue component source, which isn't ideal for users.
Fix
ui/components/UILed.vue: when a state matches butstate.coloris falsy, return'gray'instead ofundefined. Same fallback the function already uses for "no match found" and "no value received yet" — extends it to cover the "matched state, no color set" case so the bulb is never silently invisible.Also restructures the match check into a single
matchedboolean to keep the result-resolution in one place.No behaviour change for correctly-configured LEDs.
Docs
README.md: adds a "JSON config" section documenting the underlyingstatesfield name. The editor labels this section "Values"; the underlying node property isstates. This trips up users hand-editing flow JSON or generating it from scripts (including this engagement — several wrong guesses before reading the source).Also reworded the existing "If a value is provided that it doesn't recognise" bullet to mention the missing-color fallback explicitly, matching the new behaviour.
Testing
ui-ledwhose state entries lacked colors. Before: invisible. After: gray bulb (visibly there, just neutral).grayfallback fires in three independent code paths now: no value yet (existing), no state matches (existing), matching state has no color (new).Notes
colorvalues for the defaultstates(would change UX for existing users who currently see invisible LEDs but then add colors via the editor). Open to doing that as a follow-up if you think it's a clearer fix.