From 2f291b205713887800948f5264fae59565949eb5 Mon Sep 17 00:00:00 2001 From: Ristomatti Airo Date: Thu, 29 Feb 2024 21:54:59 +0200 Subject: [PATCH 1/2] chore: Reformat vacuum-card.ts --- src/vacuum-card.ts | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/vacuum-card.ts b/src/vacuum-card.ts index aa4afd66..66a1ebbf 100755 --- a/src/vacuum-card.ts +++ b/src/vacuum-card.ts @@ -31,13 +31,13 @@ const PKG_VERSION = 'PKG_VERSION_VALUE'; console.info( `%c VACUUM-CARD %c ${PKG_VERSION}`, 'color: white; background: blue; font-weight: 700;', - 'color: blue; background: white; font-weight: 700;' + 'color: blue; background: white; font-weight: 700;', ); if (!customElements.get('ha-icon-button')) { customElements.define( 'ha-icon-button', - class extends (customElements.get('paper-icon-button') ?? HTMLElement) {} + class extends (customElements.get('paper-icon-button') ?? HTMLElement) {}, ); } @@ -105,7 +105,7 @@ export class VacuumCard extends LitElement { this.requestUpdate(); this.thumbUpdater = setInterval( () => this.requestUpdate(), - this.config.map_refresh * 1000 + this.config.map_refresh * 1000, ); } } @@ -127,7 +127,7 @@ export class VacuumCard extends LitElement { { bubbles: false, composed: true, - } + }, ); } @@ -140,7 +140,7 @@ export class VacuumCard extends LitElement { private callVacuumService( service: ServiceCallRequest['service'], params: VacuumServiceCallParams = { request: true }, - options: ServiceCallRequest['serviceData'] = {} + options: ServiceCallRequest['serviceData'] = {}, ) { this.hass.callService('vacuum', service, { entity_id: this.config.entity, @@ -160,7 +160,7 @@ export class VacuumCard extends LitElement { private handleVacuumAction( action: string, - params: VacuumActionParams = { request: true } + params: VacuumActionParams = { request: true }, ) { return () => { if (!this.config.actions[action]) { @@ -182,7 +182,7 @@ export class VacuumCard extends LitElement { private renderSource(): Template { const { fan_speed: source, fan_speed_list: sources } = this.getAttributes( - this.entity + this.entity, ); if (!sources || !source) { @@ -201,16 +201,15 @@ export class VacuumCard extends LitElement { ${sources.map( - (item, index) => - html` - - ${localize(`source.${item.toLowerCase()}`) || item} - - ` + (item, index) => html` + + ${localize(`source.${item.toLowerCase()}`) || item} + + `, )} @@ -295,7 +294,7 @@ export class VacuumCard extends LitElement {
${subtitle}
`; - } + }, ); if (!stats.length) { @@ -421,7 +420,7 @@ export class VacuumCard extends LitElement { `; - } + }, ); const dockButton = html` From 182afbee07c28bcc2683a5b11e62d937a899b09f Mon Sep 17 00:00:00 2001 From: Ristomatti Airo Date: Thu, 29 Feb 2024 21:56:42 +0200 Subject: [PATCH 2/2] fix: Reference to null status value on HA versions >=2024.2 After upgrading to Home Assistant 2024.2.4, vacuum-card didn't render due to null reference. The error shown on the console: Uncaught (in promise) TypeError: Cannot read properties of null (reading 'toLowerCase') at qr.renderStatus (vacuum-card.js?hacstag=261291295280:4:14674) at qr.render (vacuum-card.js?hacstag=261291295280:4:17680) at qr.update (vacuum-card.js?hacstag=261291295280:1:15173) at qr.performUpdate (vacuum-card.js?hacstag=261291295280:1:6493) at qr.scheduleUpdate (vacuum-card.js?hacstag=261291295280:1:6140) at qr._$Ej (vacuum-card.js?hacstag=261291295280:1:6048) Based on the types, both `status` and `state` attributes can be undefined, while the `state` on the entity itself always has a string value. By reorganizing the return value of `getAttributes`, we ensure the derived `status` won't get overwritten by an undefined `entity.attributes.status`. --- src/vacuum-card.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vacuum-card.ts b/src/vacuum-card.ts index 66a1ebbf..4115d0bd 100755 --- a/src/vacuum-card.ts +++ b/src/vacuum-card.ts @@ -175,8 +175,8 @@ export class VacuumCard extends LitElement { const { status, state } = entity.attributes; return { - status: status || state || entity.state, ...entity.attributes, + status: status ?? state ?? entity.state, }; }