-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSensorMultiLevelDriver.ts
64 lines (57 loc) · 1.96 KB
/
SensorMultiLevelDriver.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import BoundValueStream from '../../Streams/BoundValueStream'
import fahrenheitToCelsiusTransformer from '../../Values/Transformers/fahrenheitToCelsiusTransformer'
import ManagedDriver from './ManagedDriver'
import { Value } from 'openzwave-shared'
export default class SensorMultiLevelDriver extends ManagedDriver {
addValue(index: number, value: Value) {
switch (index) {
case 1:
this.registerTemperature(index, value)
break
case 3:
this.registerLuminance(index, value)
break
case 5:
this.registerHumidity(index, value)
break
}
}
registerTemperature(index: number, value: Value) {
const { Service, Characteristic } = this.hap
const service = this.accessory.getService(Service.TemperatureSensor)
const valueStream = new BoundValueStream(value, this.valueObservables, this.log)
const unit = (value.units || 'celsius')
.toString()
.toUpperCase()
.substring(0, 1)
this.registerCharacteristic(index, value, {
service,
valueStream,
characteristic: Characteristic.CurrentTemperature,
options: {
// Assumes only units are C/F… No ones reporting Kelvin, right??
transformer: unit !== 'C' ? fahrenheitToCelsiusTransformer() : undefined,
},
})
}
registerLuminance(index: number, value: Value) {
const { Service, Characteristic } = this.hap
const service = this.accessory.getService(Service.LightSensor)
const valueStream = new BoundValueStream(value, this.valueObservables, this.log)
this.registerCharacteristic(index, value, {
service,
valueStream,
characteristic: Characteristic.CurrentAmbientLightLevel,
})
}
registerHumidity(index: number, value: Value) {
const { Service, Characteristic } = this.hap
const service = this.accessory.getService(Service.HumiditySensor)
const valueStream = new BoundValueStream(value, this.valueObservables, this.log)
this.registerCharacteristic(index, value, {
service,
valueStream,
characteristic: Characteristic.CurrentRelativeHumidity,
})
}
}