Skip to content

Commit

Permalink
humidity: Add new htu21d sensor
Browse files Browse the repository at this point in the history
Note only humidity is used with this sensor also
measuring temperature,
maybe an other API will be needed to support both type.

Relate-to: rzr/generic-sensors-lite#13
Change-Id: I19a57898209ed6421cc760ae5a2ab3f4d8034379
Signed-off-by: Philippe Coval <[email protected]>
  • Loading branch information
rzr committed Jan 18, 2020
1 parent 83a5c8e commit a12b5bf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
20 changes: 20 additions & 0 deletions generic-sensors-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ const colorSensor = {
],
};

const humiditySensor = {
type: 'multiLevelSensor',
sensorType: 'humiditySensor',
name: 'Humidity Sensor',
properties: [
level(true),
on(),
],
};


const temperatureSensor = {
type: 'multiLevelSensor',
sensorType: 'temperatureSensor',
Expand All @@ -90,12 +101,14 @@ const temperatureSensor = {
const GENERICSENSORS_THINGS = [
ambientLightSensor,
colorSensor,
humiditySensor,
temperatureSensor,
];

const GENERICSENSORS_THINGS_PROTOTYPES = {
ambientLightSensor: ambientLightSensor,
colorSensor: colorSensor,
humiditySensor: humiditySensor,
temperatureSensor: temperatureSensor,
};

Expand Down Expand Up @@ -124,6 +137,8 @@ class GenericSensorsProperty extends Property {
sensor = this.device.sensors.ambientLight;
} else if (this.device.sensorType === 'colorSensor') {
sensor = this.device.sensors.color;
} else if (this.device.sensorType === 'humiditySensor') {
sensor = this.device.sensors.humidity;
}
return sensor;
}
Expand Down Expand Up @@ -154,6 +169,8 @@ class GenericSensorsProperty extends Property {
this.setCachedValue(this.device.sensors.ambientLight.illuminance);
} else if (this.device.sensorType == 'colorSensor') {
this.setCachedValue(this.device.sensors.color.color);
} else if (this.device.sensorType == 'humiditySensor') {
this.setCachedValue(this.device.sensors.humidity.level);
}
}
this.device.notifyPropertyChanged(this);
Expand All @@ -180,6 +197,9 @@ class GenericSensorsDevice extends Device {
} else if (config.sensorType === 'colorSensor') {
this.sensors.color =
new GenericSensors.Color({controller: this.sensorController});
} else if (config.sensorType === 'humiditySensor') {
this.sensors.humidity =
new GenericSensors.Humidity({controller: this.sensorController});
}

for (const prop
Expand Down
9 changes: 8 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
"sensorType": "colorSensor",
"type": "customSensor"
},
{
"name": "Humidity Sensor",
"sensorController": "htu21d",
"sensorType": "humiditySensor",
"type": "multiLevelSensor"
},
{
"name": "Temperature Sensor",
"sensorController": "bmp085",
Expand All @@ -52,6 +58,7 @@
"enum": [
"ambientLightSensor",
"colorSensor",
"humiditySensor",
"temperatureSensor"
],
"type": "string"
Expand Down Expand Up @@ -79,4 +86,4 @@
},
"short_name": "Gen Sensors",
"version": "0.0.10"
}
}
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
"sensorController": "tcs34725",
"name": "Color Sensor"
},
{
"type": "multiLevelSensor",
"sensorType": "humiditySensor",
"sensorController": "htu21d",
"name": "Humidity Sensor"
},
{
"type": "multiLevelSensor",
"sensorType": "temperatureSensor",
Expand Down Expand Up @@ -101,6 +107,7 @@
"enum": [
"ambientLightSensor",
"colorSensor",
"humiditySensor",
"temperatureSensor"
]
},
Expand Down

0 comments on commit a12b5bf

Please sign in to comment.