Skip to content

Commit

Permalink
Fix minimum/maximum values. (#264)
Browse files Browse the repository at this point in the history
Fixes #261
  • Loading branch information
mrstegeman authored Dec 4, 2020
1 parent 686db9b commit 13a585e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@
}
},
"short_name": "Zigbee",
"version": "0.15.1"
"version": "0.15.2"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zigbee-adapter",
"version": "0.15.1",
"version": "0.15.2",
"description": "Zigbee adapter plugin for WebThings Gateway",
"author": "WebThingsIO",
"main": "index.js",
Expand Down
28 changes: 14 additions & 14 deletions zb-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,15 @@ class ZigbeeProperty extends Property {

// We set the min/max here so that updated values get sent to the
// gateway when we do the propertyChanged notification.
if (!this.hasOwnProperty('maximum')) {
if (typeof this.maximum !== 'number') {
const minColorTempProperty = this.device.findProperty('_minTemperature');
if (minColorTempProperty && minColorTempProperty.value) {
this.minimumMireds = minColorTempProperty.value; // mireds
this.maximum = Math.trunc(1000000 / this.minimumMireds);
thingDescriptionUpdated = true;
}
}
if (!this.hasOwnProperty('minimum')) {
if (typeof this.minimum !== 'number') {
const maxColorTempProperty = this.device.findProperty('_maxTemperature');
if (maxColorTempProperty && maxColorTempProperty.value) {
this.maximumMireds = maxColorTempProperty.value; // mireds
Expand Down Expand Up @@ -489,13 +489,13 @@ class ZigbeeProperty extends Property {
* Parses the temperature attribute as a property.
*/
parseIlluminanceMeasurementAttr(attrEntry) {
if (!this.hasOwnProperty('minimum')) {
if (typeof this.minimum !== 'number') {
const minProperty = this.device.findProperty('_minIlluminance');
if (minProperty && minProperty.value) {
this.minimum = this.attrToIlluminance(minProperty.value);
}
}
if (!this.hasOwnProperty('maximum')) {
if (typeof this.maximum !== 'number') {
const maxProperty = this.device.findProperty('_maxIlluminance');
if (maxProperty && maxProperty.value) {
this.maximum = this.attrToIlluminance(maxProperty.value);
Expand All @@ -506,10 +506,10 @@ class ZigbeeProperty extends Property {
// A measuredValue of 0 is interpreted as "too low to measure".
if (measuredValue > 0) {
illuminance = Math.pow(10, (measuredValue - 1) / 10000);
if (this.hasOwnProperty('minimum')) {
if (typeof this.minimum === 'number') {
illuminance = Math.max(this.minimum, illuminance);
}
if (this.hasOwnProperty('maximum')) {
if (typeof this.maximum === 'number') {
illuminance = Math.min(this.maximum, illuminance);
}
}
Expand Down Expand Up @@ -546,24 +546,24 @@ class ZigbeeProperty extends Property {
* Parses the temperature attribute as a property.
*/
parseTemperatureMeasurementAttr(attrEntry) {
if (!this.hasOwnProperty('minimum')) {
if (typeof this.minimum !== 'number') {
const minTempProperty = this.device.findProperty('_minTemp');
if (minTempProperty && minTempProperty.value) {
this.minimum = this.attrToTemperature(minTempProperty.value);
}
}
if (!this.hasOwnProperty('maximum')) {
if (typeof this.maximum !== 'number') {
const maxTempProperty = this.device.findProperty('_maxTemp');
if (maxTempProperty && maxTempProperty.value) {
this.maximum = this.attrToTemperature(maxTempProperty.value);
}
}
const measuredValue = attrEntry.attrData;
let temperature = this.attrToTemperature(measuredValue);
if (this.hasOwnProperty('minimum')) {
if (typeof this.minimum === 'number') {
temperature = Math.max(this.minimum, temperature);
}
if (this.hasOwnProperty('maximum')) {
if (typeof this.maximum === 'number') {
temperature = Math.min(this.maximum, temperature);
}
return [temperature, `${temperature.toFixed(1)} (${measuredValue})`];
Expand Down Expand Up @@ -939,14 +939,14 @@ class ZigbeeProperty extends Property {
// i.e. 6500K corresponds to a colorTempPhysicalMin = 153
// 2700L corresponds to a colorTempPhysicalMax = 370

if (!this.hasOwnProperty('maximum')) {
if (typeof this.maximum !== 'number') {
const minColorTempProperty = this.device.findProperty('_minTemperature');
if (minColorTempProperty && minColorTempProperty.value) {
this.minimumMireds = minColorTempProperty.value; // mireds
this.maximum = Math.trunc(1000000 / this.minimumMireds);
}
}
if (!this.hasOwnProperty('minimum')) {
if (typeof this.minimum !== 'number') {
const maxColorTempProperty = this.device.findProperty('_maxTemperature');
if (maxColorTempProperty && maxColorTempProperty.value) {
this.maximumMireds = maxColorTempProperty.value; // mireds
Expand Down Expand Up @@ -1187,7 +1187,7 @@ class ZigbeeProperty extends Property {
}

setMinimum(minimum) {
if (this.hasOwnProperty('minimum') && this.minimum == minimum) {
if (typeof this.minimum === 'number' && this.minimum == minimum) {
// No change detected - ignore
return;
}
Expand All @@ -1196,7 +1196,7 @@ class ZigbeeProperty extends Property {
}

setMaximum(maximum) {
if (this.hasOwnProperty('maximum') && this.maximum == maximum) {
if (typeof this.maximum === 'number' && this.maximum == maximum) {
// No change detected - ignore
return;
}
Expand Down

0 comments on commit 13a585e

Please sign in to comment.