Skip to content

Commit

Permalink
fixup! Add Aqara TVOC Sensor Support with history
Browse files Browse the repository at this point in the history
  • Loading branch information
sieren committed Sep 11, 2021
1 parent 251c09f commit c07a96e
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/HueSensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,7 @@ function HueSensor (accessory, id, obj) {
this.history.entry.temp = 0
this.history.entry.humidity = 0
this.history.entry.voc = 0
break
default:
break
}
Expand Down Expand Up @@ -1801,6 +1802,7 @@ HueSensor.prototype.checkState = function (state, event) {
switch (key) {
case 'airquality':
this.checkAirQuality(state.airquality)
break
case 'angle':
break
case 'battery':
Expand Down Expand Up @@ -2047,8 +2049,9 @@ HueSensor.prototype.addEntry = function (changed) {
break
case 'room2':
{
let key = this.type.key === 'airqualityppb' ? 'voc' :
(this.type.key === 'temperature' ? 'temp' : this.type.key)
const key = this.type.key === 'airqualityppb'
? 'voc'
: (this.type.key === 'temperature' ? 'temp' : this.type.key)
this.history.entry[key] = this.hk[this.type.key]
if (changed || this.type.key !== this.history.resource.type.key) {
return
Expand Down Expand Up @@ -2407,17 +2410,18 @@ HueSensor.prototype.checkAirQuality = function (airquality) {
)
this.obj.state.airquality = airquality
}
let qualities = {
'excellent': Characteristic.AirQuality.EXCELLENT,
'good': Characteristic.AirQuality.GOOD,
'moderate': Characteristic.AirQuality.FAIR,
'poor': Characteristic.AirQuality.INFERIOR,
'unhealthy': Characteristic.AirQuality.POOR
const qualities = {
excellent: Characteristic.AirQuality.EXCELLENT,
good: Characteristic.AirQuality.GOOD,
moderate: Characteristic.AirQuality.FAIR,
poor: Characteristic.AirQuality.INFERIOR,
unhealthy: Characteristic.AirQuality.POOR
}

let hkAirQuality = qualities[airquality]
if (!hkAirQuality)
if (!hkAirQuality) {
hkAirQuality = Characteristic.AirQuality.UNKNOWN
}

if (this.hk.airquality !== hkAirQuality) {
if (this.hk.airquality !== undefined) {
Expand Down

0 comments on commit c07a96e

Please sign in to comment.