mirror of
https://github.com/koush/scrypted.git
synced 2026-02-20 05:12:47 +00:00
31 lines
981 B
TypeScript
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()));
|
|
}
|