homekit: add more supported sensors

This commit is contained in:
Koushik Dutta
2022-01-27 19:12:59 -08:00
parent f75fbe634d
commit 227ed1de75
3 changed files with 10 additions and 8 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/homekit",
"version": "0.0.173",
"version": "0.0.174",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/homekit",
"version": "0.0.173",
"version": "0.0.174",
"dependencies": {
"hap-nodejs": "file:../../external/HAP-NodeJS",
"lodash": "^4.17.21",

View File

@@ -40,5 +40,5 @@
"@types/qrcode": "^1.4.1",
"@types/url-parse": "^1.4.3"
},
"version": "0.0.173"
"version": "0.0.174"
}

View File

@@ -1,5 +1,5 @@
import { MotionSensor, BinarySensor, ScryptedDevice, ScryptedDeviceType, ScryptedInterface, Thermometer } from '@scrypted/sdk'
import { MotionSensor, BinarySensor, ScryptedDevice, ScryptedDeviceType, ScryptedInterface, Thermometer, HumiditySensor } from '@scrypted/sdk'
import { addSupportedType, bindCharacteristic, DummyDevice } from '../common'
import { Characteristic, Service } from '../hap';
import { makeAccessory } from './common';
@@ -9,20 +9,17 @@ addSupportedType({
probe(device: DummyDevice) {
return device.interfaces.includes(ScryptedInterface.Thermometer) || device.interfaces.includes(ScryptedInterface.BinarySensor) || device.interfaces.includes(ScryptedInterface.MotionSensor);
},
getAccessory: async (device: ScryptedDevice & BinarySensor & MotionSensor & Thermometer) => {
getAccessory: async (device: ScryptedDevice & BinarySensor & MotionSensor & Thermometer & HumiditySensor) => {
const accessory = makeAccessory(device);
if (device.interfaces.includes(ScryptedInterface.BinarySensor)) {
const contactSensorService = accessory.addService(Service.ContactSensor, device.name);
contactSensorService.getCharacteristic(Characteristic.ContactSensorState)
bindCharacteristic(device, ScryptedInterface.BinarySensor, contactSensorService, Characteristic.ContactSensorState,
() => !!device.binaryState);
}
if (device.interfaces.includes(ScryptedInterface.MotionSensor)) {
const motionSensorService = accessory.addService(Service.MotionSensor, device.name);
bindCharacteristic(device, ScryptedInterface.MotionSensor, motionSensorService, Characteristic.MotionDetected,
() => !!device.motionDetected, true);
}
@@ -31,7 +28,12 @@ addSupportedType({
const service = accessory.addService(Service.TemperatureSensor, device.name);
bindCharacteristic(device, ScryptedInterface.Thermometer, service, Characteristic.CurrentTemperature,
() => device.temperature || 0);
}
if (device.interfaces.includes(ScryptedInterface.HumiditySensor)) {
const service = accessory.addService(Service.HumiditySensor, device.name);
bindCharacteristic(device, ScryptedInterface.HumiditySensor, service, Characteristic.CurrentRelativeHumidity,
() => device.humidity || 0);
}
// todo: more sensors.