Skip to content

Commit

Permalink
refactor: Update VehicleButtons component to remove console log state…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
ngocjohn committed Sep 30, 2024
1 parent ae8c25d commit f348ce1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
11 changes: 2 additions & 9 deletions src/components/cards/vic-vehicle-buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,7 +55,7 @@ export class VehicleButtons extends LitElement {
return this._config.button_grid?.use_swiper || false;
}

protected async firstUpdated(_changedProperties: PropertyValues): Promise<void> {
protected firstUpdated(_changedProperties: PropertyValues): void {
super.firstUpdated(_changedProperties);
this._fetchSecondaryInfo();
}
Expand All @@ -68,21 +68,15 @@ export class VehicleButtons extends LitElement {
}

private async checkCustomChanged(): Promise<void> {
// 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');
}
}

Expand All @@ -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]);
})
);

Expand Down
2 changes: 1 addition & 1 deletion src/components/editor/custom-button-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class CustomButtonAction extends LitElement {

const updates: Partial<VehicleCardConfig> = {};

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;
Expand Down
14 changes: 7 additions & 7 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
},
];

Expand Down Expand Up @@ -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 = {
Expand Down
5 changes: 2 additions & 3 deletions src/vehicle-info-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -60,7 +60,6 @@ export class VehicleCard extends LitElement implements LovelaceCard {
@state() private _activeSubCard: Set<string> = new Set();
@state() private _mapPopupLovelace: LovelaceCardConfig[] = [];
@state() private chargingInfoVisible!: boolean;
@state() private isTyreHorizontal!: boolean;

// Preview states
@state() private _currentPreviewType: 'button' | 'card' | 'tire' | null = null;
Expand Down Expand Up @@ -156,8 +155,8 @@ export class VehicleCard extends LitElement implements LovelaceCard {
protected async firstUpdated(_changedProperties: PropertyValues): Promise<void> {
super.firstUpdated(_changedProperties);
await handleCardFirstUpdated(this);
this._setUpPreview();
this.setUpButtonCards();
this._setUpPreview();
}

protected updated(changedProps: PropertyValues): void {
Expand Down

0 comments on commit f348ce1

Please sign in to comment.