Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
tmjo committed Oct 31, 2020
1 parent 0604a15 commit 13a931b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 94 deletions.
4 changes: 0 additions & 4 deletions src/charger-card-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ export class ChargerCardEditor extends LitElement {

get _show_name() {
if (this._config) {
// if(this._config.show_name != undefined){
// console.log("this config show_name: " +this._config.show_name);
// return this._config.show_name;
// }
return this._config.show_name !== undefined ? this._config.show_name : true;
}
return true;
Expand Down
49 changes: 5 additions & 44 deletions src/charger-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { hasConfigOrEntityChanged, fireEvent, domainIcon } from 'custom-card-hel
import './charger-card-editor';
import localize from './localize';
import styles from './styles';
// import defaultImage from './img/charger_generic_223x302.png';
import * as cconst from './const';

if (!customElements.get('ha-icon-button')) {
Expand Down Expand Up @@ -58,7 +57,6 @@ class ChargerCard extends LitElement {
get usedChargerLimit(){
const { dynamicChargerCurrent, dynamicCircuitCurrent, maxChargerCurrent, maxCircuitCurrent } = this.getEntities();
const circuitRatedCurrent = this.hass.states[this.config.entity].attributes["circuit_ratedCurrent"];
// const usedChargerLimit = Math.min(dynamicChargerCurrent.state, dynamicCircuitCurrent.state, maxChargerCurrent.state, maxCircuitCurrent.state, circuitRatedCurrent);
const usedChargerLimit = Math.min(this.getEntityState(dynamicChargerCurrent), this.getEntityState(dynamicCircuitCurrent), this.getEntityState(maxChargerCurrent), this.getEntityState(maxCircuitCurrent), circuitRatedCurrent);
return usedChargerLimit;
}
Expand Down Expand Up @@ -149,9 +147,6 @@ class ChargerCard extends LitElement {

getEntityId(entity_base){
try{

// let myVar = entity_base.split(".")[0] + "." +this.entityBasename +"_" +entity_base.split(".")[1];
// console.log(myVar);
return entity_base.split(".")[0] + "." +this.entityBasename +"_" +entity_base.split(".")[1];
}catch(err){
return null;
Expand Down Expand Up @@ -232,14 +227,6 @@ class ChargerCard extends LitElement {
return null;
}
}
// getEntityState(entity_base){
// console.log(entity_base);
// try{
// return this.getEntity(entity_base).state;
// }catch(err){
// return null;
// }
// }

getEntityAttribute(entity_base, attribute){
try{
Expand Down Expand Up @@ -404,7 +391,6 @@ class ChargerCard extends LitElement {
}

renderImage(state) {
// if (this.compactView || !this.image) {
let compactview = "";
if(this.compactView){compactview = "-compact";}

Expand All @@ -426,7 +412,7 @@ class ChargerCard extends LitElement {
}

renderStats(state) {
/* SHOW DATATABLE? */
/* SHOW DATATABLE */
if (!this.showStats) {
return html``;
}
Expand Down Expand Up @@ -521,7 +507,7 @@ class ChargerCard extends LitElement {


renderCollapsibleConfig(){
/* SHOW COLLAPSIBLE? */
/* SHOW COLLAPSIBLES */
if (!this.showCollapsibles) {
return html``;
}
Expand Down Expand Up @@ -555,7 +541,7 @@ class ChargerCard extends LitElement {
}

renderCollapsibleInfo(){
/* SHOW COLLAPSIBLE? */
/* SHOW COLLAPSIBLES */
if (!this.showCollapsibles) {
return html``;
}
Expand Down Expand Up @@ -587,7 +573,7 @@ class ChargerCard extends LitElement {
}

renderCollapsibleLimits(){
/* SHOW COLLAPSIBLE? */
/* SHOW COLLAPSIBLES */
if (!this.showCollapsibles) {
return html``;
}
Expand Down Expand Up @@ -621,12 +607,10 @@ class ChargerCard extends LitElement {
return html``;
}

// let value = entity.state;
let value = this.getEntityState(entity);
let icon = this.renderIcon(entity);
let useUnit = this.getEntityAttribute(entity, 'unit_of_measurement');
if(round){
// value = Math.round(entity.state);
value = Math.round(value);
}
return html`
Expand Down Expand Up @@ -665,9 +649,7 @@ class ChargerCard extends LitElement {

const sources = cconst.CURRENTLIMITS;
let value = this.getEntityState(entity);
// let selected = sources.indexOf(entity.state);
let selected = sources.indexOf(value);
// let useUnit = entity.attributes['unit_of_measurement'];
let useUnit = this.getEntityAttribute(entity, 'unit_of_measurement');
let useIcon = icon === undefined ? this.renderIcon(entity) : icon;

Expand Down Expand Up @@ -715,13 +697,10 @@ class ChargerCard extends LitElement {
if(entity === null || entity === undefined){
return html``;
}
// let value = entity.state;
let value = this.getEntityState(entity);
// let unit = entity.attributes['unit_of_measurement'];
let useUnit = this.getEntityAttribute(entity, 'unit_of_measurement');
let icon = this.renderIcon(entity);
if(round){
// value = Math.round(entity.state);
value = Math.round(value);
}
return html`
Expand All @@ -736,28 +715,21 @@ class ChargerCard extends LitElement {
}

renderIcon(entity){
// let icon = entity.attributes['icon'] ==! undefined ? entity.attributes['icon'] : cconst.ICONS[this.getEntityBase(entity.entity_id)] || "mdi:cancel";
let entity_id = entity.entity_id;
let icon = this.getEntityAttribute(entity, 'icon') ==! null ? this.getEntityAttribute(entity, 'icon') : cconst.ICONS[this.getEntityBase(entity_id)] || "mdi:cancel";
let domainIcon = this.getEntityAttribute(entity, 'device_class') ==! null ? domainIcon(this.getEntityAttribute(entity, 'device_class'), this.getEntityState(entity)) : false;
// return domainicon ==! undefined ? domainicon : icon ==! undefined ? icon : cconst.ICONS[this.getEntityBase(entity.entity_id)] || "mdi:cancel";
return domainIcon || icon;
}

renderToolbar(state) {
/* SHOW TOOLBAR? */
/* SHOW TOOLBAR */
if (!this.showToolbar) {
return html``;
}

/* CUSTOM BUTTONS FROM CONFIG */
const { actions = [] } = this.config;
const customButtons = actions.map(({ name, service, icon, service_data }) => {
// const execute = () => {
// const [domain, name] = service.split('.');
// this.hass.callService(domain, name, service_data);
// };
// return html`<ha-icon-button icon="${icon}" title="${name}" @click="${execute}"></ha-icon-button>`;
return this.renderToolbarButton(service, icon, name, service_data);
});

Expand Down Expand Up @@ -830,17 +802,6 @@ class ChargerCard extends LitElement {
`;
}

// renderToolbarButton(service, icon, text){
// return html`
// <paper-button @click="${() => this.callService(service)}">
// <div class="tooltip">
// <ha-icon icon="${icon}"></ha-icon>
// <span class="tooltiptext">${localize(text)}</span>
// </div>
// </paper-button>
// `;
// }

renderCompact() {
const { state } = this.entity;
return html`
Expand Down
46 changes: 0 additions & 46 deletions src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ import imageBlack from './img/charger_black_223x302.png';
import imageWhite from './img/charger_white_223x302.png';
import imageDarkblue from './img/charger_darkblue_223x302.png';

// export const CHARGER_IMAGES = {
// "Generic": imageGeneric,
// "Anthracite": imageAnthracite,
// "Red": imageRed,
// "Black": imageBlack,
// "White": imageWhite,
// "Darkblue": imageDarkblue
// };

export const DEFAULTIMAGE = "Generic";
export const CHARGER_IMAGES = [
Expand All @@ -69,24 +61,6 @@ export const CHARGER_IMAGES = [
{name: "Darkblue", img: imageDarkblue},
];

// export const CHARGER_IMAGES = new Map([
// ['Generic', imageGeneric],
// ['Anthracite', imageAnthracite],
// ['Red', imageRed],
// ['Black', imageBlack],
// ['White', imageWhite],
// ['Darkblue', imageDarkblue],
// ]);

// export const CHARGER_IMAGES = {
// imageGeneric,
// imageAnthracite,
// imageRed,
// imageBlack,
// imageWhite,
// imageDarkblue,
// };

import ledOff from './img/charger_leds_bg.gif';
import ledWhite2 from './img/charger_leds_white_2.gif';
import ledWhiteAll from './img/charger_leds_white_all.gif';
Expand Down Expand Up @@ -120,26 +94,6 @@ export const LEDIMAGES = {
};


// export const LEDIMAGES = {
// normal: {
// 'STANDBY': "./img/charger_leds_white_2.gif",
// 'PAUSED': "./img/charger_leds_white_all.gif",
// 'CHARGING': "./img/charger_leds_white_flashing.gif",
// 'READY_TO_CHARGE': "./img/charger_leds_white_all.gif",
// 'ERROR': "./img/charger_leds_off.gif",
// 'CAR_CONNECTED': "./img/charger_leds_white_all.gif",
// },
// smart: {
// 'STANDBY': "./img/charger_leds_blue_2.gif",
// 'PAUSED': "./img/charger_leds_blue_all.gif",
// 'CHARGING': "./img/charger_leds_blue_flashing.gif",
// 'READY_TO_CHARGE': "./img/charger_leds_blue_all.gif",
// 'ERROR': "./img/charger_leds_off.gif",
// 'CAR_CONNECTED': "./img/charger_leds_blue_all.gif",
// }

// };

export const ICONS={
"binary_sensor.cable_locked_car" : "mdi:lock",
"switch.cable_permanently_locked_charger" : "mdi:lock",
Expand Down

0 comments on commit 13a931b

Please sign in to comment.