Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always set to off state when in pressMode. #1

Open
wants to merge 2 commits into
base: latest
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ If it work, add devices.
"type": "bot",
"name": "Bot 51",
"bleMac": "e7:4d:36:cf:9e:51",
"scanDuration": 2000
"scanDuration": 2000,
"pressMode": true
},
{
"type": "curtain",
Expand All @@ -90,7 +91,7 @@ If it work, add devices.
]
```

**Requird Settings**
**Required Settings**

- `devices` - SwitchBot devices list.
- `type` - Device type. Currently supports `bot`, `curtain` and `meter`.
Expand All @@ -106,6 +107,7 @@ If it work, add devices.
- For a Meter, sets how frequently to scan in order to retrieve temperature and humidity values. Default is `60000` (unit: ms).
- For a Curtain, sets how frequently to scan in order to retrieve the curtain position. Default is `60000` (unit: ms) when idle.
- `openCloseThreshold` - Set the threshold before/after which the curtain is reported as fully open/closed to HomeKit. Default is `5`, so any position under 5% is reported as fully open and above 95% as fully closed.
- `pressMode` - Set to `true` to treat "Press mode" of Bot.

Please note that:

Expand Down
4 changes: 4 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
"openCloseThreshold": {
"type": "integer",
"title": "Open close threshold (For Curtain. Default is 5000ms)"
},
"pressMode": {
"type": "boolean",
"title": "Press mode (For Bot. Default is false)"
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/bot-accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class Bot implements AccessoryPlugin {
private readonly log: Logging;
private readonly bleMac: string;
private readonly scanDuration: number;
private readonly pressMode: boolean;
private readonly switchbot: any;

private switchOn = false;
Expand All @@ -28,11 +29,12 @@ export class Bot implements AccessoryPlugin {
private readonly botService: Service;
private readonly informationService: Service;

constructor(hap: HAP, log: Logging, name: string, bleMac: string, scanDuration: number) {
constructor(hap: HAP, log: Logging, name: string, bleMac: string, scanDuration: number, pressMode: boolean) {
this.log = log;
this.name = name;
this.bleMac = bleMac;
this.scanDuration = scanDuration;
this.pressMode = pressMode;
const SwitchBot = require("node-switchbot");
this.switchbot = new SwitchBot();

Expand Down Expand Up @@ -75,7 +77,7 @@ export class Bot implements AccessoryPlugin {
});
} else {
log.info(targetDevice.modelName + " (" + targetDevice.address + ") was found.");
// Set event handers
// Set event handlers
targetDevice.onconnect = () => {
// log.info('Connected.');
};
Expand All @@ -88,7 +90,7 @@ export class Bot implements AccessoryPlugin {
})
.then(() => {
log.info("Done.");
this.switchOn = targetState;
this.switchOn = this.pressMode ? false : targetState;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.runTimer = setTimeout(() => {
this.botService?.getCharacteristic(hap.Characteristic.On).updateValue(this.switchOn);
}, 500);
Expand Down
10 changes: 6 additions & 4 deletions src/switchbot-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,23 @@ class SwitchBotPlatform implements StaticPlatformPlugin {
this.log.debug(device.name);
this.log.debug(device.bleMac);
this.log.debug(device.scanDuration, typeof device.scanDuration);
this.log.debug(device.pressMode);
let scanDuration: number = device.scanDuration || 1000;
let scanInterval: number = device.scanInterval || 60000;
if (scanInterval < scanDuration) {
scanInterval = scanDuration + 1000;
}
switch (device.type) {
case "bot":
deviceList.push(new Bot(hap, this.log, device.name, device.bleMac.toLowerCase(), scanDuration));
const pressMode: boolean = device.pressMode || false;
deviceList.push(new Bot(hap, this.log, device.name, device.bleMac.toLowerCase(), scanDuration, pressMode));
break;
case "curtain":
const reverseDir: boolean = device.reverseDir || false;
const moveTime: number = device.moveTime || 2000;
deviceList.push(new Curtain(hap, this.log, device.name, device.bleMac.toLowerCase(),
deviceList.push(new Curtain(hap, this.log, device.name, device.bleMac.toLowerCase(),
scanDuration, reverseDir, moveTime, device.scanInterval || 60000, device.openCloseThreshold || 5));
break;
break;
case "meter":
deviceList.push(new Meter(hap, this.log, device.name, device.bleMac.toLowerCase(), scanDuration, scanInterval));
break;
Expand All @@ -91,7 +93,7 @@ class SwitchBotPlatform implements StaticPlatformPlugin {
break;
case "contact":
deviceList.push(new Contact(hap, this.log, device.name, device.bleMac.toLowerCase(), scanDuration, scanInterval));
break;
break;
default:
break;
}
Expand Down