Skip to content

Commit 475357e

Browse files
committed
Add v1.2.1
1 parent 3f0d33f commit 475357e

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"displayName": "Homebridge Virtual Button",
33
"name": "homebridge-virtual-button",
4-
"version": "1.2.0",
4+
"version": "1.2.1",
55
"description": "A short description about what your plugin does.",
66
"license": "Apache-2.0",
77
"repository": {

src/platform.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,25 @@ export class ExampleHomebridgePlatform implements DynamicPlatformPlugin {
8080
request: IncomingMessage,
8181
response: ServerResponse
8282
) {
83+
const [_url, query] =
84+
request.url && request.url.includes("?") ? request.url.split("?") : [];
85+
const nameRaw = query ? query.replace("name=", "") : "";
86+
const instanceName = nameRaw ? decodeURIComponent(nameRaw) : null;
87+
const instance = this.instances.find((i) => {
88+
return i.getName() === instanceName;
89+
});
90+
8391
if (request.url?.includes("/toggle")) {
84-
const [_url, query] = request.url ? request.url.split("?") : [];
85-
const nameRaw = query ? query.replace("name=", "") : "";
86-
const name = decodeURIComponent(nameRaw);
87-
const instance = this.instances.find((i) => {
88-
return i.getName() === name;
89-
});
9092
if (instance) {
9193
await instance.toggleState();
9294
} else {
93-
this.log.error("Could not find instance for name:", name);
95+
this.log.error("Could not find instance for name:", instanceName);
96+
}
97+
} else if (request.url?.includes("/setOn")) {
98+
if (instance) {
99+
await instance.setStateOn();
100+
} else {
101+
this.log.error("Could not find instance for name:", instanceName);
94102
}
95103
}
96104

src/platformAccessory.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { Service, PlatformAccessory, CharacteristicValue } from "homebridge";
22

33
import { ExampleHomebridgePlatform } from "./platform";
44

5+
const sleep = async (ms: number) =>
6+
new Promise((resolve) => setTimeout(resolve, ms));
7+
58
/**
69
* Platform Accessory
710
* An instance of this class is created for each accessory your platform registers
@@ -71,6 +74,20 @@ export class PlatformSwitchAccessory {
7174
);
7275
}
7376

77+
async setStateOn() {
78+
await this.setOn(true);
79+
this.service?.updateCharacteristic(
80+
this.platform.Characteristic.On,
81+
this.states?.On
82+
);
83+
await sleep(1500);
84+
await this.setOn(false);
85+
this.service?.updateCharacteristic(
86+
this.platform.Characteristic.On,
87+
this.states?.On
88+
);
89+
}
90+
7491
/**
7592
* Handle "SET" requests from HomeKit
7693
* These are sent when the user changes the state of an accessory, for example, turning on a Light bulb.
@@ -81,6 +98,7 @@ export class PlatformSwitchAccessory {
8198
value
8299
);
83100
this.states.On = value as boolean;
101+
await sleep(300);
84102
}
85103

86104
/**

0 commit comments

Comments
 (0)