Skip to content

Commit 3c7bcf6

Browse files
author
QuickSander
committed
feat: Use homebridge debug parameter instead of own.
1 parent e6978ed commit 3c7bcf6

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ It currently expects the http server to return a float ranging from 0-100 (step
5454
* `identifyUrl` \<string | [urlObject](#urlobject)\> **optional**: URL to call when the HomeKit identify action is requested.
5555
* `pullInterval` \<integer\> **optional**: The property expects an interval in **milliseconds** in which the plugin
5656
pulls updates from your http device. For more information read [pulling updates](#the-pull-way).
57-
* `debug` \<boolean\> **optional**: Enable debug mode and write more logs.
5857
* `maxValue` \<float\> **optional**: Maximum lux value the sensor can return. Defaults to BH1750 light sensor module value: 2^16 -1 = 65535.
5958
* `minValue` \<float\> **optional**: Minimum lux value the sensor can return. Default to 0.0.
6059

index.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,21 @@ module.exports = function (homebridge) {
4646
function HttpAmbientLightSensor(log, config) {
4747
this.log = log;
4848
this.name = config.name;
49-
this.debug = config.debug || false;
5049
this.minSensorValue = config.minValue || MIN_LUX_VALUE;
5150
this.maxSensorValue = config.maxValue || MAX_LUX_VALUE;
5251

5352
if (config.getUrl) {
5453
try {
5554
this.getUrl = configParser.parseUrlProperty(config.getUrl);
5655
} 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...");
5958
return;
6059
}
6160
}
6261
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...");
6564
return;
6665
}
6766

@@ -70,8 +69,8 @@ function HttpAmbientLightSensor(log, config) {
7069
try {
7170
this.identifyUrl = configParser.parseUrlProperty(config.identifyUrl);
7271
} 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...");
7574
return;
7675
}
7776
}
@@ -111,17 +110,17 @@ function HttpAmbientLightSensor(log, config) {
111110
HttpAmbientLightSensor.prototype = {
112111

113112
identify: function (callback) {
114-
this.log("Identify requested!");
113+
this.log.info("Identify requested");
115114

116115
if (this.identifyUrl) {
117116
http.httpRequest(this.identifyUrl, (error, response, body) => {
118117

119118
if (error) {
120-
this.log("identify() failed: %s", error.message);
119+
this.log.error("identify() failed: %s", error.message);
121120
callback(error);
122121
}
123122
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);
125124
callback(new Error("Got http error code " + response.statusCode));
126125
}
127126
else {
@@ -156,12 +155,11 @@ HttpAmbientLightSensor.prototype = {
156155
characteristic = Characteristic.CurrentAmbientLightLevel;
157156
break;
158157
default:
159-
this.log("Encountered unknown characteristic handling notification: " + body.characteristic);
158+
this.log.warn("Encountered unknown characteristic handling notification: " + body.characteristic);
160159
return;
161160
}
161+
this.log.debug("Update received from device: " + body.characteristic + ": " + body.value);
162162

163-
if (this.debug)
164-
this.log("Updating '" + body.characteristic + "' to new value: " + body.value);
165163
this.homebridgeService.setCharacteristic(characteristic, value);
166164
},
167165

@@ -171,17 +169,16 @@ HttpAmbientLightSensor.prototype = {
171169
this.pullTimer.resetTimer();
172170

173171
if (error) {
174-
this.log("getSensorValue() failed: %s", error.message);
172+
this.log.error("getSensorValue() failed: %s", error.message);
175173
callback(error);
176174
}
177175
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);
179177
callback(new Error("Got http error code " + response.statusCode));
180178
}
181179
else {
182180
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);
185182

186183
callback(null, sensorValue);
187184
}

0 commit comments

Comments
 (0)