Files
scrypted/plugins/homekit/src/common.ts
Koushik Dutta 3fede89f3d remove cruft
2021-09-08 13:19:52 -07:00

31 lines
981 B
TypeScript

import { EventListenerRegister, ScryptedDevice, ScryptedDeviceType, ScryptedInterface } from '@scrypted/sdk';
import { Accessory, Service } from './hap';
export interface DummyDevice {
interfaces?: string[];
type?: ScryptedDeviceType;
}
interface SupportedType {
type: ScryptedDeviceType;
probe(device: DummyDevice): boolean;
getAccessory: (device: ScryptedDevice & any) => Accessory;
noBridge?: boolean;
}
export const supportedTypes: { [type: string]: SupportedType } = {};
export function addSupportedType(type: SupportedType) {
supportedTypes[type.type] = type;
}
export function bindCharacteristic(device: ScryptedDevice, event: ScryptedInterface, service: Service, characteristic: any, map: () => any, refresh?: boolean): EventListenerRegister {
service.updateCharacteristic(characteristic, map());
return device.listen({
event,
watch: !refresh,
}, () => service.updateCharacteristic(characteristic, map()));
}