import { ScryptedNativeId , ScryptedDevice , Device , DeviceManifest , EventDetails , EventListenerOptions , EventListenerRegister , ScryptedInterfaceProperty , MediaObject , SystemDeviceState , MediaManager , HttpRequest } from '@scrypted/sdk/types' ; export interface PluginLogger { log ( level , message ) : Promise < void > ; clear ( ) : Promise < void > ; clearAlert ( message ) : Promise < void > ; clearAlerts ( ) : Promise < void > ; } export interface PluginAPI { setState ( nativeId , key , value ) : Promise < void > ; onDevicesChanged ( deviceManifest ) : Promise < void > ; onDeviceDiscovered ( device ) : Promise < string > ; onDeviceEvent ( nativeId , eventInterface , eventData ? ) : Promise < void > ; onMixinEvent ( id , nativeId , eventInterface , eventData ? ) : Promise < void > ; onDeviceRemoved ( nativeId ) : Promise < void > ; setStorage ( nativeId , storage ) : Promise < void > ; getDeviceById ( id ) : Promise < ScryptedDevice > ; setDeviceProperty ( id , property , value ) : Promise < void > ; removeDevice ( id ) : Promise < void > ; listen ( EventListener ) : Promise < EventListenerRegister > ; listenDevice ( id , event , callback ) : Promise < EventListenerRegister > ; ioClose ( id ) : Promise < void > ; ioSend ( id , message ) : Promise < void > ; deliverPush ( endpoint , request ) : Promise < void > ; getLogger ( nativeId ) : Promise < PluginLogger > ; getComponent ( id ) : Promise < any > ; getMediaManager ( ) : Promise < MediaManager > ; requestRestart ( ) : Promise < void > ; } class EventListenerRegisterProxy implements EventListenerRegister { __proxy_oneway_methods = [ 'removeListener' , ] ; removeListener ( ) { this . listeners . delete ( this ) ; this . listener . removeListener ( ) ; } constructor ( public listener , public listeners ) { this . listeners . add ( this ) ; } } export class PluginAPIManagedListeners { listeners = new Set < EventListenerRegister > ( ) ; manageListener ( listener ) { return new EventListenerRegisterProxy ( listener , this . listeners ) ; } removeListeners ( ) { for ( const l of [ ... this . listeners ] ) { l . removeListener ( ) ; } this . listeners . clear ( ) ; } } export class PluginAPIProxy extends PluginAPIManagedListeners implements PluginAPI { constructor ( public api , public mediaManager ? ) { super ( ) ; } setState ( nativeId , key , value ) { return this . api . setState ( nativeId , key , value ) ; } onDevicesChanged ( deviceManifest ) { return this . api . onDevicesChanged ( deviceManifest ) ; } onDeviceDiscovered ( device ) { return this . api . onDeviceDiscovered ( device ) ; } onDeviceEvent ( nativeId , eventInterface , eventData ? ) { return this . api . onDeviceEvent ( nativeId , eventInterface , eventData ) ; } onMixinEvent ( id , nativeId , eventInterface , eventData ? ) { return this . api . onMixinEvent ( nativeId , eventInterface , eventData ) ; } onDeviceRemoved ( nativeId ) { return this . api . onDeviceRemoved ( nativeId ) ; } setStorage ( nativeId , storage ) { return this . api . setStorage ( nativeId , storage ) ; } getDeviceById ( id ) { return this . api . getDeviceById ( id ) ; } setDeviceProperty ( id , property , value ) { return this . api . setDeviceProperty ( id , property , value ) ; } removeDevice ( id ) { return this . api . removeDevice ( id ) ; } async listen ( callback ) { return this . manageListener ( await this . api . listen ( callback ) ) ; } async listenDevice ( id , event , callback ) { return this . manageListener ( await this . api . listenDevice ( id , event , callback ) ) ; } ioClose ( id ) { return this . api . ioClose ( id ) ; } ioSend ( id , message ) { return this . api . ioSend ( id , message ) ; } deliverPush ( endpoint , request ) { return this . api . deliverPush ( endpoint , request ) ; } getLogger ( nativeId ) { return this . api . getLogger ( nativeId ) ; } getComponent ( id ) { return this . api . getComponent ( id ) ; } async getMediaManager ( ) { return this . mediaManager ; } async requestRestart ( ) { return this . api . requestRestart ( ) ; } } export interface PluginRemoteLoadZipOptions { /**
     * The filename to load the script as. Use for debugger source mapping.
     */ filename ? : string ; /**
     * The path that the zip is currently unzipped at on the server. May not
     * exist on the "remote", if it is not the same machine.
     */ unzippedPath ? : string ; } export interface PluginRemote { loadZip ( packageJson , zipData , options ? ) : Promise < any > ; setSystemState ( state ) : Promise < void > ; setNativeId ( nativeId , id , storage ) : Promise < void > ; updateDeviceState ( id , state ) : Promise < void > ; notify ( id , eventTime , eventInterface , property , value , changed ? ) : Promise < void > ; ioEvent ( id , event , message ? ) : Promise < void > ; createDeviceState ( id , setState ) : Promise < any > ; getServicePort ( name , ... args ) : Promise < number > ; } export interface MediaObjectRemote extends MediaObject { getData ( ) : Promise < Buffer | string > ; }