File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ The configuration can contain the following properties:
51
51
* ` getUrl ` \< string | [ urlObject] ( #urlobject ) \> ** required** : Defines the url
52
52
(and other properties when using an urlObject) to query the current value from the sensor.
53
53
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.
54
55
* ` pullInterval ` \< integer\> ** optional** : The property expects an interval in ** milliseconds** in which the plugin
55
56
pulls updates from your http device. For more information read [ pulling updates] ( #the-pull-way ) .
56
57
* ` debug ` \< boolean\> ** optional** : Enable debug mode and write more logs.
Original file line number Diff line number Diff line change @@ -66,6 +66,17 @@ function HttpAmbientLightSensor(log, config) {
66
66
return ;
67
67
}
68
68
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
+
69
80
this . homebridgeService = new Service . LightSensor ( this . name ) ;
70
81
this . homebridgeService . getCharacteristic ( Characteristic . CurrentAmbientLightLevel )
71
82
. setProps ( {
@@ -90,8 +101,28 @@ function HttpAmbientLightSensor(log, config) {
90
101
HttpAmbientLightSensor . prototype = {
91
102
92
103
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
+
95
126
} ,
96
127
97
128
getServices : function ( ) {
You can’t perform that action at this time.
0 commit comments