Skip to content

Commit

Permalink
do not call services if not needed (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Oct 17, 2021
1 parent b7d7f94 commit daf2885
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions climate-mode-entity-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@

renderMode(mode) {
const isActive =
(!mode.preset_mode || mode.preset_mode === this.state.preset_mode) &&
(!mode.hvac_mode || mode.hvac_mode === this.state.hvac_mode) &&
(!mode.fan_mode || mode.fan_mode === this.state.fan_mode) &&
(!mode.swing_mode || mode.swing_mode === this.state.swing_mode) &&
(!mode.preset_mode == null ||
mode.preset_mode === this.state.preset_mode) &&
(!mode.hvac_mode == null || mode.hvac_mode === this.state.hvac_mode) &&
(!mode.fan_mode == null || mode.fan_mode === this.state.fan_mode) &&
(!mode.swing_mode == null ||
mode.swing_mode === this.state.swing_mode) &&
(mode.temperature == null ||
mode.temperature === this.state.temperature);

Expand All @@ -89,35 +91,41 @@
}

setMode(mode) {
if (mode.hvac_mode) {
if (mode.hvac_mode != null && mode.hvac_mode != this.state.hvac_mode) {
this._hass.callService("climate", "set_hvac_mode", {
entity_id: this._config.entity,
hvac_mode: mode.hvac_mode,
});
}

if (mode.preset_mode) {
if (
mode.preset_mode != null &&
mode.preset_mode != this.state.preset_mode
) {
this._hass.callService("climate", "set_preset_mode", {
entity_id: this._config.entity,
preset_mode: mode.preset_mode,
});
}

if (mode.fan_mode) {
if (mode.fan_mode != null && mode.fan_mode != this.state.fan_mode) {
this._hass.callService("climate", "set_fan_mode", {
entity_id: this._config.entity,
fan_mode: mode.fan_mode,
});
}

if (mode.swing_mode) {
if (mode.swing_mode != null && mode.swing_mode != this.state.swing_mode) {
this._hass.callService("climate", "set_swing_mode", {
entity_id: this._config.entity,
swing_mode: mode.swing_mode,
});
}

if (mode.temperature != null) {
if (
mode.temperature != null &&
mode.temperature != this.state.temperature
) {
this._hass.callService("climate", "set_temperature", {
entity_id: this._config.entity,
temperature: mode.temperature,
Expand Down

0 comments on commit daf2885

Please sign in to comment.