mirror of
https://github.com/koush/scrypted.git
synced 2026-02-09 08:42:19 +00:00
sync on device change
This commit is contained in:
4
plugins/google-home/package-lock.json
generated
4
plugins/google-home/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/google-home",
|
||||
"version": "0.0.12",
|
||||
"version": "0.0.13",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/google-home",
|
||||
"version": "0.0.12",
|
||||
"version": "0.0.13",
|
||||
"dependencies": {
|
||||
"actions-on-google": "^2.13.0",
|
||||
"axios": "^0.21.1",
|
||||
|
||||
@@ -35,5 +35,5 @@
|
||||
"@types/mdns": "^0.0.34",
|
||||
"@types/url-parse": "^1.4.3"
|
||||
},
|
||||
"version": "0.0.12"
|
||||
"version": "0.0.13"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { EngineIOHandler, HttpRequest, HttpRequestHandler, HttpResponse, MixinDeviceBase, MixinProvider, Refresh, RTCAVMessage, ScryptedDevice, ScryptedDeviceBase, ScryptedDeviceType, ScryptedInterface, ScryptedMimeTypes } from '@scrypted/sdk';
|
||||
import { EngineIOHandler, HttpRequest, HttpRequestHandler, HttpResponse, MixinDeviceBase, MixinProvider, Refresh, RTCAVMessage, ScryptedDevice, ScryptedDeviceBase, ScryptedDeviceType, ScryptedInterface, ScryptedInterfaceProperty, ScryptedMimeTypes } from '@scrypted/sdk';
|
||||
import sdk from '@scrypted/sdk';
|
||||
import type { SmartHomeV1DisconnectRequest, SmartHomeV1DisconnectResponse, SmartHomeV1ExecuteRequest, SmartHomeV1ExecuteResponse, SmartHomeV1ExecuteResponseCommands, SmartHomeV1QueryRequest, SmartHomeV1QueryResponse, SmartHomeV1ReportStateRequest, SmartHomeV1SyncRequest, SmartHomeV1SyncResponse } from 'actions-on-google/dist/service/smarthome/api/v1';
|
||||
import { smarthome } from 'actions-on-google/dist/service/smarthome';
|
||||
@@ -44,7 +44,10 @@ class GoogleHome extends ScryptedDeviceBase implements HttpRequestHandler, Engin
|
||||
});
|
||||
reportQueue = new Set<string>();
|
||||
reportStateThrottled = throttle(() => this.reportState(), 2000);
|
||||
throttleSync = throttle(() => this.requestSync(), 15000);
|
||||
throttleSync = throttle(() => this.requestSync(), 15000, {
|
||||
leading: false,
|
||||
trailing: true,
|
||||
});
|
||||
plugins: Promise<any>;
|
||||
defaultIncluded: any;
|
||||
localEndpoint: http.Server;
|
||||
@@ -81,6 +84,24 @@ class GoogleHome extends ScryptedDeviceBase implements HttpRequestHandler, Engin
|
||||
this.queueReportState(source);
|
||||
});
|
||||
|
||||
systemManager.listen((eventSource, eventDetails, eventData) => {
|
||||
if (eventDetails.eventInterface !== ScryptedInterface.ScryptedDevice)
|
||||
return;
|
||||
|
||||
if (!eventDetails.changed)
|
||||
return;
|
||||
|
||||
if (eventDetails.property !== ScryptedInterfaceProperty.id) {
|
||||
if (this.storage.getItem(`link-${eventSource?.id}`) !== this.linkTracker) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const device = systemManager.getDeviceById(eventSource?.id);
|
||||
this.log.i(`Device descriptor changed: ${device?.name}. Requesting sync.`);
|
||||
this.throttleSync();
|
||||
});
|
||||
|
||||
this.plugins = systemManager.getComponent('plugins');
|
||||
|
||||
this.localEndpoint = new http.Server((req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user