From ffed4a03af4aeec35a5412bcfe29f73a274db475 Mon Sep 17 00:00:00 2001 From: Kevin Merritt Date: Sat, 14 May 2022 13:13:54 -0400 Subject: [PATCH] homekit: support IntrusionSensor as ContactSensor service (#244) --- plugins/homekit/src/types/sensor.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/homekit/src/types/sensor.ts b/plugins/homekit/src/types/sensor.ts index c0f76533f..d36c29bb2 100644 --- a/plugins/homekit/src/types/sensor.ts +++ b/plugins/homekit/src/types/sensor.ts @@ -1,4 +1,4 @@ -import { AmbientLightSensor, AudioSensor, BinarySensor, FloodSensor, HumiditySensor, MotionSensor, OccupancySensor, PM25Sensor, AirQualitySensor, ScryptedDevice, ScryptedDeviceType, ScryptedInterface, Thermometer, VOCSensor, AirQuality, EntrySensor } from '@scrypted/sdk'; +import { AmbientLightSensor, AudioSensor, BinarySensor, FloodSensor, HumiditySensor, MotionSensor, OccupancySensor, PM25Sensor, AirQualitySensor, ScryptedDevice, ScryptedDeviceType, ScryptedInterface, Thermometer, VOCSensor, AirQuality, EntrySensor, IntrusionSensor } from '@scrypted/sdk'; import { addSupportedType, bindCharacteristic, DummyDevice, HomeKitSession } from '../common'; import { Characteristic, Service } from '../hap'; import { makeAccessory } from './common'; @@ -33,6 +33,7 @@ const supportedSensors: string[] = [ ScryptedInterface.PM25Sensor, ScryptedInterface.VOCSensor, ScryptedInterface.EntrySensor, + ScryptedInterface.IntrusionSensor, ]; addSupportedType({ @@ -44,7 +45,7 @@ addSupportedType({ } return false; }, - getAccessory: async (device: ScryptedDevice & OccupancySensor & AmbientLightSensor & AmbientLightSensor & AudioSensor & BinarySensor & MotionSensor & Thermometer & HumiditySensor & FloodSensor & AirQualitySensor & PM25Sensor & VOCSensor & EntrySensor, homekitSession: HomeKitSession) => { + getAccessory: async (device: ScryptedDevice & OccupancySensor & AmbientLightSensor & AmbientLightSensor & AudioSensor & BinarySensor & MotionSensor & Thermometer & HumiditySensor & FloodSensor & AirQualitySensor & PM25Sensor & VOCSensor & EntrySensor & IntrusionSensor, homekitSession: HomeKitSession) => { const accessory = makeAccessory(device, homekitSession); if (device.interfaces.includes(ScryptedInterface.BinarySensor)) { @@ -55,6 +56,10 @@ addSupportedType({ const service = accessory.addService(Service.ContactSensor, device.name); bindCharacteristic(device, ScryptedInterface.EntrySensor, service, Characteristic.ContactSensorState, () => !!device.entryOpen); + } else if (device.interfaces.includes(ScryptedInterface.IntrusionSensor)) { + const service = accessory.addService(Service.ContactSensor, device.name); + bindCharacteristic(device, ScryptedInterface.IntrusionSensor, service, Characteristic.ContactSensorState, + () => !!device.intrusionDetected); } if (device.interfaces.includes(ScryptedInterface.OccupancySensor)) {