Skip to content

Commit

Permalink
fix(thermostat): correct handling of auto mode as per Homebridge spec
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbitt authored Jul 10, 2023
1 parent 19a60d8 commit b418ecb
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/accessories/thermostat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,34 @@ export class ThermostatAccessory {
const mode = this.toCurrentHeatingCoolingStateCharacteristic(
event.last_read_state as ThermostatMode
);
this.state.heating_cooling_state.current = mode;
let actualMode = mode;
if (mode === this.platform.Characteristic.TargetHeatingCoolingState.AUTO) {
// Determine if heating or cooling based on target and current temperature
if (
this.state.target_temperature.current <
this.state.current_temperature.current
) {
actualMode = this.platform.Characteristic.CurrentHeatingCoolingState.COOL;
} else if (
this.state.target_temperature.current >
this.state.current_temperature.current
) {
actualMode = this.platform.Characteristic.CurrentHeatingCoolingState.HEAT;
} else {
actualMode = this.platform.Characteristic.CurrentHeatingCoolingState.OFF;
}
}
this.state.heating_cooling_state.current = actualMode;
this.state.heating_cooling_state.target = mode;
this.thermostatService.updateCharacteristic(
this.platform.Characteristic.CurrentHeatingCoolingState,
mode
actualMode
);
this.thermostatService.updateCharacteristic(
this.platform.Characteristic.TargetHeatingCoolingState,
mode
);
break;
case 'cooling_setpoint':
const coolingSetpoint = this.toTemperatureCharacteristic(
Number(event.last_read_state)
);
this.state.cooling_threshold_temperature.current = coolingSetpoint;
this.state.cooling_threshold_temperature.target = coolingSetpoint;
this.thermostatService.updateCharacteristic(
this.platform.Characteristic.CoolingThresholdTemperature,
coolingSetpoint
);
break;
case 'heating_setpoint':
const heatingSetpoint = this.toTemperatureCharacteristic(
Number(event.last_read_state)
Expand Down Expand Up @@ -256,8 +262,6 @@ export class ThermostatAccessory {
return this.platform.Characteristic.CurrentHeatingCoolingState.COOL;
case 'heat':
return this.platform.Characteristic.CurrentHeatingCoolingState.HEAT;
case 'auto':
return this.platform.Characteristic.TargetHeatingCoolingState.AUTO;
default:
return this.platform.Characteristic.TargetHeatingCoolingState.OFF;
}
Expand Down

0 comments on commit b418ecb

Please sign in to comment.