Skip to content

Commit

Permalink
Added Charging Notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
WJDDesigns committed Aug 1, 2024
1 parent 11f7797 commit 7ff1d36
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 8 deletions.
22 changes: 22 additions & 0 deletions styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,26 @@ export const styles = css`
input:checked + .slider:before {
transform: translateX(26px);
}
/* Charging animation */
.charging {
animation: pulse-blue 2s infinite;
}
@keyframes pulse-blue {
0% {
transform: scale(0.95);
box-shadow: 0 0 0 0 rgba(52, 172, 224, 0.7);
}
70% {
transform: scale(1);
box-shadow: 0 0 0 10px rgba(52, 172, 224, 0);
}
100% {
transform: scale(0.95);
box-shadow: 0 0 0 0 rgba(52, 172, 224, 0);
}
}
`;
20 changes: 18 additions & 2 deletions ultra-vehicle-card-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export class UltraVehicleCardEditor extends LitElement {
hass: { type: Object },
config: { type: Object },
_levelEntityFilter: { type: String },
_rangeEntityFilter: { type: String }
_rangeEntityFilter: { type: String },
_chargingStatusEntityFilter: { type: String }
};
}

Expand All @@ -19,6 +20,7 @@ export class UltraVehicleCardEditor extends LitElement {
super();
this._levelEntityFilter = '';
this._rangeEntityFilter = '';
this._chargingStatusEntityFilter = '';
}

setConfig(config) {
Expand All @@ -28,6 +30,7 @@ export class UltraVehicleCardEditor extends LitElement {
vehicle_type: "EV",
level_entity: "",
range_entity: "",
charging_status_entity: "",
show_level: true,
show_range: true,
...config
Expand Down Expand Up @@ -113,6 +116,15 @@ export class UltraVehicleCardEditor extends LitElement {
</label>
</div>
</div>
${this.config.vehicle_type === 'EV' ? html`
<div class="input-group">
<div class="entity-row">
<label for="charging_status_entity">Charging Status Entity</label>
${this._renderEntityPicker('charging_status_entity', this._chargingStatusEntityFilter)}
</div>
</div>
` : ''}
</div>
`;
}
Expand Down Expand Up @@ -153,6 +165,8 @@ export class UltraVehicleCardEditor extends LitElement {
this._levelEntityFilter = filter;
} else if (configValue === 'range_entity') {
this._rangeEntityFilter = filter;
} else if (configValue === 'charging_status_entity') {
this._chargingStatusEntityFilter = filter;
}
this.requestUpdate();
}
Expand All @@ -166,6 +180,8 @@ export class UltraVehicleCardEditor extends LitElement {
this._levelEntityFilter = '';
} else if (configValue === 'range_entity') {
this._rangeEntityFilter = '';
} else if (configValue === 'charging_status_entity') {
this._chargingStatusEntityFilter = '';
}
this.configChanged(this.config);
}
Expand Down Expand Up @@ -229,4 +245,4 @@ export class UltraVehicleCardEditor extends LitElement {
}
}

customElements.define("ultra-vehicle-card-editor", UltraVehicleCardEditor);
customElements.define("ultra-vehicle-card-editor", UltraVehicleCardEditor);
41 changes: 35 additions & 6 deletions ultra-vehicle-card.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LitElement, html } from "https://unpkg.com/lit-element@2.4.0/lit-element.js?module";
import { LitElement, html, css } from "https://unpkg.com/lit-element@2.4.0/lit-element.js?module";
import { UltraVehicleCardEditor } from "./ultra-vehicle-card-editor.js";
import { styles } from "./styles.js";

Expand All @@ -11,7 +11,31 @@ class UltraVehicleCard extends LitElement {
}

static get styles() {
return styles;
return [
styles,
css`
@keyframes pulse-blue {
0% {
transform: scale(0.95);
box-shadow: 0 0 0 0 rgba(52, 172, 224, 0.7);
}
70% {
transform: scale(1);
box-shadow: 0 0 0 10px rgba(52, 172, 224, 0);
}
100% {
transform: scale(0.95);
box-shadow: 0 0 0 0 rgba(52, 172, 224, 0);
}
}
.charging {
animation: pulse-blue 2s infinite;
}
`
];
}

setConfig(config) {
Expand All @@ -24,6 +48,7 @@ class UltraVehicleCard extends LitElement {
vehicle_type: "EV",
show_level: true,
show_range: true,
charging_status_entity: "",
...config
};
}
Expand All @@ -41,10 +66,13 @@ class UltraVehicleCard extends LitElement {
const range = rangeEntity ? Math.round(parseFloat(rangeEntity.state)) : null;
const rangeUnit = this._getRangeUnit();

const chargingStatusEntity = this.config.charging_status_entity ? this.hass.states[this.config.charging_status_entity] : null;
const isCharging = chargingStatusEntity && chargingStatusEntity.state.toLowerCase() === 'charging';

return html`
<ha-card>
<ha-card class="${isCharging ? 'charging' : ''}">
<div class="vehicle-card-content">
<h2 class="vehicle-name" style="text-align: center;">${this.config.title}</h2>
<h2 class="vehicle-name">${this.config.title}</h2>
${this.config.image_url ? html`
<div class="vehicle-image-container">
<img class="vehicle-image" src="${this.config.image_url}" alt="Vehicle Image">
Expand All @@ -56,7 +84,7 @@ class UltraVehicleCard extends LitElement {
<div class="progress" style="width: ${level}%;"></div>
</div>
<div class="level-text">
<span>${level}% ${levelUnit}</span>
<span>${isCharging ? 'Charging' : `${level}% ${levelUnit}`}</span>
${this.config.show_range && this.config.range_entity && range !== null ? html`<span class="range">${range} ${rangeUnit}</span>` : ''}
</div>
</div>
Expand Down Expand Up @@ -88,6 +116,7 @@ class UltraVehicleCard extends LitElement {
vehicle_type: "EV",
level_entity: "",
range_entity: "",
charging_status_entity: "",
show_level: true,
show_range: true
};
Expand All @@ -102,4 +131,4 @@ window.customCards.push({
name: "Ultra Vehicle Card",
description: "A card that displays vehicle information with fuel/charge level and range.",
preview: true
});
});

0 comments on commit 7ff1d36

Please sign in to comment.