From 064da326c096d03d67b10c84c5b1854431a89787 Mon Sep 17 00:00:00 2001 From: Brett Jia Date: Sun, 18 Feb 2024 22:18:57 -0500 Subject: [PATCH 1/4] core: reset base date on each reschedule call (#1331) --- plugins/core/src/builtins/scheduler.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugins/core/src/builtins/scheduler.ts b/plugins/core/src/builtins/scheduler.ts index fc077f832..f94f60ed6 100644 --- a/plugins/core/src/builtins/scheduler.ts +++ b/plugins/core/src/builtins/scheduler.ts @@ -26,18 +26,18 @@ export class Scheduler { schedule.saturday, ]; - const date = new Date(); - date.setHours(schedule.hour); - date.setMinutes(schedule.minute); - const ret: ScryptedDevice = { async setName() { }, async setType() { }, async setRoom() { }, async setMixins() { }, - async probe() { return true }, + async probe() { return true; }, listen(event: EventListenerOptions, callback, source?: ScryptedDeviceBase) { function reschedule(): Date { + const date = new Date(); + date.setHours(schedule.hour); + date.setMinutes(schedule.minute); + const now = Date.now(); for (let i = 0; i < 8; i++) { const future = new Date(date.getTime() + i * 24 * 60 * 60 * 1000); @@ -65,7 +65,7 @@ export class Scheduler { eventId: undefined, eventInterface: 'Scheduler', eventTime: Date.now(), - }, prevWhen) + }, prevWhen); } function setupTimer() { @@ -87,8 +87,13 @@ export class Scheduler { timeout = null; when = null; } - } - } + }; + }, + id: "", + pluginId: "", + interfaces: [], + mixins: [], + providedInterfaces: [] } ret.name = 'Scheduler'; From eec6291d9e69ee2354cb463d6cdb235b3197c6de Mon Sep 17 00:00:00 2001 From: Long Zheng Date: Mon, 19 Feb 2024 18:12:39 +1100 Subject: [PATCH 2/4] CI build changed plugins (#1323) * Fix WritableDeviceState * Fix tsconfig error * Fix test * Create build-plugins-changed.yml * Update build-sdk.yml * Update build-plugins-changed.yml --- .github/workflows/build-plugins-changed.yml | 40 +++++++++++++++++++++ .github/workflows/build-sdk.yml | 2 +- plugins/snapshot/test/test.ts | 26 -------------- plugins/snapshot/tsconfig.json | 3 +- 4 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/build-plugins-changed.yml diff --git a/.github/workflows/build-plugins-changed.yml b/.github/workflows/build-plugins-changed.yml new file mode 100644 index 000000000..046127edc --- /dev/null +++ b/.github/workflows/build-plugins-changed.yml @@ -0,0 +1,40 @@ +name: Build changed plugins + +on: + push: + branches: ["main"] + paths: ["plugins/**"] + pull_request: + paths: ["plugins/**"] + workflow_dispatch: + +jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 2 + - uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: Set up base packages + run: ./npm-install.sh + + - name: Build changed plugins + run: | + # Get the list of changed directories in /plugins + changed_dirs=$(git diff --name-only HEAD^ HEAD ./plugins | awk -F/ '{print $2}' | uniq) + + # Loop through each changed directory + for dir in $changed_dirs; do + pushd "./plugins/$dir" + echo "plugins/$dir > npm install" + npm install + echo "plugins/$dir > npm run build" + npm run build + popd + done diff --git a/.github/workflows/build-sdk.yml b/.github/workflows/build-sdk.yml index 871797135..b14794325 100644 --- a/.github/workflows/build-sdk.yml +++ b/.github/workflows/build-sdk.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: node-version: 18 - run: npm ci diff --git a/plugins/snapshot/test/test.ts b/plugins/snapshot/test/test.ts index 86861c9dd..7a77a2bb2 100644 --- a/plugins/snapshot/test/test.ts +++ b/plugins/snapshot/test/test.ts @@ -1,6 +1,5 @@ import { writeFileSync } from "fs"; import { ffmpegFilterImage } from "../src/ffmpeg-image-filter"; -import { sharpFilterImage } from "../src/sharp-image-filter"; import path from 'path'; async function main1() { @@ -27,29 +26,4 @@ async function main1() { console.log('test1 done'); } -async function main2() { - const ret = await sharpFilterImage('/Users/koush/Downloads/151-1678381127261.jpg', - { - blur: true, - // crop: { - // // fractional: true, - // left: 100, - // top: 100, - // width: 1000, - // height: 500, - // }, - brightness: -.2, - text: { - fontFile: path.join(__dirname, '../fs/Lato-Bold.ttf'), - text: 'Hello World', - } - // } - // { "crop": { "left": 0.216796875, "top": 0.2552083333333333, "width": 0.318359375, "height": 0.17907714843749994, "fractional": true } - } - ); - writeFileSync('test2.jpg', ret); - console.log('test2 done'); -} - main1(); -main2(); diff --git a/plugins/snapshot/tsconfig.json b/plugins/snapshot/tsconfig.json index a976b26c4..f38f8df74 100644 --- a/plugins/snapshot/tsconfig.json +++ b/plugins/snapshot/tsconfig.json @@ -8,6 +8,7 @@ "sourceMap": true }, "include": [ - "src/**/*" + "src/**/*", + "test/**/*", ] } \ No newline at end of file From a47f7e25660c2ef982a65d387ccf8dfefa6c3988 Mon Sep 17 00:00:00 2001 From: Long Zheng Date: Tue, 20 Feb 2024 03:17:05 +1100 Subject: [PATCH 3/4] sdk: define this type (#1332) * sdk: define this type * Fix indent --- sdk/src/index.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sdk/src/index.ts b/sdk/src/index.ts index 779a48ffb..b86983449 100644 --- a/sdk/src/index.ts +++ b/sdk/src/index.ts @@ -159,24 +159,22 @@ export class MixinDeviceBase extends DeviceBase implements DeviceState { (function () { function _createGetState(state: ScryptedInterfaceProperty) { - return function () { - // @ts-ignore: this as any + return function (this: ScryptedDeviceBase | MixinDeviceBase) { this._lazyLoadDeviceState(); - // @ts-ignore: this as any + // @ts-ignore: accessing private property return this._deviceState?.[state]; }; } function _createSetState(state: ScryptedInterfaceProperty) { - return function (value: any) { - // @ts-ignore: this as any + return function (this: ScryptedDeviceBase | MixinDeviceBase, value: any) { this._lazyLoadDeviceState(); - // @ts-ignore: this as any + // @ts-ignore: accessing private property if (!this._deviceState) { console.warn('device state is unavailable. the device must be discovered with deviceManager.onDeviceDiscovered or deviceManager.onDevicesChanged before the state can be set.'); } else { - // @ts-ignore: this as any + // @ts-ignore: accessing private property this._deviceState[state] = value; } }; From 657921a5b3ee52939f0607d9364e7c73659141db Mon Sep 17 00:00:00 2001 From: Long Zheng Date: Wed, 21 Feb 2024 08:31:22 +1100 Subject: [PATCH 4/4] sdk/server: Fix type of canMixin (#1333) * Fix type of canMixin * Allow undefined * Add void --- common/src/autoenable-mixin-provider.ts | 2 +- sdk/types/scrypted_python/scrypted_sdk/types.py | 2 +- sdk/types/src/types.input.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/src/autoenable-mixin-provider.ts b/common/src/autoenable-mixin-provider.ts index 517be6948..438b7741a 100644 --- a/common/src/autoenable-mixin-provider.ts +++ b/common/src/autoenable-mixin-provider.ts @@ -73,5 +73,5 @@ export abstract class AutoenableMixinProvider extends ScryptedDeviceBase { this.storage.setItem('hasEnabledMixin', JSON.stringify(this.hasEnabledMixin)); } - abstract canMixin(type: ScryptedDeviceType, interfaces: string[]): Promise; + abstract canMixin(type: ScryptedDeviceType, interfaces: string[]): Promise; } diff --git a/sdk/types/scrypted_python/scrypted_sdk/types.py b/sdk/types/scrypted_python/scrypted_sdk/types.py index a55b1412e..290c6079f 100644 --- a/sdk/types/scrypted_python/scrypted_sdk/types.py +++ b/sdk/types/scrypted_python/scrypted_sdk/types.py @@ -1097,7 +1097,7 @@ class Microphone: class MixinProvider: """MixinProviders can add and intercept interfaces to other devices to add or augment their behavior.""" - async def canMixin(self, type: ScryptedDeviceType, interfaces: list[str]) -> list[str]: + async def canMixin(self, type: ScryptedDeviceType, interfaces: list[str]) -> None | list[str]: pass async def getMixin(self, mixinDevice: Any, mixinDeviceInterfaces: list[ScryptedInterface], mixinDeviceState: WritableDeviceState) -> Any: diff --git a/sdk/types/src/types.input.ts b/sdk/types/src/types.input.ts index 9c87a5883..0af68371c 100644 --- a/sdk/types/src/types.input.ts +++ b/sdk/types/src/types.input.ts @@ -1862,7 +1862,7 @@ export interface MixinProvider { /** * Called by the system to determine if this provider can create a mixin for the supplied device. Returns null if a mixin can not be created, otherwise returns a list of new interfaces (which may be an empty list) that are provided by the mixin. */ - canMixin(type: ScryptedDeviceType, interfaces: string[]): Promise; + canMixin(type: ScryptedDeviceType, interfaces: string[]): Promise; /** * Create a mixin that can be applied to the supplied device.