Skip to content

Commit 189f9f9

Browse files
committed
Add cooldown option
1 parent 33cf25c commit 189f9f9

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,5 @@ dist
117117
.yarn/cache
118118
.yarn/unplugged
119119
.yarn/build-state.yml
120-
.pnp.*
120+
.pnp.*
121+
.DS_Store

config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
"title": "Disply name for homekit",
1818
"type": "string",
1919
"required": true
20+
},
21+
"cooldown": {
22+
"title": "Cooldown time in seconds",
23+
"type": "integer",
24+
"required": false
2025
}
2126
}
2227
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"displayName": "Homebridge Virtual Button",
33
"name": "homebridge-virtual-button",
44
"type": "module",
5-
"version": "1.3.1",
5+
"version": "1.4.0",
66
"description": "Just simple virtual buttons accessories for Homebridge",
77
"license": "Apache-2.0",
88
"repository": {

src/platformAccessory.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ export class PlatformSwitchAccessory {
9898
value,
9999
);
100100
this.states.On = value as boolean;
101+
102+
if (!!this.accessory.context.switch.cooldown && this.accessory.context.switch.cooldown > 0) {
103+
setTimeout(() => {
104+
this.platform.log.info(
105+
`Cooldown finished for "${this.accessory.context.switch.name}", turning off...`,
106+
);
107+
this.states.On = false;
108+
this.service.updateCharacteristic(
109+
this.platform.Characteristic.On,
110+
this.states.On,
111+
);
112+
}
113+
, this.accessory.context.switch.cooldown * 1000);
114+
}
115+
101116
await sleep(300);
102117
}
103118

0 commit comments

Comments
 (0)