sdk: mixin events

This commit is contained in:
Koushik Dutta
2021-09-17 13:04:37 -07:00
parent a0c0c478fe
commit dd5d3e3c77
3 changed files with 11 additions and 5 deletions

3
sdk/index.d.ts vendored
View File

@@ -65,7 +65,8 @@ export class ScryptedDeviceBase implements DeviceState {
export class MixinDeviceBase<T> implements DeviceState {
constructor(mixinDevice: T, mixinDeviceInterfaces: ScryptedInterface[], mixinDeviceState: { [key: string]: any }, providerNativeId: string);
constructor(mixinDevice: T, mixinDeviceInterfaces: ScryptedInterface[], mixinDeviceState: { [key: string]: any }, mixinProviderNativeId: string);
mixinProviderNativeId: string;
mixinDevice: ScryptedDevice & T;
mixinDeviceInterfaces: ScryptedInterface[];
console: Console;

View File

@@ -40,17 +40,17 @@ class ScryptedDeviceBase {
}
class MixinDeviceBase {
constructor(mixinDevice, mixinDeviceInterfaces, mixinDeviceState, providerNativeId) {
constructor(mixinDevice, mixinDeviceInterfaces, mixinDeviceState, mixinProviderNativeId) {
this.mixinDevice = mixinDevice;
this.mixinDevice = mixinDevice;
this.mixinDeviceInterfaces = mixinDeviceInterfaces;
this._deviceState = mixinDeviceState;
this.providerNativeId = providerNativeId;
this.mixinProviderNativeId = mixinProviderNativeId;
}
get storage() {
if (!this._storage) {
this._storage = deviceManager.getMixinStorage(this.id, this.providerNativeId);
this._storage = deviceManager.getMixinStorage(this.id, this.mixinProviderNativeId);
}
return this._storage;
}

7
sdk/types.d.ts vendored
View File

@@ -709,9 +709,14 @@ export interface DeviceManager {
* @param id The id of the device being mixined.
* @param nativeId The nativeId of the MixinProvider.
*/
getMixinStorage(id: string, nativeId?: string): Storage;
getMixinStorage(id: string, nativeId: string): Storage;
/**
* Fire an event for a mixin provided by this plugin.
*/
onMixinEvent(id: string, nativeId: string, eventInterface: string, eventData: any): Promise<void>;
/**
* Get the per device Storage object.
*/
getDeviceStorage(nativeId: string): Storage;