From f348ce19bca9331d7cbc6fbd30667bcaf033566d Mon Sep 17 00:00:00 2001 From: Viet Ngoc Date: Tue, 1 Oct 2024 00:51:18 +0200 Subject: [PATCH] refactor: Update VehicleButtons component to remove console log statement --- src/components/cards/vic-vehicle-buttons.ts | 11 ++--------- src/components/editor/custom-button-action.ts | 2 +- src/editor.ts | 14 +++++++------- src/vehicle-info-card.ts | 5 ++--- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/components/cards/vic-vehicle-buttons.ts b/src/components/cards/vic-vehicle-buttons.ts index 41d6d14..8287afc 100644 --- a/src/components/cards/vic-vehicle-buttons.ts +++ b/src/components/cards/vic-vehicle-buttons.ts @@ -19,7 +19,7 @@ export class VehicleButtons extends LitElement { @property({ type: Object }) _config!: VehicleCardConfig; @property({ type: Object }) _buttons!: ButtonCardEntity; - @state() private _isButtonReady = false; + @state() private _isButtonReady: boolean = false; @state() _secondaryInfo: { [key: string]: CustomButton } = {}; private swiper: Swiper | null = null; @@ -55,7 +55,7 @@ export class VehicleButtons extends LitElement { return this._config.button_grid?.use_swiper || false; } - protected async firstUpdated(_changedProperties: PropertyValues): Promise { + protected firstUpdated(_changedProperties: PropertyValues): void { super.firstUpdated(_changedProperties); this._fetchSecondaryInfo(); } @@ -68,21 +68,15 @@ export class VehicleButtons extends LitElement { } private async checkCustomChanged(): Promise { - // console.log('check custom changed'); let changed = false; const changedKeys: string[] = []; for (const key in this._secondaryInfo) { const oldState = this._secondaryInfo[key].state; const oldNotify = this._secondaryInfo[key].notify; - // check if the state or notify has changed const { state, notify } = await this._getSecondaryInfo(key); if (oldState !== state || oldNotify !== notify) { - // this._fetchSecondaryInfo(); - // console.log('change detected'); changedKeys.push(key); changed = true; - } else { - // console.log('no change detected'); } } @@ -91,7 +85,6 @@ export class VehicleButtons extends LitElement { await Promise.all( changedKeys.map(async (key) => { newSecondaryInfo[key] = await this._getSecondaryInfo(key); - // console.log('secondary info', newSecondaryInfo[key]); }) ); diff --git a/src/components/editor/custom-button-action.ts b/src/components/editor/custom-button-action.ts index 1ba9751..f3a2642 100644 --- a/src/components/editor/custom-button-action.ts +++ b/src/components/editor/custom-button-action.ts @@ -127,7 +127,7 @@ export class CustomButtonAction extends LitElement { const updates: Partial = {}; - if (this.config.added_cards.hasOwnProperty(buttonName)) { + if (this.config.added_cards && this.config.added_cards[buttonName]) { const button = { ...(this.config.added_cards[buttonName].button || {}) }; const buttonActionConfig = { ...(button.button_action || {}) }; buttonActionConfig[configValue] = newValue; diff --git a/src/editor.ts b/src/editor.ts index 444f7c2..1fcb289 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -23,11 +23,11 @@ import { ExtendedButtonConfigItem, defaultConfig, } from './types'; +import { Create } from './utils'; import { uploadImage } from './utils/editor-image-handler'; import { handleFirstUpdated, deepMerge } from './utils/ha-helpers'; import { compareVersions } from './utils/helpers'; import { loadHaComponents, stickyPreview } from './utils/loader'; -import { Create } from './utils'; // Import the custom card components import './components/editor'; @@ -773,35 +773,35 @@ export class VehicleCardEditor extends LitElement implements LovelaceCardEditor value: tireCard.image_size || 100, label: 'Base image size', configValue: 'image_size', - pickerType: 'number' as 'number', + pickerType: 'number' as const, options: { selector: { number: { max: 200, min: 0, mode: 'slider', step: 1 } } }, }, { value: tireCard.value_size || 100, label: 'Name & Value size', configValue: 'value_size', - pickerType: 'number' as 'number', + pickerType: 'number' as const, options: { selector: { number: { max: 150, min: 50, mode: 'slider', step: 1 } } }, }, { value: tireCard.top || 50, label: `${tireCard.horizontal ? 'Horizontal' : 'Vertical'} position`, configValue: 'top', - pickerType: 'number' as 'number', + pickerType: 'number' as const, options: { selector: { number: { max: 100, min: 0, mode: 'slider', step: 1 } } }, }, { value: tireCard.left || 50, label: `${tireCard.horizontal ? 'Vertical' : 'Horizontal'} position`, configValue: 'left', - pickerType: 'number' as 'number', + pickerType: 'number' as const, options: { selector: { number: { max: 100, min: 0, mode: 'slider', step: 1 } } }, }, { value: tireCard.horizontal || false, label: 'Horizontal layout', configValue: 'horizontal', - pickerType: 'selectorBoolean' as 'selectorBoolean', + pickerType: 'selectorBoolean' as const, }, ]; @@ -1474,7 +1474,7 @@ export class VehicleCardEditor extends LitElement implements LovelaceCardEditor this._dispatchCardEvent('close_preview'); }, 50); } else { - let tireConfig = this._config.extra_configs?.tire_card_custom; + const tireConfig = this._config.extra_configs?.tire_card_custom; console.log('Setting tire preview'); if (this._config) { this._config = { diff --git a/src/vehicle-info-card.ts b/src/vehicle-info-card.ts index fd9fc05..bf5a853 100644 --- a/src/vehicle-info-card.ts +++ b/src/vehicle-info-card.ts @@ -11,9 +11,9 @@ import { LovelaceCard, } from 'custom-card-helpers'; import { LitElement, html, TemplateResult, PropertyValues, CSSResultGroup, nothing } from 'lit'; +import { styleMap } from 'lit-html/directives/style-map.js'; import { customElement, property, state, query } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; -import { styleMap } from 'lit-html/directives/style-map.js'; import './components/cards'; import { VehicleButtons } from './components/cards'; @@ -60,7 +60,6 @@ export class VehicleCard extends LitElement implements LovelaceCard { @state() private _activeSubCard: Set = new Set(); @state() private _mapPopupLovelace: LovelaceCardConfig[] = []; @state() private chargingInfoVisible!: boolean; - @state() private isTyreHorizontal!: boolean; // Preview states @state() private _currentPreviewType: 'button' | 'card' | 'tire' | null = null; @@ -156,8 +155,8 @@ export class VehicleCard extends LitElement implements LovelaceCard { protected async firstUpdated(_changedProperties: PropertyValues): Promise { super.firstUpdated(_changedProperties); await handleCardFirstUpdated(this); - this._setUpPreview(); this.setUpButtonCards(); + this._setUpPreview(); } protected updated(changedProps: PropertyValues): void {