Skip to content

Commit

Permalink
add option for doublePres as requested in #124
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker committed Dec 28, 2021
1 parent b30d890 commit 3fefa07
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
9 changes: 9 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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);"
}
}
}
},
Expand Down Expand Up @@ -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",
Expand Down
18 changes: 16 additions & 2 deletions src/devices/bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class Bot {
deviceLogging!: string;
deviceRefreshRate!: number;

// Others
doublePress!: number;

// Updates
botUpdateInProgress!: boolean;
doBotUpdate!: Subject<void>;
Expand All @@ -51,17 +54,24 @@ 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;
this.StatusLowBattery = 1;

// 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();
Expand Down Expand Up @@ -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') {
Expand Down
1 change: 1 addition & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type meter = {
export type bot = {
mode?: string;
deviceType?: string;
doublePress?: number;
};

export type humidifier = {
Expand Down

0 comments on commit 3fefa07

Please sign in to comment.