Skip to content

Commit

Permalink
Fix for thermostat units
Browse files Browse the repository at this point in the history
  • Loading branch information
kuestess committed Sep 26, 2022
1 parent 86410f9 commit 68bba83
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.
## 0.5.4-1
- [FIXED] Fix for temperature units
## 0.5.4
- [NEW] Initial support for thermostat (#267)
## 0.5.3
- [FIXED] Fix for fanlinc issue (#278)
## 0.5.1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": false,
"displayName": "InsteonLocal",
"name": "homebridge-platform-insteonlocal",
"version": "0.5.4",
"version": "0.5.4-1",
"description": "Insteon platform plugin with local control for homebridge: https://github.com/nfarina/homebridge",
"license": "ISC",
"repository": {
Expand Down
49 changes: 38 additions & 11 deletions src/InsteonLocalAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { InsteonLocalPlatform } from './InsteonLocalPlatform';
import moment, { Moment } from 'moment';
import util from 'util';
import _ from 'underscore';
import insteonUtils from 'home-controller/lib/Insteon/utils';
const convertTemp = insteonUtils.convertTemp;

export class InsteonLocalAccessory {
service: Service;
Expand Down Expand Up @@ -146,7 +148,7 @@ export class InsteonLocalAccessory {
}

if (this.deviceType == 'thermostat') {
this.tempUnits = this.device.tempUnits;
//this.tempUnits = this.device.tempUnits; //Not currently used - determined from thermostat
}

if(this.refreshInterval > 0){
Expand Down Expand Up @@ -1932,17 +1934,29 @@ export class InsteonLocalAccessory {
}
//get current temperature
if(status.temperature){
this.service.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(status.temperature);
this.currentTemp = status.temperature;
if(status.unit == 'C'){
this.currentTemp = status.temperature;
} else {
this.currentTemp = convertTemp('F', 'C', status.temperature);
}
this.service.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(this.currentTemp);
}
//get target temperature
if(status.setpoints){
if(this.mode == 'cool'){
this.service.getCharacteristic(this.platform.Characteristic.TargetTemperature).updateValue(status.setpoints.cool);
this.targetTemp = status.setpoints.cool;
if(status.unit == 'C'){
this.targetTemp = status.setpoints.cool;
} else {
this.targetTemp = convertTemp('F', 'C', status.setpoints.cool);
}
this.service.getCharacteristic(this.platform.Characteristic.TargetTemperature).updateValue(this.targetTemp);
} else if(this.mode == 'heat'){
this.service.getCharacteristic(this.platform.Characteristic.TargetTemperature).updateValue(status.setpoints.heat);
this.targetTemp = status.setpoints.heat;
if(status.unit == 'C'){
this.targetTemp = status.setpoints.heat;
} else {
this.targetTemp = convertTemp('F', 'C', status.setpoints.heat);
}
this.service.getCharacteristic(this.platform.Characteristic.TargetTemperature).updateValue(this.targetTemp);
}
}
});
Expand All @@ -1954,13 +1968,21 @@ export class InsteonLocalAccessory {
return;
}

let theTemp;

this.log('Setting ' + this.name + ' temperature to ' + temp);

this.platform.checkHubConnection();
this.lastUpdate = moment();

if(this.unit == 'F'){
theTemp = convertTemp('C', 'F', temp);
} else {
theTemp = temp;
}

if(this.mode == 'cool'){
this.thermostat.coolTemp(temp, (response)=>{
this.thermostat.coolTemp(theTemp, (response)=>{
if(!response || typeof(response) === 'undefined'){
return new Error('Thermostat did not return status');
}
Expand All @@ -1969,7 +1991,7 @@ export class InsteonLocalAccessory {
this.targetTemp = temp;
});
} else if(this.mode == 'heat'){
this.thermostat.heatTemp(temp, (response)=>{
this.thermostat.heatTemp(theTemp, (response)=>{
if(!response || typeof(response) === 'undefined'){
return new Error('Thermostat did not return status');
}
Expand All @@ -1996,8 +2018,13 @@ export class InsteonLocalAccessory {
return new Error('Thermostat did not return current temp');
}

this.service.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(temp);
this.currentTemp = temp;
if(this.unit == 'C'){
this.currentTemp = temp;
} else {
this.currentTemp = convertTemp('F', 'C', temp);
}

this.service.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(this.currentTemp);
});


Expand Down

0 comments on commit 68bba83

Please sign in to comment.