diff --git a/config.schema.json b/config.schema.json index 5694adb5..3ea4f027 100644 --- a/config.schema.json +++ b/config.schema.json @@ -185,6 +185,14 @@ "condition": { "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Bot' && model.options.devices[arrayIndices].deviceId && model.options.devices[arrayIndices].bot && model.options.devices[arrayIndices].bot.mode);" } + }, + "doublePress": { + "title": "Do you want to similate a double press?", + "type": "number", + "placeholder": "2", + "condition": { + "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Bot' && model.options.devices[arrayIndices].deviceId && model.options.devices[arrayIndices].bot && model.options.devices[arrayIndices].bot.mode);" + } } } }, @@ -777,6 +785,7 @@ "options.devices[].configDeviceType", "options.devices[].bot.mode", "options.devices[].bot.deviceType", + "options.devices[].bot.doublePress", "options.devices[].meter.hide_temperature", "options.devices[].meter.hide_humidity", "options.devices[].humidifier.set_minStep", diff --git a/src/devices/bots.ts b/src/devices/bots.ts index 0c390b02..379bead4 100644 --- a/src/devices/bots.ts +++ b/src/devices/bots.ts @@ -39,6 +39,9 @@ export class Bot { deviceLogging!: string; deviceRefreshRate!: number; + // Others + doublePress!: number; + // Updates botUpdateInProgress!: boolean; doBotUpdate!: Subject; @@ -51,9 +54,16 @@ export class Bot { // default placeholders if (this.On === undefined) { this.On = false; + this.accessory.context.On = this.On; } else { this.On = this.accessory.context.On; } + if (device.bot?.doublePress) { + this.doublePress = device.bot?.doublePress; + this.accessory.context.doublePress = this.doublePress; + } else { + this.doublePress = 1; + } this.refreshRate(); this.logs(); this.BatteryLevel = 100; @@ -61,7 +71,7 @@ export class Bot { // Bot Config this.debugLog(`Bot: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, mode: ${device.bot?.mode},` - + ` deviceType: ${device.bot?.deviceType})`); + + ` deviceType: ${device.bot?.deviceType}, doublePress: ${this.doublePress})`); // this is subject we use to track when we need to POST changes to the SwitchBot API this.doBotUpdate = new Subject(); @@ -151,7 +161,11 @@ export class Bot { ) .subscribe(async () => { try { - await this.pushChanges(); + interval(100) + .pipe(take(this.doublePress!)) + .subscribe(async () => { + await this.pushChanges(); + }); } catch (e: any) { this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges`); if (this.deviceLogging === 'debug') { diff --git a/src/settings.ts b/src/settings.ts index bd31a7ea..22446a50 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -62,6 +62,7 @@ export type meter = { export type bot = { mode?: string; deviceType?: string; + doublePress?: number; }; export type humidifier = {