Skip to content

Commit 46d0902

Browse files
author
QuickSander
committed
feat: Added identify HomeKit request option.
1 parent 0409a08 commit 46d0902

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ The configuration can contain the following properties:
5151
* `getUrl` \<string | [urlObject](#urlobject)\> **required**: Defines the url
5252
(and other properties when using an urlObject) to query the current value from the sensor.
5353
It currently expects the http server to return a float ranging from 0-100 (step 0.1) leaving out any html markup.
54+
* `identifyUrl` \<string | [urlObject](#urlobject)\> **optional**: URL to call when the HomeKit identify action is requested.
5455
* `pullInterval` \<integer\> **optional**: The property expects an interval in **milliseconds** in which the plugin
5556
pulls updates from your http device. For more information read [pulling updates](#the-pull-way).
5657
* `debug` \<boolean\> **optional**: Enable debug mode and write more logs.

index.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ function HttpAmbientLightSensor(log, config) {
6666
return;
6767
}
6868

69+
70+
if(config.identifyUrl) {
71+
try {
72+
this.identifyUrl = configParser.parseUrlProperty(config.identifyUrl);
73+
} catch (error) {
74+
this.log.warn("Error occurred while parsing 'identifyUrl': " + error.message);
75+
this.log.warn("Aborting...");
76+
return;
77+
}
78+
}
79+
6980
this.homebridgeService = new Service.LightSensor(this.name);
7081
this.homebridgeService.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
7182
.setProps({
@@ -90,8 +101,28 @@ function HttpAmbientLightSensor(log, config) {
90101
HttpAmbientLightSensor.prototype = {
91102

92103
identify: function (callback) {
93-
this.log("Identify requested!");
94-
callback();
104+
this.log("Identify requested!");
105+
106+
if (this.identifyUrl) {
107+
http.httpRequest(this.identifyUrl, (error, response, body) => {
108+
109+
if (error) {
110+
this.log("identify() failed: %s", error.message);
111+
callback(error);
112+
}
113+
else if (response.statusCode !== 200) {
114+
this.log("identify() returned http error: %s", response.statusCode);
115+
callback(new Error("Got http error code " + response.statusCode));
116+
}
117+
else {
118+
callback(null);
119+
}
120+
});
121+
}
122+
else {
123+
callback(null);
124+
}
125+
95126
},
96127

97128
getServices: function () {

0 commit comments

Comments
 (0)