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

Refactored the 'hasHumiditySensor' function to account for all currently supported tags and updated sensors to expose 'batteryRemaining' property #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions lib/sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ const sensorPropertiesMap = {
},
'signal': {
reading: ["signaldBm", xforms.noop]
},
'batteryremaining': {
reading: ["batteryRemaining", xforms.noop]
}
};
/* eslint-enable no-invalid-this */
Expand Down
24 changes: 19 additions & 5 deletions lib/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ WirelessTag.prototype.hasMotionSensor = function() {
};
/** Whether the tag has a light sensor. */
WirelessTag.prototype.hasLightSensor = function() {
return (this.tagType === 26);
return (this.tagType === 26 || this.tagType === 107);
};
/** Whether the tag has a moisture sensor. */
WirelessTag.prototype.hasMoistureSensor = function() {
Expand Down Expand Up @@ -244,9 +244,15 @@ WirelessTag.prototype.hasEventSensor = function() {
};
/** Whether the tag has a humidity sensor. */
WirelessTag.prototype.hasHumiditySensor = function() {
if (this.isOutdoorTag()) return false;
if ((this.rev & 0x0F) === 0x0D && this.rev >= 0x4D) return false;
return this.canHighPrecTemp();
return (this.tagType === 13
|| this.tagType === 21
|| this.tagType === 26
|| this.tagType === 52
|| this.tagType === 72
|| this.tagType === 102
|| this.tagType === 106
|| this.tagType === 107
);
};
/** Whether the tag has a temperature sensor. */
WirelessTag.prototype.hasTempSensor = function() {
Expand Down Expand Up @@ -296,6 +302,13 @@ WirelessTag.prototype.hasBatterySensor = function() {
WirelessTag.prototype.hasSignalSensor = function() {
return this.isPhysicalTag();
};
/**
* Whether the tag reports the batteryRemaining. (All
* non-virtual tags do.)
*/
WirelessTag.prototype.hasBatteryRemainingSensor = function() {
return this.isPhysicalTag();
};
/** Whether the tag's motion sensor is an accelerometer. */
WirelessTag.prototype.hasAccelerometer = function() {
return this.hasMotionSensor() && ((this.rev & 0x0F) === 0x0A);
Expand Down Expand Up @@ -331,6 +344,7 @@ WirelessTag.prototype.canHighPrecTemp = function() {
|| this.tagType === 26 // ambient light
|| this.tagType === 72 // PIR
|| this.tagType === 42 // outdoor tag w/ probe
|| this.tagType === 106 // precision ext-power sensor
|| this.isKumostat()
;
};
Expand Down Expand Up @@ -389,7 +403,7 @@ WirelessTag.prototype.isWeMo = function() {
WirelessTag.prototype.isWeMoLED = function() {
return (this.isWeMo() && (this.data.cap > 0));
};
/** Whether the tab object represents a Dropcam camera. */
/** Whether the tag object represents a Dropcam camera. */
WirelessTag.prototype.isCamera = function() {
return (this.tagType === 92);
};
Expand Down