Skip to content

Commit

Permalink
Merge pull request #88 from vingerha/main
Browse files Browse the repository at this point in the history
Extend Tempo with 'remaining days'
  • Loading branch information
vingerha authored Aug 30, 2023
2 parents d13eabe + 998652c commit 7be5385
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dist/content-card-linky-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class contentCardLinkyEditor extends LitElement {
return this._config.ewEntityJ2 || "";
}

get _tempoEntity() {
return this._config.tempoEntityInfo || "";
}

get _tempoEntityJ0() {
return this._config.tempoEntityJ0 || "";
}
Expand Down Expand Up @@ -195,6 +199,7 @@ export class contentCardLinkyEditor extends LitElement {
${this.renderSensorPicker("EcoWatt", this._ewEntity, "ewEntity")}
${this.renderSensorPicker("EcoWattJ1", this._ewEntityJ1, "ewEntityJ1")}
${this.renderSensorPicker("EcoWattJ2", this._ewEntityJ2, "ewEntityJ2")}
${this.renderSensorPicker("TempoInfo", this._tempoEntityInfo, "tempoEntityInfo")}
${this.renderSensorPicker("TempoJ0", this._tempoEntityJ0, "tempoEntityJ0")}
${this.renderSensorPicker("TempoJ1", this._tempoEntityJ1, "tempoEntityJ1")}
<!-- Switches -->
Expand Down
22 changes: 21 additions & 1 deletion dist/content-card-linky.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,13 @@ class ContentCardLinky extends LitElement {
return [tempoDate, tempoValues.get(tempoValue), tempoValue];
}

getTempoRemainingDays(tempoEntity) {
let tempoRemainingRed = tempoEntity.attributes["days_red"];
let tempoRemainingWhite = tempoEntity.attributes["days_white"];
let tempoRemainingBlue = tempoEntity.attributes["days_blue"];
return [tempoRemainingRed, tempoRemainingWhite, tempoRemainingBlue];
}

renderTempo(attributes, config) {
if (attributes.serviceEnedis === undefined ){
return html ``;
Expand All @@ -703,17 +710,23 @@ class ContentCardLinky extends LitElement {
if (this.config.showTempo === false ){
return html ``;
}
let sensorName = this.config.tempoEntityInfo;
const tempoInfo = this.hass.states[sensorName];
let sensorNameJ0 = this.config.tempoEntityJ0;
const tempoJ0 = this.hass.states[sensorNameJ0];
let sensorNameJ1 = this.config.tempoEntityJ1;
const tempoJ1 = this.hass.states[sensorNameJ1];

if (!tempoJ0 || tempoJ0.length === 0 || !tempoJ1 || tempoJ1.length === 0) {
return html `Tempo: sensor(s) indisponible ou incorrecte`;
return html `Tempo: sensor(s) J0 et/ou J1 indisponible ou incorrecte`;
}
if (!tempoInfo || tempoInfo.length === 0) {
return html `Tempo: sensor 'info' indisponible ou incorrecte`;
}

let [dateJ0, valueJ0, stateJ0] = this.getTempoDateValue(tempoJ0);
let [dateJ1, valueJ1, stateJ1] = this.getTempoDateValue(tempoJ1);
let [remainingRed, remainingWhite, remainingBlue] = this.getTempoRemainingDays(tempoInfo);

return html`
<table style="width:100%">
Expand All @@ -722,6 +735,13 @@ class ContentCardLinky extends LitElement {
<td class="tempo-${valueJ1}" style="width:50%">${ (new Date(dateJ1)).toLocaleDateString('fr-FR', {weekday: 'long', day: 'numeric'})}</td>
</tr>
</table>
<table style="width:100%">
<tr>
<td class="tempo-red" style="width:33.33%">${remainingRed}</td>
<td class="tempo-white" style="width:33.33%">${remainingWhite}</td>
<td class="tempo-blue" style="width:33.33%">${remainingBlue}</td>
</tr>
</table>
`

Expand Down

0 comments on commit 7be5385

Please sign in to comment.