Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get temp back to fahr. #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,19 @@ function ZWayServerAccessory(name, devDesc, platform) {
this.log = platform.log;
}

function getFahr(vdev, field) {
if(vdev.metrics.scaleTitle == "°C")
return vdev.metrics[field];
else
return (vdev.metrics[field] - 32) * (5/9);
}

function setFahr(vdev, level) {
if(vdev.metrics.scaleTitle == "°C")
return level;
else
return level * (9/5) + 32;
}

ZWayServerAccessory.prototype = {

Expand Down Expand Up @@ -877,7 +890,7 @@ ZWayServerAccessory.prototype = {

if(cx instanceof Characteristic.CurrentTemperature){
cx.zway_getValueFromVDev = function(vdev){
return vdev.metrics.level;
return getFahr(vdev, "level")
};
cx.value = cx.zway_getValueFromVDev(vdev);
cx.on('get', function(callback, context){
Expand All @@ -888,33 +901,33 @@ ZWayServerAccessory.prototype = {
});
}.bind(this));
cx.setProps({
minValue: vdev.metrics && vdev.metrics.min !== undefined ? vdev.metrics.min : -40,
maxValue: vdev.metrics && vdev.metrics.max !== undefined ? vdev.metrics.max : 999
minValue: vdev.metrics && vdev.metrics.min !== undefined ? getFahr(vdev, "min") : -40,
maxValue: vdev.metrics && vdev.metrics.max !== undefined ? getFahr(vdev, "max") : 999
});
return cx;
}

if(cx instanceof Characteristic.TargetTemperature){
cx.zway_getValueFromVDev = function(vdev){
return vdev.metrics.level;
return getFahr(vdev, "level")
};
cx.value = cx.zway_getValueFromVDev(vdev);
cx.on('get', function(callback, context){
debug("Getting value for " + vdev.metrics.title + ", characteristic \"" + cx.displayName + "\"...");
this.getVDev(vdev).then(function(result){
debug("Got value: " + cx.zway_getValueFromVDev(result.data) + ", for " + vdev.metrics.title + ".");
console.log("Got value: " + cx.zway_getValueFromVDev(result.data) + ", for " + vdev.metrics.title + ".");
callback(false, cx.zway_getValueFromVDev(result.data));
});
}.bind(this));
cx.on('set', interlock(function(level, callback){
this.command(vdev, "exact", {level: parseInt(level, 10)}).then(function(result){
//debug("Got value: " + result.data.metrics.level + ", for " + vdev.metrics.title + ".");
this.command(vdev, "exact", {level: setFahr(vdev, parseInt(level, 10))}).then(function(result){
console.log("Got value: " + level + ", for " + vdev.metrics.title + ".");
callback();
});
}.bind(this)));
cx.setProps({
minValue: vdev.metrics && vdev.metrics.min !== undefined ? vdev.metrics.min : 5,
maxValue: vdev.metrics && vdev.metrics.max !== undefined ? vdev.metrics.max : 40
minValue: vdev.metrics && vdev.metrics.min !== undefined ? getFahr(vdev, "min") : -40,
maxValue: vdev.metrics && vdev.metrics.max !== undefined ? getFahr(vdev, "max") : 999
});
return cx;
}
Expand Down Expand Up @@ -960,7 +973,7 @@ ZWayServerAccessory.prototype = {
});
// Hmm... apparently if this is not setable, we can't add a thermostat change to a scene. So, make it writable but a no-op.
cx.on('set', interlock(function(newValue, callback){
debug("WARN: Set of TargetHeatingCoolingState not yet implemented, resetting to HEAT!")
//debug("WARN: Set of TargetHeatingCoolingState not yet implemented, resetting to HEAT!")
callback(undefined, Characteristic.TargetHeatingCoolingState.HEAT);
}.bind(this)));
return cx;
Expand Down