Skip to content

Commit

Permalink
Add click on auto-fan to disable and dlbclick on preset to change the…
Browse files Browse the repository at this point in the history
… value
  • Loading branch information
Jean-Marc Collin committed Dec 10, 2023
1 parent 66a768d commit 955b795
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
16 changes: 8 additions & 8 deletions dist/versatile-thermostat-ui-card.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"disable_security_warning": "Disable battery warning",
"disable_buttons": "Disable plus/minus buttons",
"disable_power_infos": "Disable power infos",
"disable_auto_fan_infos": "Disable auto-fan infos",
"disable_name": "Disable name"
}
}
Expand Down Expand Up @@ -53,6 +54,7 @@
"fan_high": "High",
"fan_mute": "Mute",
"fan_turbo": "Turbo",
"fan_none": "None"
"fan_none": "None",
"change_message": "Double click to change preset"
}
}
4 changes: 3 additions & 1 deletion src/localize/languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"disable_security_warning": "Désactiver sécurité messages",
"disable_buttons": "Désactiver les boutons +/-",
"disable_power_infos": "Désactiver les infos de puissance",
"disable_auto_fan_infos": "Désactiver les infos auto-ventilation",
"disable_name": "Désactiver le nom"
}
}
Expand Down Expand Up @@ -51,6 +52,7 @@
"fan_high": "Haut",
"fan_mute": "Silence",
"fan_turbo": "Turbo",
"fan_none": "Aucun"
"fan_none": "Aucun",
"change_message": "Double clic pour changer le preset"
}
}
31 changes: 28 additions & 3 deletions src/versatile-thermostat-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1025,13 +1025,32 @@ export class VersatileThermostatUi extends LitElement implements LovelaceCard {
});
}

private last_target_temperature;

private _handlePreset(e: MouseEvent): void {
this.last_target_temperature = this.stateObj.attributes.temperature
this.hass!.callService("climate", "set_preset_mode", {
entity_id: this._config!.entity,
preset_mode: (e.currentTarget as any).preset,
});
}

private _recordPreset(e: MouseEvent): void {
this.hass!.callService("versatile_thermostat", "set_preset_temperature", {
entity_id: this._config!.entity,
preset: (e.currentTarget as any).preset,
temperature: this.last_target_temperature
});
}

private _handleClickOrDoubleClick(e: MouseEvent): void {
if (e.detail === 1) {
this._handlePreset(e);
} else if (e.detail === 2) {
this._recordPreset(e);
}
}

private _handleClickInfo(e: MouseEvent): void {
// TODO removes this or complete thie
this.hass!.callService("versatile_thermostat", "set_device_power", {
Expand Down Expand Up @@ -1123,14 +1142,21 @@ export class VersatileThermostatUi extends LitElement implements LovelaceCard {
}

private _renderPreset(preset: string, currentPreset: string): TemplateResult {
const localizePreset = this.hass!.localize(`component.climate.state._.${preset}`) || localize({ hass: this.hass, string: `extra_states.${preset}` });
const localizePreset =
( this.hass!.localize(`component.climate.state._.${preset}`) ||
localize({ hass: this.hass, string: `extra_states.${preset}` }))
+ "\n" + localize({ hass: this.hass, string: `extra_states.change_message` });

// title="${currentPreset === preset ? preset : ''}"

return html `
<div class="preset-label">
<ha-icon-button
title="${currentPreset === preset ? preset : ''}"
class=${classMap({ "selected-icon": currentPreset === preset })}
.preset=${preset}
@click=${this._handlePreset}
@click=${this._handleClickOrDoubleClick}
@dblclick=${this._handleClickOrDoubleClick}
tabindex="0"
.path=${modeIcons[preset]}
.label=${localizePreset}
Expand All @@ -1149,7 +1175,6 @@ export class VersatileThermostatUi extends LitElement implements LovelaceCard {
title="${localizeInfo}"
class=${info.class}
.name=${info.name}
@click=${this._handleClickInfo}
tabindex="0"
.path=${modeIcons[info.name]}
.label=${localizeInfo}
Expand Down

0 comments on commit 955b795

Please sign in to comment.