Skip to content

Commit

Permalink
soc from range electric as attr
Browse files Browse the repository at this point in the history
  • Loading branch information
ngocjohn committed Jun 9, 2024
1 parent 827c933 commit 2a9a554
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ export const sensorDeviceFilters: {
distanceStart: { suffix: '_distancestart' },
liquidConsumptionReset: { suffix: '_liquidconsumptionreset' },
liquidConsumptionStart: { suffix: '_liquidconsumptionstart' },
electicConsumptionReset: { suffix: '_electricconsumptionreset' },
electricConsumptionReset: { suffix: '_electricconsumptionreset' },
electricConsumptionStart: { suffix: '_electricconsumptionstart' },
odometer: { suffix: '_odometer' },
rangeLiquid: { suffix: '_rangeliquid' },
rangeElectric: { suffix: '_rangeelectric' },
rangeElectric: { suffix: '_rangeelectrickm' },
fuelLevel: { suffix: '_tanklevelpercent' },
adBlueLevel: { suffix: '_tankleveladblue' },
ecoScoreTotal: { suffix: '_ecoscoretotal' },
Expand Down
23 changes: 14 additions & 9 deletions src/vehicle-info-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export class VehicleCard extends LitElement {
}
}
}
console.log('sensors:', entityIds);
return entityIds;
}

Expand Down Expand Up @@ -608,19 +609,18 @@ export class VehicleCard extends LitElement {

private generateDataRow(
title: string,
data: Array<{ key: string; name?: string; icon?: string }>, // icon is optional now
data: Array<{ key: string; name?: string; icon?: string; state?: string }>, // icon is optional now
entityCollection: any,
): TemplateResult {
return html`
<div class="default-card">
<div class="data-header">${title}</div>
${data.map(({ key, name, icon }) => {
${data.map(({ key, name, icon, state }) => {
const entity = entityCollection[key];
const entityId = entity?.entity_id;
const entityName = name ?? entity?.original_name;
let entityState = entityId ? this.getEntityState(entityId) : '';
let entityState = state ?? this.getEntityState(entityId);
const unitOfMeasurement = entityId ? this.getAttrUnitOfMeasurement(entityId) : '';
// Render correct formated state
if (!isNaN(parseFloat(entityState)) && entityState !== '') {
entityState = formatNumber(entityState, this.hass.locale);
Expand Down Expand Up @@ -649,20 +649,25 @@ export class VehicleCard extends LitElement {

private _renderDefaultTripCard(): TemplateResult | void {
const generateDataArray = (
keys: { key: string; name?: string; icon?: string }[],
): { key: string; name: string; icon: string }[] => {
return keys.map(({ key, name, icon }) => ({
keys: { key: string; name?: string; icon?: string; state?: string }[],
): { key: string; name: string; icon: string; state: string }[] => {
return keys.map(({ key, name, icon, state }) => ({
key,
name: name ?? this.sensorDevices[key]?.original_name,
icon: icon ?? this.getEntityAttribute(this.sensorDevices[key]?.entity_id, 'icon'),
state: state ?? this.getEntityState(this.sensorDevices[key]?.entity_id),
}));
};

const overViewDataKeys = [
{ key: 'odometer' },
{ key: 'fuelLevel' },
{ key: 'rangeLiquid' },
{ key: 'soc' },
{
key: 'soc',
name: 'State of charger',
state: this.getEntityAttribute(this.sensorDevices.rangeElectric?.entity_id, 'soc'),
},
{ key: 'maxSoc' },
{ key: 'rangeElectric' },
];
Expand Down Expand Up @@ -969,7 +974,7 @@ export class VehicleCard extends LitElement {
hollow: {
margin: 5,
size: '40%',
background: 'transparent',
background: '#ffffff',
image: undefined,
},
dataLabels: {
Expand Down

0 comments on commit 2a9a554

Please sign in to comment.