Propose scoped-beer-override: bind the manual override to the keg it corrects
The beer_name override reinstated in 0.3.1 has no link to the keg it corrects, so it outlives it. Every card configured before 0.3.0 carries the key (the editor of that era always wrote it, getStubConfig seeded it), which 0.3.1 promoted into a silent permanent override — reported as a card showing Leffe Blonde while the machine reported Leffe Ruby. The same failure recurs on any keg swap even without legacy config. Proposes beer_overrides keyed by product ID, so a correction expires structurally rather than needing a write the card cannot make, plus a visible marker when an override is applied. beer_name joins beer_entity as an ignored key. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
schema: spec-driven
|
||||
created: 2026-09-16
|
||||
@@ -0,0 +1,105 @@
|
||||
## Context
|
||||
|
||||
0.3.1 resolves the displayed beer through four rungs: the `beer_name` config override, a catalogue entry matched on the `keg_product_id` sensor, a beer resolved from the `keg_name` sensor, then the no-keg state. Rung 1 is unconditional and permanent, and that is the defect. The override records "the beer currently in my machine is detected wrongly" but stores it as a global config value with no link to that keg, so it keeps asserting itself after the keg is gone.
|
||||
|
||||
Two populations hit this. Cards configured before 0.3.0 all carry a `beer_name`, because the ≤0.2.0 editor's "Default Beer" select had no auto option and `getStubConfig` seeded `beer_name: "Stella Artois"`. 0.3.0 deleted the key and ignored it; 0.3.1 revived the same key with inverted semantics, reactivating those dormant values as detection overrides. The second population is anyone who sets an override correctly today — their card goes wrong at the next keg change.
|
||||
|
||||
The binding constraint on any fix: a Lovelace card cannot rewrite its own config. `config-changed` is only honoured while the editor dialog is open, so the card cannot expire or clean up a stale override even when it can prove one is stale. Staleness has to be structurally impossible, or visible enough that the user clears it.
|
||||
|
||||
## Goals / Non-Goals
|
||||
|
||||
**Goals:**
|
||||
|
||||
- A stale override becomes inert without anyone editing config.
|
||||
- Auto-detection is what an upgraded card does, regardless of what earlier versions wrote into its YAML.
|
||||
- The escape hatch survives: a keg the catalogue maps to the wrong beer, or does not know at all, can still be corrected without hand-editing YAML.
|
||||
- The card never silently displays a beer that contradicts what the machine reports.
|
||||
- The 0.3.1 no-keg honesty property is preserved: no configured value can make the card name a beer that is not in the machine.
|
||||
|
||||
**Non-Goals:**
|
||||
|
||||
- Correcting the catalogue itself. A mis-mapped product ID should still be reported upstream and fixed in `beer-catalog.ts`; the override is a local stopgap, not a substitute.
|
||||
- Any change to the integration. Its sensors and `keg_catalog.json` remain a fixed upstream contract.
|
||||
- Reinstating the in-card beer picker dialog. Corrections belong in the config editor, as decided in the previous change.
|
||||
- Migrating legacy `beer_name` values to the new key. See decision 2.
|
||||
- Per-keg glass size, freshness or layout scoping. Only beer identity is keg-scoped.
|
||||
|
||||
## Decisions
|
||||
|
||||
### 1. The override is keyed by product ID
|
||||
|
||||
`beer_overrides` is a map from the product ID string the integration reports to a beer name resolved through the existing `resolveBeer` path (catalogue name, slug, or `custom_beers` entry):
|
||||
|
||||
```yaml
|
||||
beer_overrides:
|
||||
"1095": "Leffe Ruby"
|
||||
```
|
||||
|
||||
An entry applies only while `keg_product_id` reports that ID. Swap the keg and the key stops matching, so the correction expires on its own with no writes — which is what makes it viable under the can't-persist constraint. A stale entry costs nothing but a line of YAML, and it becomes useful again if that keg is ever tapped a second time.
|
||||
|
||||
The previous change considered and rejected this shape as "a new config surface for a rare case, and it cannot help when the ID is unresolved." The first half is now outweighed: the global key's unbounded lifetime is a correctness bug, not a convenience question. The second half was too quick — an ID that the *catalogue* does not recognise is still a perfectly good map key, and that is precisely the common case for a new beer. The genuine gap is narrower: a machine whose `keg_product_id` is missing or unavailable cannot be corrected this way. Rung 3 (the reported name) already covers that case, and the no-keg state covers the rest.
|
||||
|
||||
Rejected alternatives:
|
||||
|
||||
- **Keep the global key, gate it with a `config_version` stamp.** Distinguishes legacy values from deliberate ones, which solves the migration but not the recurrence: a deliberate override still goes stale at the next keg change. It also adds a config field whose only purpose is to compensate for a key having had two meanings.
|
||||
- **Rename the global key** (e.g. `beer_override`). Same objection — it fixes the name collision and nothing about lifetime.
|
||||
- **Demote `beer_name` to a fallback that applies only when nothing is detected.** Cheap, and stale values become harmless. Rejected because it discards the escape hatch entirely — a keg detected as the wrong beer cannot be corrected at all — and it regresses the no-keg state back to naming a beer that is not in the machine.
|
||||
|
||||
### 2. Legacy `beer_name` is ignored, not migrated
|
||||
|
||||
Reading the old value into the new map is impossible to do correctly: `beer_name` carries no record of which keg it was for, so there is no ID to key it under. Guessing the currently reported ID would silently manufacture an override the user never asked for, which is the present bug wearing a new key name.
|
||||
|
||||
So `beer_name` joins `beer_entity` as a key the card ignores without throwing. There is a precedent for exactly this in `card-config`: `beer_entity` was removed in the same commit that removed `beer_name`, and it got the ignore treatment while `beer_name` was resurrected instead. This restores the symmetry.
|
||||
|
||||
The cost falls on anyone who set an override deliberately during 0.3.1's lifetime: their card reverts to auto-detection. That is a short window, the reverted behaviour is correct for most of them (the catalogue now covers all 114 upstream IDs), and re-applying the correction is one editor action. A README upgrade note covers it.
|
||||
|
||||
### 3. An override that contradicts detection is shown, not hidden
|
||||
|
||||
When an override is active, the card SHALL indicate it, and the indication SHALL carry the name detection resolved so the two are comparable. This is what turns a future stale override from an unexplainable wrong card into something a user can diagnose without reading YAML.
|
||||
|
||||
Keep it small: a compact marker adjacent to the beer name, not a dialog. The marker appears whenever an override is applied — including when it agrees with detection, since an agreeing override is still a value the user should know is there. Rejected alternative: show the marker only on disagreement. Slightly quieter, but it hides the override in exactly the case where it is redundant and should be deleted.
|
||||
|
||||
The existing `freshness-indicator` element is the styling precedent for a compact status pill on the card.
|
||||
|
||||
### 4. Overrides do not apply in the no-keg state
|
||||
|
||||
With no keg reported there is no product ID, so no map entry can match and the card falls through to "no keg detected". This is a property of decision 1 rather than a rule to implement, and it is worth stating as a requirement so a future refactor cannot quietly reintroduce a configured value that names an absent beer.
|
||||
|
||||
### 5. Overrides live in config, not `localStorage`
|
||||
|
||||
Glass size is stored per-browser in `localStorage` because it is a personal preference. A keg correction is a fact about the machine and the catalogue, so it belongs in config: shared across every browser and dashboard, visible in YAML, reviewable, and portable. Storing it per-browser would make two people looking at the same dashboard see different beers.
|
||||
|
||||
### 6. The editor writes the override from the live product ID
|
||||
|
||||
`_discoverDevices` already builds a `translation_key → entityId` map per device, so `entities.get("keg_product_id")` gives the editor the sensor directly and `hass.states[...]` gives the live value. The 120-entry dropdown is replaced by an action scoped to what is currently tapped — "this keg is detected wrongly" — plus a beer selector, writing a single `beer_overrides` entry keyed by that ID.
|
||||
|
||||
The editor also lists existing entries with the beer each names and a remove control, which is how a stale entry from a previous keg becomes visible and clearable. When no product ID is currently reported, the action is disabled with a short explanation rather than hidden, so the feature is discoverable before it is needed.
|
||||
|
||||
## Risks / Trade-offs
|
||||
|
||||
- **A machine that reports no usable `keg_product_id` cannot be corrected.** → Rung 3 already renders the integration-reported name, and the honest no-keg state covers the rest. Accepted as a documented limitation rather than adding a second, name-keyed override surface for a case that may not exist in practice.
|
||||
|
||||
- **`beer_overrides` is a nested map, which is harder to hand-write than a flat string and easy to get wrong** (unquoted numeric keys, wrong ID). → The editor is the supported path and writes the ID itself. An entry whose key never matches is inert, so the failure mode of a typo is "override does nothing", not a wrong beer.
|
||||
|
||||
- **Users who set `beer_name` deliberately in 0.3.1 lose their setting on upgrade.** → Ignored rather than erroring, called out in the README upgrade note, and re-applied with one editor action. Weighed against leaving every pre-0.3.0 card silently misidentifying its keg.
|
||||
|
||||
- **Stale entries accumulate in config over time.** → They are inert and small. The editor's list makes them visible, and the alternative — the card pruning them — is precluded by the can't-persist constraint.
|
||||
|
||||
- **The override marker adds visual noise to a card whose layouts are already dense**, particularly `compact`. → It is a small pill following the `freshness-indicator` precedent, and it only renders when an override is actually applied, which is rare by design.
|
||||
|
||||
- **The keg-scoped editor action reads live sensor state, coupling the editor to entity resolution that currently lives in the card.** → The editor already resolves the same entities by `translation_key` for device discovery; this reads one more key from a map it has already built. If that duplication grows, extracting a shared resolver is a separate refactor.
|
||||
|
||||
## Migration Plan
|
||||
|
||||
1. Types and detection: add `beer_overrides`, remove `beer_name`, ignore it when present, and rewrite the precedence in `_updateDetectedBeer`. At this point every existing card reverts to auto-detection — the behaviour fix lands here on its own.
|
||||
2. The override marker in the label and the layouts that show beer identity.
|
||||
3. The editor: keg-scoped correction action plus the existing-overrides list, replacing the dropdown.
|
||||
4. Spec deltas, README (`beer_overrides`, ignored `beer_name`, upgrade note), version bump to 0.4.0 and rebuilt bundle.
|
||||
|
||||
Rollback is a bundle revert. Since step 1 only ignores a key, a card configured under 0.4.0 stays loadable on 0.3.1 — `beer_overrides` is unknown there and ignored, and the card falls back to detection, which is the same behaviour minus the correction.
|
||||
|
||||
## Open Questions
|
||||
|
||||
- Exact wording and placement of the override marker per layout, especially `compact` and `vessel`, where horizontal space is tight.
|
||||
- Whether the editor's beer selector for a correction should offer the full catalogue or bias toward the detected beer's brewery, which is where sibling mis-mappings cluster.
|
||||
- Whether a mis-mapping corrected locally should prompt the user to report it upstream, given the fix belongs in the catalogue rather than in every affected user's config.
|
||||
@@ -0,0 +1,35 @@
|
||||
## Why
|
||||
|
||||
The `beer_name` override reinstated in 0.3.1 has no connection to the keg it corrects, so it outlives that keg and silently misidentifies every later one. This is not hypothetical: a user upgrading from 0.2.0 reported the card showing "Leffe Blonde" while the machine's `keg_name` sensor read "Leffe Ruby". The cause was a dormant `beer_name: Leffe Blonde` in their card YAML, written by the ≤0.2.0 editor — whose "Default Beer" select had no auto option and always wrote the key, with `getStubConfig` seeding `beer_name: "Stella Artois"` on card creation. Every card configured before 0.3.0 therefore carries a value that 0.3.1 promoted into a permanent, invisible detection override.
|
||||
|
||||
Dropping the legacy value alone would not fix this. A global override is stale by construction: a user who legitimately sets one today to correct a mis-detected keg gets a wrong card the moment they swap kegs, with nothing on screen explaining why. The card cannot self-heal, because `config-changed` is only honoured while the editor dialog is open — a card cannot rewrite its own Lovelace config. Staleness must therefore be made structurally impossible rather than cleaned up after the fact.
|
||||
|
||||
## What Changes
|
||||
|
||||
- Scope the manual override to the product ID it corrects, via a new `beer_overrides` map keyed by product ID (e.g. `{ "1095": "Leffe Ruby" }`). An override applies only while the machine reports that ID, so swapping kegs makes it inert with no writes required.
|
||||
- **BREAKING (repair)** — `beer_name` is removed as a config key and ignored when present, joining `beer_entity` in the ignored-keys list. Auto-detection becomes the default for every existing card, which is the behaviour users upgrading from ≤0.2.0 expect.
|
||||
- Surface disagreement instead of resolving it silently: when an active override names a different beer than detection resolved, the card SHALL indicate that an override is in effect.
|
||||
- An override SHALL NOT apply in the no-keg state. With no keg reported there is no ID to match, so the honest "no keg detected" state introduced in 0.3.1 is preserved rather than being papered over by a stale name.
|
||||
- Replace the editor's 120-entry "Beer override" dropdown with an action scoped to the currently detected keg — "this keg is detected wrongly" — which captures the reported product ID and writes the map entry. Unrecognised IDs are still valid keys, so this covers kegs the catalogue does not know.
|
||||
- `custom_beers` stays reachable, now as an override target resolved through the same name/slug/custom path.
|
||||
|
||||
## Capabilities
|
||||
|
||||
### New Capabilities
|
||||
|
||||
None. This change modifies the requirements of existing capabilities.
|
||||
|
||||
### Modified Capabilities
|
||||
|
||||
- `keg-auto-detection`: Detection precedence changes. The unconditional `beer_name` override at rung 1 is replaced by a product-ID-scoped override that applies only when the reported ID matches an entry in `beer_overrides`. The "Override wins over successful detection" scenario is restated in scoped terms, override behaviour in the no-keg state is specified, and a requirement is added to surface an override that contradicts detection.
|
||||
- `card-config`: `beer_name` moves from a supported key to an ignored legacy key. `beer_overrides` is added as a product-ID-keyed map. The unknown-override-name scenario is restated against the new key, `custom_beers` is redocumented as an override target, and the editor's beer field is respecified as a keg-scoped correction action.
|
||||
|
||||
## Impact
|
||||
|
||||
- `src/types.ts` — remove `beer_name`, add `beer_overrides?: Record<string, string>`.
|
||||
- `src/perfectdraft-card.ts` — `_updateDetectedBeer` precedence, override-conflict state for the label, no-keg interaction.
|
||||
- `src/editor.ts` — replace the beer dropdown with the keg-scoped correction action; needs the live product-ID state, which the editor does not read today.
|
||||
- `src/beer-catalog.ts` — no change expected; `resolveBeer` already handles name, slug and custom entries.
|
||||
- `README.md` — document `beer_overrides`, state that `beer_name` is ignored, and add an upgrade note for users coming from ≤0.2.0 whose cards carry the key.
|
||||
- `package.json` / `dist/perfectdraft-card.js` — minor version bump to 0.4.0 (config-breaking) and rebuilt bundle. The bundle's console banner is the only way a user can confirm which build is running, and 0.3.0 shipped without a bump, so the bump is load-bearing for supportability.
|
||||
- No integration dependency change: still PerfectDraft integration 0.4.0+ for the keg sensors.
|
||||
@@ -0,0 +1,98 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Keg-scoped beer overrides configuration
|
||||
The card SHALL accept an optional `beer_overrides` config map, keyed by the product ID the integration reports, so a correction is bound to the keg it corrects.
|
||||
|
||||
#### Scenario: Map shape
|
||||
- **WHEN** a `beer_overrides` value is provided in config
|
||||
- **THEN** each key SHALL be the product ID string as reported by the `keg_product_id` sensor
|
||||
- **THEN** each value SHALL be a beer name resolvable against the catalog, a catalog slug, or the `name` of a `custom_beers` entry
|
||||
|
||||
#### Scenario: Overrides absent
|
||||
- **WHEN** the card config has no `beer_overrides`
|
||||
- **THEN** the card SHALL rely entirely on auto-detection
|
||||
- **THEN** `getStubConfig()` SHALL NOT populate `beer_overrides`, so newly created cards start with detection only
|
||||
|
||||
#### Scenario: Entry recorded against the currently tapped keg
|
||||
- **WHEN** the user corrects the detected beer from the visual editor
|
||||
- **THEN** the editor SHALL write a single `beer_overrides` entry keyed by the product ID currently reported for the configured device
|
||||
- **THEN** the editor SHALL NOT write an entry that is not keyed by a reported product ID
|
||||
|
||||
#### Scenario: No product ID currently reported
|
||||
- **WHEN** the visual editor is displayed AND the configured device reports no usable `keg_product_id` state
|
||||
- **THEN** the correction control SHALL be shown in a disabled state with an explanation that a keg must be detected first
|
||||
- **THEN** the editor SHALL NOT be prevented from displaying or removing existing entries
|
||||
|
||||
#### Scenario: Existing entries are reviewable and removable
|
||||
- **WHEN** the visual editor is displayed AND `beer_overrides` contains entries
|
||||
- **THEN** the editor SHALL list each entry with the product ID and the beer it names
|
||||
- **THEN** the editor SHALL provide a control to remove an individual entry
|
||||
- **THEN** removing the last entry SHALL remove `beer_overrides` from the config
|
||||
|
||||
## MODIFIED Requirements
|
||||
|
||||
### Requirement: Configuration validation
|
||||
The card SHALL validate its configuration and display clear errors for invalid config.
|
||||
|
||||
#### Scenario: Missing device configuration
|
||||
- **WHEN** the card config has no `device_id`
|
||||
- **THEN** the card SHALL throw an error during `setConfig()` that triggers HA's built-in error card display
|
||||
- **THEN** the error message SHALL instruct the user to configure the card via the visual editor
|
||||
|
||||
#### Scenario: Invalid glass_size value
|
||||
- **WHEN** the card config specifies a `glass_size` that is not one of the supported values (250, 330, 500, 568, 473)
|
||||
- **THEN** the card SHALL fall back to the default of 330 mL
|
||||
|
||||
#### Scenario: Unknown beer name in an override entry
|
||||
- **WHEN** a `beer_overrides` entry whose key matches the reported product ID names a beer that matches nothing in the catalog (built-in or custom)
|
||||
- **THEN** the card SHALL treat it as a custom beer with that name and use a generic color palette
|
||||
- **THEN** the card SHALL NOT fall back to auto-detection, since a matching override signals the user's intent
|
||||
|
||||
#### Scenario: Override entry with a malformed key
|
||||
- **WHEN** a `beer_overrides` key does not correspond to any product ID the machine reports
|
||||
- **THEN** the card SHALL ignore that entry without throwing
|
||||
- **THEN** the card SHALL resolve the beer by detection
|
||||
|
||||
#### Scenario: Removed configuration keys ignored
|
||||
- **WHEN** the card config contains `beer_entity` or `beer_name`, neither of which is supported
|
||||
- **THEN** the card SHALL ignore them without throwing
|
||||
- **THEN** the card SHALL resolve the beer by detection as though the key were absent
|
||||
|
||||
### Requirement: Visual card editor
|
||||
The card SHALL provide a graphical configuration editor as the primary means of configuration.
|
||||
|
||||
#### Scenario: Editor registration
|
||||
- **WHEN** `getConfigElement()` is called on the card class
|
||||
- **THEN** it SHALL return a custom element that renders a configuration form
|
||||
- **THEN** `getStubConfig()` SHALL return a minimal valid configuration for new card creation (auto-selecting the sole device if only one exists)
|
||||
|
||||
#### Scenario: Editor fields
|
||||
- **WHEN** the visual editor is displayed
|
||||
- **THEN** it SHALL provide: a device picker (dropdown of discovered PerfectDraft devices), glass size (dropdown of five options), layout selection, and a correction control scoped to the currently detected keg
|
||||
- **THEN** all fields SHALL be UI controls — no freeform text input for entity IDs or product IDs
|
||||
- **THEN** the editor SHALL NOT present beer selection as a required or default setting
|
||||
- **THEN** the editor SHALL NOT offer a beer setting that applies regardless of which keg is tapped
|
||||
|
||||
#### Scenario: Editor fires config-changed events
|
||||
- **WHEN** the user changes any editor field
|
||||
- **THEN** the editor SHALL fire a `config-changed` custom event with the updated config
|
||||
- **THEN** the card preview SHALL update to reflect the change
|
||||
|
||||
### Requirement: Custom beers configuration
|
||||
The card SHALL support extending the beer catalog via the `custom_beers` config array, reachable through a `beer_overrides` entry.
|
||||
|
||||
#### Scenario: Custom beer entry structure
|
||||
- **WHEN** a `custom_beers` array entry is provided in config
|
||||
- **THEN** it SHALL require at minimum a `name` field (string)
|
||||
- **THEN** it SHALL accept optional fields: `color_primary` (CSS color), `color_secondary` (CSS color), `color_text` (CSS color), `image_url` (URL string), `brewery` (string), `style` (string), `abv` (number)
|
||||
|
||||
#### Scenario: Custom beer selected by a matching override
|
||||
- **WHEN** a `beer_overrides` entry matching the reported product ID names the same string as the `name` of a `custom_beers` entry
|
||||
- **THEN** the card SHALL display that custom beer using its configured colors and image
|
||||
|
||||
## REMOVED Requirements
|
||||
|
||||
### Requirement: Optional manual beer override
|
||||
**Reason**: `beer_name` applied unconditionally and permanently, with no link to the keg it corrected, so it misidentified every subsequent keg. Every card configured before 0.3.0 carries the key, because the editor of that era always wrote it and `getStubConfig()` seeded it, and 0.3.1 promoted those dormant values into silent detection overrides.
|
||||
|
||||
**Migration**: `beer_name` is ignored when present; no automatic migration is possible because the value records no product ID and guessing one would manufacture an override the user never set. Cards revert to auto-detection, which for most is the correct result now that the catalog covers all upstream product IDs. To re-apply a correction, use the keg-scoped correction control in the editor while that keg is tapped, which records it under `beer_overrides`.
|
||||
@@ -0,0 +1,65 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Manual override scoped to the reported keg
|
||||
A manual override SHALL apply only while the machine reports the product ID that override was recorded against, so that a correction cannot outlive the keg it corrects.
|
||||
|
||||
#### Scenario: Override applies to the keg it was recorded for
|
||||
- **WHEN** `beer_overrides` contains an entry whose key equals the state of the `keg_product_id` sensor
|
||||
- **THEN** the card SHALL display the beer resolved from that entry's value, resolved by catalog name, slug, or matching `custom_beers` entry
|
||||
- **THEN** the card SHALL use that beer for the name, brand colors, style, ABV, and artwork
|
||||
|
||||
#### Scenario: Override does not apply to a different keg
|
||||
- **WHEN** `beer_overrides` contains entries AND none of their keys equals the reported `keg_product_id` state
|
||||
- **THEN** the card SHALL ignore every entry and resolve the beer by detection
|
||||
- **THEN** the card SHALL NOT display any beer named by a non-matching entry
|
||||
|
||||
#### Scenario: Override for an unrecognised product ID
|
||||
- **WHEN** the reported `keg_product_id` matches no catalog entry's `kegId` AND `beer_overrides` contains an entry for that ID
|
||||
- **THEN** the card SHALL display the beer named by that entry
|
||||
- **THEN** the card SHALL NOT fall back to the integration-reported keg name
|
||||
|
||||
#### Scenario: No override applies when no keg is reported
|
||||
- **WHEN** the `keg_product_id` sensor reports no usable state AND `beer_overrides` contains entries
|
||||
- **THEN** the card SHALL enter the no-keg-detected state
|
||||
- **THEN** the card SHALL NOT display any beer named by `beer_overrides`
|
||||
|
||||
#### Scenario: Override entry naming an unknown beer
|
||||
- **WHEN** a matching `beer_overrides` entry names a beer present in neither the catalog nor `custom_beers`
|
||||
- **THEN** the card SHALL display that name against the generic color palette
|
||||
- **THEN** the card SHALL NOT fall back to detection, since a matching override signals the user's intent for this keg
|
||||
|
||||
### Requirement: Active override is visible
|
||||
When the card displays a beer because of an override rather than detection, it SHALL make that visible, so a user can tell an override from a detection result without reading config.
|
||||
|
||||
#### Scenario: Override applied
|
||||
- **WHEN** the card displays a beer resolved from a matching `beer_overrides` entry
|
||||
- **THEN** the card SHALL render an indication that an override is in effect
|
||||
|
||||
#### Scenario: Override contradicts detection
|
||||
- **WHEN** an override is applied AND detection would have resolved a different beer for the same keg
|
||||
- **THEN** the indication SHALL identify the beer that detection resolved
|
||||
- **THEN** the card SHALL NOT silently present the override as a detection result
|
||||
|
||||
#### Scenario: No override applied
|
||||
- **WHEN** the card displays a beer resolved by detection with no matching override
|
||||
- **THEN** the card SHALL NOT render an override indication
|
||||
|
||||
## MODIFIED Requirements
|
||||
|
||||
### Requirement: Detection precedence
|
||||
The card SHALL apply a single, defined precedence order when determining which beer to display.
|
||||
|
||||
#### Scenario: Precedence order
|
||||
- **WHEN** the card determines the beer to display
|
||||
- **THEN** it SHALL apply the first applicable source in this order: (1) a `beer_overrides` entry whose key matches the reported product ID, (2) a catalog entry matched by reported product ID, (3) a beer resolved from the reported keg name, (4) the no-keg-detected state
|
||||
- **THEN** no later source SHALL override an earlier one
|
||||
|
||||
#### Scenario: Matching override wins over successful detection
|
||||
- **WHEN** a `beer_overrides` entry matches the reported product ID AND that same product ID also resolves to a different catalog entry
|
||||
- **THEN** the card SHALL display the beer named by the override entry
|
||||
- **THEN** the card SHALL indicate that an override is in effect rather than substituting silently
|
||||
|
||||
#### Scenario: No configured value can precede detection unconditionally
|
||||
- **WHEN** the card determines the beer to display
|
||||
- **THEN** no config value SHALL take precedence over detection except by matching the currently reported product ID
|
||||
- **THEN** a config value that names a beer without reference to a product ID SHALL NOT affect the displayed beer
|
||||
@@ -0,0 +1,43 @@
|
||||
## 1. Config surface and detection precedence
|
||||
|
||||
- [ ] 1.1 In `src/types.ts`, remove `beer_name` from `PerfectDraftCardConfig` and add `beer_overrides?: Record<string, string>`
|
||||
- [ ] 1.2 In `src/perfectdraft-card.ts`, rewrite the first rung of `_updateDetectedBeer` to look up `_config.beer_overrides` by the reported `keg_product_id` state instead of reading `_config.beer_name`
|
||||
- [ ] 1.3 Resolve a matching override's value through the existing `resolveBeer(value, this._config.custom_beers)` path so catalog names, slugs and `custom_beers` entries all work
|
||||
- [ ] 1.4 Confirm no override is consulted when the product ID state is absent, `unknown` or `unavailable`, so the no-keg state is unreachable from config
|
||||
- [ ] 1.5 Track whether the displayed beer came from an override and what detection would have resolved, so the marker in group 2 has both names available
|
||||
- [ ] 1.6 Verify `beer_name` and `beer_entity` in a config load without throwing and leave the card on detection
|
||||
|
||||
## 2. Override visibility on the card
|
||||
|
||||
- [ ] 2.1 Add an override marker element and styles, following the `freshness-indicator` pill precedent
|
||||
- [ ] 2.2 Include the detection-resolved name in the marker when it differs from the override
|
||||
- [ ] 2.3 Render the marker in the layouts that show beer identity: `landscape`, `portrait`, `hero`, `vessel`
|
||||
- [ ] 2.4 Decide and implement the `compact` layout treatment, where horizontal space is tight (open question in design.md)
|
||||
- [ ] 2.5 Confirm the marker is absent whenever no override is applied
|
||||
|
||||
## 3. Editor
|
||||
|
||||
- [ ] 3.1 Remove the `beer_name` dropdown and its `getAllBeers()` import if it becomes unused
|
||||
- [ ] 3.2 Read the live `keg_product_id` state for the selected device from the `translation_key` map `_discoverDevices` already builds
|
||||
- [ ] 3.3 Add the keg-scoped correction control: a beer selector that writes one `beer_overrides` entry keyed by the currently reported product ID
|
||||
- [ ] 3.4 Disable the correction control with an explanation when no product ID is currently reported, without hiding it
|
||||
- [ ] 3.5 List existing `beer_overrides` entries with product ID and beer name, each with a remove control
|
||||
- [ ] 3.6 Remove the `beer_overrides` key entirely when its last entry is removed
|
||||
- [ ] 3.7 Confirm each editor mutation fires `config-changed` and the preview updates
|
||||
|
||||
## 4. Documentation and release
|
||||
|
||||
- [ ] 4.1 Document `beer_overrides` in `README.md`, replacing the `beer_name` override section, including the YAML example
|
||||
- [ ] 4.2 Add an upgrade note stating that `beer_name` is ignored, why, and how to re-apply a correction
|
||||
- [ ] 4.3 State in the README how to confirm which bundle version is running, since the console banner is the only signal
|
||||
- [ ] 4.4 Bump `package.json`, `CARD_VERSION` and `EDITOR_VERSION` to 0.4.0 — all three, so the banner cannot disagree with the release again
|
||||
- [ ] 4.5 Rebuild `dist/perfectdraft-card.js` with `npm run build`
|
||||
|
||||
## 5. Verification
|
||||
|
||||
- [ ] 5.1 Run `npm run lint` and `npm run check:catalog` clean
|
||||
- [ ] 5.2 Reproduce the original report: a config carrying `beer_name: "Leffe Blonde"` with a keg reporting product ID `1095` SHALL display Leffe Ruby
|
||||
- [ ] 5.3 Verify the recurrence case: an override recorded for one product ID stops applying when the reported ID changes, with no config edit
|
||||
- [ ] 5.4 Verify an override on a product ID absent from the catalog displays the named beer rather than the integration-reported name
|
||||
- [ ] 5.5 Verify the no-keg state still renders "No keg detected" with `beer_overrides` populated
|
||||
- [ ] 5.6 Verify a 0.4.0 config loads on the 0.3.1 bundle without throwing, per the rollback path in design.md
|
||||
Reference in New Issue
Block a user