diff --git a/dist/perfectdraft-card.js b/dist/perfectdraft-card.js
index 4d5e2c8..853bd8e 100644
--- a/dist/perfectdraft-card.js
+++ b/dist/perfectdraft-card.js
@@ -145,7 +145,7 @@ function e(e,t,r,s){var i,a=arguments.length,o=a<3?t:null===s?s=Object.getOwnPro
color: #f5a623;
margin-bottom: 16px;
}
- `}};e([ge({attribute:!1})],Ie.prototype,"hass",void 0),e([pe()],Ie.prototype,"_config",void 0),e([pe()],Ie.prototype,"_devices",void 0),Ie=e([ce("perfectdraft-card-editor")],Ie);function Se(){const e=document.querySelectorAll("script[src]");for(const t of e){const e=t.src;if(e.includes("perfectdraft-card"))return e.substring(0,e.lastIndexOf("/")+1)}return"/hacsfiles/perfectdraft-card/"}function De(e,t){return`perfectdraft-card:${e}:${t}`}function Le(e){if(!e||"unavailable"===e||"unknown"===e)return null;const t=parseFloat(e);return isNaN(t)?null:t}let ze=class extends ne{constructor(){super(...arguments),this._glassSize=ye,this._layout=Fe,this._showGlassDialog=!1,this._failedImages=new Set,this._entityIds={},this._entitiesResolved=!1,this._openGlassDialog=()=>{this._showGlassDialog=!0}}setConfig(e){if(!e.device_id)throw new Error("PerfectDraft Card: No device configured. Please use the visual editor to select a PerfectDraft device.");var t;this._config={...e},this._layout=(t=e.layout,be.some(e=>e.value===t)?t:Fe);const r=e.matrix_columns;this._matrixColumns="number"==typeof r&&Number.isFinite(r)&&r>0?Math.floor(r):void 0,this._maxMatrixWidth="string"==typeof e.max_matrix_width&&e.max_matrix_width.trim()?e.max_matrix_width.trim():void 0;const s=localStorage.getItem(De(e.device_id,"glass"));this._glassSize=s?parseInt(s,10):e.glass_size??ye}getCardSize(){switch(this._layout){case"compact":return 1;case"vessel":return 4;case"portrait":return 6;default:return 5}}getGridOptions(){switch(this._layout){case"compact":return{rows:1,columns:12,min_columns:2,min_rows:1};case"portrait":return{rows:5,columns:6,min_columns:1,min_rows:3};case"vessel":return{rows:4,columns:6,min_columns:1,min_rows:2};case"hero":return{rows:5,columns:8,min_columns:1,min_rows:2};default:return{columns:4,rows:3,min_columns:1,min_rows:2}}}static getStubConfig(e){const t=e.entities||{},r=new Set;for(const e of Object.values(t))e.platform===me&&e.device_id&&r.add(e.device_id);return{device_id:1===r.size?[...r][0]:"",glass_size:ye,layout:Fe}}static getConfigElement(){return document.createElement("perfectdraft-card-editor")}connectedCallback(){super.connectedCallback(),this._resolveEntities()}willUpdate(e){(e.has("hass")||e.has("_config"))&&(this._resolveEntities(),this._updateDetectedBeer())}_resolveEntities(){if(!this.hass||!this._config?.device_id)return;if(this._entitiesResolved)return;const e=this.hass.entities||{};for(const[t,r]of Object.entries(e)){if(r.platform!==me||r.device_id!==this._config.device_id)continue;const e=r.translation_key;"temperature"===e?this._entityIds.temperature=t:"keg_remaining"===e?this._entityIds.kegRemaining=t:"keg_freshness"===e?this._entityIds.kegFreshness=t:"keg_product_id"===e?this._entityIds.kegProduct=t:"keg_name"===e&&(this._entityIds.kegName=t)}this._entitiesResolved=Boolean(this._entityIds.temperature&&this._entityIds.kegRemaining&&this._entityIds.kegFreshness&&this._entityIds.kegProduct&&this._entityIds.kegName)}get _kegSensorsMissing(){return Boolean(this._entityIds.temperature)&&!this._entityIds.kegProduct&&!this._entityIds.kegName}get _beerDetected(){return void 0!==this._beer}_updateDetectedBeer(){if(!this._config)return;const e=this._config.beer_name?.trim();if(e)return void this._assignBeer(Pe(e,this._config.custom_beers));const t=this._getState(this._entityIds.kegProduct),r=this._getState(this._entityIds.kegName),s=r&&"unavailable"!==r&&"unknown"!==r?r:void 0;let i;t&&/^\d+$/.test(t)&&(i=function(e){if(e)return Ce.get(e)}(t)),!i&&s&&(i=Pe(s,this._config.custom_beers)),this._assignBeer(i)}_assignBeer(e){e?.slug===this._beer?.slug&&e?.name===this._beer?.name||(this._beer=e)}_getState(e){if(e&&this.hass)return this.hass.states[e]?.state}_selectGlass(e){this._glassSize=e,this._showGlassDialog=!1,this._config?.device_id&&localStorage.setItem(De(this._config.device_id,"glass"),String(e))}_imgError(e){this._failedImages=new Set(this._failedImages).add(e)}render(){if(!this._config||!this.hass)return N`Loading...
`;if(!this._config.device_id)return N`No device configured. Please edit this card to select a PerfectDraft device.
`;if(this._kegSensorsMissing)return N`This card needs the keg sensors added in PerfectDraft integration 0.4.0. Please update the integration, then reload this page.
`;const e=Le(this._getState(this._entityIds.temperature)),t=Le(this._getState(this._entityIds.kegRemaining)),r=Le(this._getState(this._entityIds.kegFreshness)),s=null===(i=r)?"normal":i<=xe?"expired":i<=_e?"critical":i<=ve?"urgent":i<=fe?"warning":"normal";var i;const a=null!==t?t/100*6e3:null,o=null!==a?Math.floor(a/this._glassSize):null,n={beer:this._beer??{...Be(),slug:"no-keg",name:"No keg detected"},temp:e,kegPct:t,freshDays:r,tier:s,glassCount:o},l="portrait"===this._layout?this._renderPortrait(n):"compact"===this._layout?this._renderCompact(n):"hero"===this._layout?this._renderHero(n):"vessel"===this._layout?this._renderVessel(n):this._renderLandscape(n);return N`
+ `}};e([ge({attribute:!1})],Ie.prototype,"hass",void 0),e([pe()],Ie.prototype,"_config",void 0),e([pe()],Ie.prototype,"_devices",void 0),Ie=e([ce("perfectdraft-card-editor")],Ie);function Se(){const e=document.querySelectorAll("script[src]");for(const t of e){const e=t.src;if(e.includes("perfectdraft-card"))return e.substring(0,e.lastIndexOf("/")+1)}return"/hacsfiles/perfectdraft-card/"}function De(e,t){return`perfectdraft-card:${e}:${t}`}function Le(e){if(!e||"unavailable"===e||"unknown"===e)return null;const t=parseFloat(e);return isNaN(t)?null:t}let ze=class extends ne{constructor(){super(...arguments),this._glassSize=ye,this._layout=Fe,this._showGlassDialog=!1,this._failedImages=new Set,this._entityIds={},this._entitiesResolved=!1,this._openGlassDialog=()=>{this._showGlassDialog=!0}}setConfig(e){if(!e.device_id)throw new Error("PerfectDraft Card: No device configured. Please use the visual editor to select a PerfectDraft device.");var t;this._config?.device_id!==e.device_id&&(this._entityIds={},this._entitiesResolved=!1,this._beer=void 0),this._config={...e},this._layout=(t=e.layout,be.some(e=>e.value===t)?t:Fe);const r=e.matrix_columns;this._matrixColumns="number"==typeof r&&Number.isFinite(r)&&r>0?Math.floor(r):void 0,this._maxMatrixWidth="string"==typeof e.max_matrix_width&&e.max_matrix_width.trim()?e.max_matrix_width.trim():void 0;const s=localStorage.getItem(De(e.device_id,"glass"));this._glassSize=s?parseInt(s,10):e.glass_size??ye}getCardSize(){switch(this._layout){case"compact":return 1;case"vessel":return 4;case"portrait":return 6;default:return 5}}getGridOptions(){switch(this._layout){case"compact":return{rows:1,columns:12,min_columns:2,min_rows:1};case"portrait":return{rows:5,columns:6,min_columns:1,min_rows:3};case"vessel":return{rows:4,columns:6,min_columns:1,min_rows:2};case"hero":return{rows:5,columns:8,min_columns:1,min_rows:2};default:return{columns:4,rows:3,min_columns:1,min_rows:2}}}static getStubConfig(e){const t=e.entities||{},r=new Set;for(const e of Object.values(t))e.platform===me&&e.device_id&&r.add(e.device_id);return{device_id:1===r.size?[...r][0]:"",glass_size:ye,layout:Fe}}static getConfigElement(){return document.createElement("perfectdraft-card-editor")}connectedCallback(){super.connectedCallback(),this._resolveEntities()}willUpdate(e){(e.has("hass")||e.has("_config"))&&(this._resolveEntities(),this._updateDetectedBeer())}_resolveEntities(){if(!this.hass||!this._config?.device_id)return;if(this._entitiesResolved)return;const e=this.hass.entities||{};for(const[t,r]of Object.entries(e)){if(r.platform!==me||r.device_id!==this._config.device_id)continue;const e=r.translation_key;"temperature"===e?this._entityIds.temperature=t:"keg_remaining"===e?this._entityIds.kegRemaining=t:"keg_freshness"===e?this._entityIds.kegFreshness=t:"keg_product_id"===e?this._entityIds.kegProduct=t:"keg_name"===e&&(this._entityIds.kegName=t)}this._entitiesResolved=Boolean(this._entityIds.temperature&&this._entityIds.kegRemaining&&this._entityIds.kegFreshness&&this._entityIds.kegProduct&&this._entityIds.kegName)}get _kegSensorsMissing(){return Boolean(this._entityIds.temperature)&&!this._entityIds.kegProduct&&!this._entityIds.kegName}get _beerDetected(){return void 0!==this._beer}_updateDetectedBeer(){if(!this._config)return;const e=this._config.beer_name?.trim();if(e)return void this._assignBeer(Pe(e,this._config.custom_beers));const t=this._getState(this._entityIds.kegProduct),r=this._getState(this._entityIds.kegName),s=r&&"unavailable"!==r&&"unknown"!==r?r:void 0;let i;t&&/^\d+$/.test(t)&&(i=function(e){if(e)return Ce.get(e)}(t)),!i&&s&&(i=Pe(s,this._config.custom_beers)),this._assignBeer(i)}_assignBeer(e){e?.slug===this._beer?.slug&&e?.name===this._beer?.name||(this._beer=e)}_getState(e){if(e&&this.hass)return this.hass.states[e]?.state}_selectGlass(e){this._glassSize=e,this._showGlassDialog=!1,this._config?.device_id&&localStorage.setItem(De(this._config.device_id,"glass"),String(e))}_imgError(e){this._failedImages=new Set(this._failedImages).add(e)}render(){if(!this._config||!this.hass)return N`Loading...
`;if(!this._config.device_id)return N`No device configured. Please edit this card to select a PerfectDraft device.
`;if(this._kegSensorsMissing)return N`This card needs the keg sensors added in PerfectDraft integration 0.4.0. Please update the integration, then reload this page.
`;const e=Le(this._getState(this._entityIds.temperature)),t=Le(this._getState(this._entityIds.kegRemaining)),r=Le(this._getState(this._entityIds.kegFreshness)),s=null===(i=r)?"normal":i<=xe?"expired":i<=_e?"critical":i<=ve?"urgent":i<=fe?"warning":"normal";var i;const a=null!==t?t/100*6e3:null,o=null!==a?Math.floor(a/this._glassSize):null,n={beer:this._beer??{...Be(),slug:"no-keg",name:"No keg detected"},temp:e,kegPct:t,freshDays:r,tier:s,glassCount:o},l="portrait"===this._layout?this._renderPortrait(n):"compact"===this._layout?this._renderCompact(n):"hero"===this._layout?this._renderHero(n):"vessel"===this._layout?this._renderVessel(n):this._renderLandscape(n);return N`
${l}
${this._showGlassDialog?this._renderGlassDialog():W}
diff --git a/openspec/changes/auto-detect-gap-closure/specs/keg-auto-detection/spec.md b/openspec/changes/auto-detect-gap-closure/specs/keg-auto-detection/spec.md
index 3b33675..d31c95a 100644
--- a/openspec/changes/auto-detect-gap-closure/specs/keg-auto-detection/spec.md
+++ b/openspec/changes/auto-detect-gap-closure/specs/keg-auto-detection/spec.md
@@ -81,3 +81,9 @@ The card SHALL continue attempting entity resolution until the expected sensors
#### Scenario: Resolution stops once complete
- **WHEN** all expected sensor entities for the device have been resolved
- **THEN** the card SHALL NOT repeat the registry scan on subsequent `hass` updates
+
+#### Scenario: Configured device changes
+- **WHEN** the card's configured `device_id` changes, for example because the user picked a different device in the editor
+- **THEN** the card SHALL discard the previously resolved entity IDs and the previously detected beer
+- **THEN** the card SHALL resolve entities afresh for the newly configured device
+- **THEN** the card SHALL NOT display values read from the previous device
diff --git a/openspec/changes/auto-detect-gap-closure/tasks.md b/openspec/changes/auto-detect-gap-closure/tasks.md
index f6c7908..510e564 100644
--- a/openspec/changes/auto-detect-gap-closure/tasks.md
+++ b/openspec/changes/auto-detect-gap-closure/tasks.md
@@ -38,6 +38,7 @@
- [x] 6.1 Replace the `if (this._entityIds.temperature) return;` latch in `_resolveEntities` with a condition that only stops once the expected sensor set is resolved
- [x] 6.2 Verify that keg sensors added after first render are picked up on a later `hass` update without a browser reload, and that the scan stops once complete
+- [x] 6.3 Invalidate the resolved entity IDs and detected beer in `setConfig` when `device_id` changes, so switching devices in the editor does not keep reading the previous device's sensors (pre-existing bug, surfaced by review)
## 7. Documentation and release
diff --git a/src/perfectdraft-card.ts b/src/perfectdraft-card.ts
index a444109..72ee479 100644
--- a/src/perfectdraft-card.ts
+++ b/src/perfectdraft-card.ts
@@ -81,6 +81,16 @@ export class PerfectDraftCard extends LitElement {
"PerfectDraft Card: No device configured. Please use the visual editor to select a PerfectDraft device.",
);
}
+
+ // Entity IDs and the detected beer belong to a specific device, so switching
+ // devices in the editor has to invalidate them. Without this the card keeps
+ // reading the previous device's sensors.
+ if (this._config?.device_id !== config.device_id) {
+ this._entityIds = {};
+ this._entitiesResolved = false;
+ this._beer = undefined;
+ }
+
this._config = { ...config };
this._layout = resolveLayout(config.layout) as CardLayout;