@@ -46,22 +46,21 @@ module.exports = function (homebridge) {
46
46
function HttpAmbientLightSensor ( log , config ) {
47
47
this . log = log ;
48
48
this . name = config . name ;
49
- this . debug = config . debug || false ;
50
49
this . minSensorValue = config . minValue || MIN_LUX_VALUE ;
51
50
this . maxSensorValue = config . maxValue || MAX_LUX_VALUE ;
52
51
53
52
if ( config . getUrl ) {
54
53
try {
55
54
this . getUrl = configParser . parseUrlProperty ( config . getUrl ) ;
56
55
} catch ( error ) {
57
- this . log . warn ( "Error occurred while parsing 'getUrl': " + error . message ) ;
58
- this . log . warn ( "Aborting..." ) ;
56
+ this . log . error ( "Error occurred while parsing 'getUrl': " + error . message ) ;
57
+ this . log . error ( "Aborting..." ) ;
59
58
return ;
60
59
}
61
60
}
62
61
else {
63
- this . log . warn ( "Property 'getUrl' is required!" ) ;
64
- this . log . warn ( "Aborting..." ) ;
62
+ this . log . error ( "Property 'getUrl' is required!" ) ;
63
+ this . log . error ( "Aborting..." ) ;
65
64
return ;
66
65
}
67
66
@@ -70,8 +69,8 @@ function HttpAmbientLightSensor(log, config) {
70
69
try {
71
70
this . identifyUrl = configParser . parseUrlProperty ( config . identifyUrl ) ;
72
71
} catch ( error ) {
73
- this . log . warn ( "Error occurred while parsing 'identifyUrl': " + error . message ) ;
74
- this . log . warn ( "Aborting..." ) ;
72
+ this . log . error ( "Error occurred while parsing 'identifyUrl': " + error . message ) ;
73
+ this . log . error ( "Aborting..." ) ;
75
74
return ;
76
75
}
77
76
}
@@ -111,17 +110,17 @@ function HttpAmbientLightSensor(log, config) {
111
110
HttpAmbientLightSensor . prototype = {
112
111
113
112
identify : function ( callback ) {
114
- this . log ( "Identify requested! " ) ;
113
+ this . log . info ( "Identify requested" ) ;
115
114
116
115
if ( this . identifyUrl ) {
117
116
http . httpRequest ( this . identifyUrl , ( error , response , body ) => {
118
117
119
118
if ( error ) {
120
- this . log ( "identify() failed: %s" , error . message ) ;
119
+ this . log . error ( "identify() failed: %s" , error . message ) ;
121
120
callback ( error ) ;
122
121
}
123
122
else if ( response . statusCode !== 200 ) {
124
- this . log ( "identify() returned http error: %s" , response . statusCode ) ;
123
+ this . log . error ( "identify() returned http error: %s" , response . statusCode ) ;
125
124
callback ( new Error ( "Got http error code " + response . statusCode ) ) ;
126
125
}
127
126
else {
@@ -156,12 +155,11 @@ HttpAmbientLightSensor.prototype = {
156
155
characteristic = Characteristic . CurrentAmbientLightLevel ;
157
156
break ;
158
157
default :
159
- this . log ( "Encountered unknown characteristic handling notification: " + body . characteristic ) ;
158
+ this . log . warn ( "Encountered unknown characteristic handling notification: " + body . characteristic ) ;
160
159
return ;
161
160
}
161
+ this . log . debug ( "Update received from device: " + body . characteristic + ": " + body . value ) ;
162
162
163
- if ( this . debug )
164
- this . log ( "Updating '" + body . characteristic + "' to new value: " + body . value ) ;
165
163
this . homebridgeService . setCharacteristic ( characteristic , value ) ;
166
164
} ,
167
165
@@ -171,17 +169,16 @@ HttpAmbientLightSensor.prototype = {
171
169
this . pullTimer . resetTimer ( ) ;
172
170
173
171
if ( error ) {
174
- this . log ( "getSensorValue() failed: %s" , error . message ) ;
172
+ this . log . error ( "getSensorValue() failed: %s" , error . message ) ;
175
173
callback ( error ) ;
176
174
}
177
175
else if ( response . statusCode !== 200 ) {
178
- this . log ( "getSensorValue() returned http error: %s" , response . statusCode ) ;
176
+ this . log . error ( "getSensorValue() returned http error: %s" , response . statusCode ) ;
179
177
callback ( new Error ( "Got http error code " + response . statusCode ) ) ;
180
178
}
181
179
else {
182
180
const sensorValue = parseFloat ( body ) ;
183
- if ( this . debug )
184
- this . log ( "Sensor value is currently at %s" , sensorValue ) ;
181
+ this . log . info ( "Get sensor value: %s" , sensorValue ) ;
185
182
186
183
callback ( null , sensorValue ) ;
187
184
}
0 commit comments