homebridge-ismartgate-sensor 1.4.3 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/index.js +160 -136
  3. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -5,4 +5,9 @@ Update
5
5
  - support for homebridge 2.0
6
6
  - updated dependancies
7
7
  - replaced depricated node modules
8
- - removed mdns config due to vulnerability
8
+ - removed mdns config due to vulnerability
9
+
10
+ ## 1.4.4
11
+ Update
12
+ - support for node 24
13
+ - deprecated node 18
package/index.js CHANGED
@@ -1,58 +1,52 @@
1
- let axios = require("axios")
2
- //mdns = require('mdns-js'); ///"mdns-js": "^1.0.3",
1
+ let axios = require('axios')
2
+ //mdns = require('mdns-js'); ///"mdns-js": "^1.0.3",
3
3
 
4
- var API,
5
- Accessory,
6
- Characteristic,
7
- Service;
4
+ var API, Accessory, Characteristic, Service
8
5
 
9
- module.exports = function(homebridge) {
10
- API = homebridge;
11
- Accessory = homebridge.hap.Accessory;
12
- Characteristic = homebridge.hap.Characteristic;
13
- Service = homebridge.hap.Service;
6
+ module.exports = function (homebridge) {
7
+ API = homebridge
8
+ Accessory = homebridge.hap.Accessory
9
+ Characteristic = homebridge.hap.Characteristic
10
+ Service = homebridge.hap.Service
14
11
 
15
- homebridge.registerAccessory("homebridge-ismartgate-sensor", "iSmartGate", iSmartGate);
16
- };
12
+ homebridge.registerAccessory('homebridge-ismartgate-sensor', 'iSmartGate', iSmartGate)
13
+ }
17
14
 
18
15
  function iSmartGate(log, config) {
19
- this.log = log;
20
- this.name = config["name"] || "iSmartGate Temperature";
21
- this.username = config["username"];
22
- this.password = config["password"];
23
- this.hostname = config["hostname"];
24
- this.response = null;
25
- this.cookie = null
26
-
27
- this.CurrentTemperature = null;
28
- this.BatteryLevel = null;
16
+ this.log = log
17
+ this.name = config['name'] || 'iSmartGate Temperature'
18
+ this.username = config['username']
19
+ this.password = config['password']
20
+ this.hostname = config['hostname']
21
+ this.response = null
22
+ this.cookie = null
23
+
24
+ this.CurrentTemperature = null
25
+ this.BatteryLevel = null
29
26
  }
30
27
 
31
28
  iSmartGate.prototype = {
29
+ identify: function (callback) {
30
+ this.log.info('identify')
31
+ callback()
32
+ },
32
33
 
33
- identify: function(callback) {
34
- this.log.info("identify");
35
- callback();
36
- },
37
-
38
- getServices: function() {
39
-
34
+ getServices: function () {
40
35
  // Temperature Sensor service
41
- this.TemperatureSensor = new Service.TemperatureSensor(this.name);
36
+ this.TemperatureSensor = new Service.TemperatureSensor(this.name)
42
37
 
43
38
  // Battery service
44
- this.BatteryService = new Service.Battery(this.name);
39
+ this.BatteryService = new Service.Battery(this.name)
45
40
 
46
41
  // Accessory Information service
47
- this.AccessoryInformation = new Service.AccessoryInformation();
48
- this.AccessoryInformation
49
- .setCharacteristic(Characteristic.Name, this.name)
50
- .setCharacteristic(Characteristic.Manufacturer, "iSmartGate")
51
- .setCharacteristic(Characteristic.Model, "Temperature")
52
- .setCharacteristic(Characteristic.FirmwareRevision, "1.4.2")
53
- .setCharacteristic(Characteristic.SerialNumber, this.username);
54
-
55
- /*
42
+ this.AccessoryInformation = new Service.AccessoryInformation()
43
+ this.AccessoryInformation.setCharacteristic(Characteristic.Name, this.name)
44
+ .setCharacteristic(Characteristic.Manufacturer, 'iSmartGate')
45
+ .setCharacteristic(Characteristic.Model, 'Temperature')
46
+ .setCharacteristic(Characteristic.FirmwareRevision, '1.4.2')
47
+ .setCharacteristic(Characteristic.SerialNumber, this.username)
48
+
49
+ /*
56
50
  // Start searching for the iSmartGate using mDNS
57
51
  var browser = mdns.createBrowser("_hap._tcp");
58
52
  browser.on('ready', function() { browser.discover(); });
@@ -75,138 +69,168 @@ iSmartGate.prototype = {
75
69
  }.bind(this));
76
70
  */
77
71
 
78
- // Login to the iSmartGate for the first time and refresh
79
- setTimeout(function() {
80
- this.response=this._login();
81
- }.bind(this), 2500);
82
-
83
- setTimeout(function() {
84
- this._refresh();
85
- }.bind(this), 5000);
72
+ // Login to the iSmartGate for the first time and refresh
73
+ setTimeout(
74
+ function () {
75
+ this.response = this._login()
76
+ }.bind(this),
77
+ 2500
78
+ )
79
+
80
+ setTimeout(
81
+ function () {
82
+ this._refresh()
83
+ }.bind(this),
84
+ 5000
85
+ )
86
86
 
87
87
  // Set a timer to refresh the data every 10 minutes
88
- setInterval(function() {
89
- this._refresh();
90
- }.bind(this), 600000);
88
+ setInterval(
89
+ function () {
90
+ this._refresh()
91
+ }.bind(this),
92
+ 600000
93
+ )
91
94
 
92
95
  // Set a timer to refresh the login token every 3 hours
93
- setInterval(function() {
94
- this.response=this._login();
95
- }.bind(this), 10800000);
96
+ setInterval(
97
+ function () {
98
+ this.response = this._login()
99
+ }.bind(this),
100
+ 10800000
101
+ )
96
102
 
97
103
  // Return the Accessory
98
- return [
99
- this.AccessoryInformation,
100
- this.TemperatureSensor,
101
- this.BatteryService
102
- ];
103
-
104
- },
104
+ return [this.AccessoryInformation, this.TemperatureSensor, this.BatteryService]
105
+ },
105
106
 
106
- _login: async function() {
107
+ _login: async function () {
107
108
  try {
108
109
  this.log.info('Retrieving token')
109
110
  let response = await axios({
110
- withCredentials: true,
111
+ withCredentials: true,
111
112
  method: 'post',
112
113
  url: `http://${this.hostname}/index.php`,
113
114
  headers: {
114
- 'Content-Type': 'application/x-www-form-urlencoded',
115
+ 'Content-Type': 'application/x-www-form-urlencoded',
115
116
  'Accept-Encoding': 'gzip,deflate,compress',
116
117
  },
117
- data: {
118
- "MIME Type": "application/x-www-form-urlencoded",
119
- "login": this.username,
120
- "pass": this.password,
121
- "send-login": "Sign in"
122
- },
123
- responseType: 'text'
118
+ data: {
119
+ 'MIME Type': 'application/x-www-form-urlencoded',
120
+ login: this.username,
121
+ pass: this.password,
122
+ 'send-login': 'Sign in',
123
+ },
124
+ responseType: 'text',
124
125
  }).catch(err => {
125
126
  this.log.debug(JSON.stringify(err, null, 2))
126
127
  this.log.error('Error signing in and getting token %s', err.message)
127
- if (err.response) { this.log.warn(JSON.stringify(err.response.data, null, 2))}
128
+ if (err.response) {
129
+ this.log.warn(JSON.stringify(err.response.data, null, 2))
130
+ }
128
131
  return err.response
129
132
  })
130
133
  if (response.status == 200) {
131
- this.log.info("Logged into iSmartGate succesfully");
134
+ this.log.info('Logged into iSmartGate succesfully')
132
135
  this.log.debug('signin response', response.headers)
133
- this.cookie=response.headers['set-cookie']
134
- return response
136
+ this.cookie = response.headers['set-cookie']
137
+ return response
135
138
  }
136
- } catch (err) { this.log.error('Error retrieving token \n%s', err)}
139
+ } catch (err) {
140
+ this.log.error('Error retrieving token \n%s', err)
141
+ }
137
142
  },
138
143
 
139
- _refresh: async function() {
144
+ _refresh: async function () {
140
145
  try {
141
- this.log.debug("Start refreshing temperature & battery");
146
+ this.log.debug('Start refreshing temperature & battery')
142
147
  let response = await axios({
143
- withCredentials: true,
148
+ withCredentials: true,
144
149
  method: 'get',
145
150
  url: `http://${this.hostname}/isg/temperature.php`,
146
- headers: {
147
- 'Cookie': this.cookie
151
+ headers: {
152
+ Cookie: this.cookie,
153
+ },
154
+ params: {
155
+ door: 1,
148
156
  },
149
- params: {
150
- door: 1
151
- },
152
- responseType: 'json'
157
+ responseType: 'json',
153
158
  }).catch(err => {
154
159
  this.log.debug(JSON.stringify(err, null, 2))
155
160
  this.log.error('Error fetching temperature & battery %s', err.message)
156
- if (err.response) { this.log.warn(JSON.stringify(err.response.data, null, 2))}
161
+ if (err.response) {
162
+ this.log.warn(JSON.stringify(err.response.data, null, 2))
163
+ }
157
164
  return err.response
158
165
  })
159
166
  if (response.status == 200 && Array.isArray(response.data)) {
160
- this.log.debug("Obtained status.", response.data);
161
-
162
- // Find the CurrentTemperature
163
- this.CurrentTemperature = response.data[0] / 1000;
164
-
165
- // Find the BatteryLevel
166
- switch (response.data[1]) {
167
- case "full": this.BatteryLevel = 100; break;
168
- case "80": this.BatteryLevel = 80; break;
169
- case "60": this.BatteryLevel = 60; break;
170
- case "40": this.BatteryLevel = 40; break;
171
- case "20": this.BatteryLevel = 20; break;
172
- case "low": this.BatteryLevel = 10; break;
173
-
174
- default:
175
- this.log.warn("Unexpected BatteryLevel detected.", response.data);
176
- this.BatteryLevel = 0;
177
- break;
178
- }
167
+ this.log.debug('Obtained status.', response.data)
168
+
169
+ // Find the CurrentTemperature
170
+ this.CurrentTemperature = response.data[0] / 1000
171
+
172
+ // Find the BatteryLevel
173
+ switch (response.data[1]) {
174
+ case 'full':
175
+ this.BatteryLevel = 100
176
+ break
177
+ case '80':
178
+ this.BatteryLevel = 80
179
+ break
180
+ case '60':
181
+ this.BatteryLevel = 60
182
+ break
183
+ case '40':
184
+ this.BatteryLevel = 40
185
+ break
186
+ case '20':
187
+ this.BatteryLevel = 20
188
+ break
189
+ case 'low':
190
+ this.BatteryLevel = 10
191
+ break
192
+
193
+ default:
194
+ this.log.warn('Unexpected BatteryLevel detected.', response.data)
195
+ this.BatteryLevel = 0
196
+ break
197
+ }
179
198
 
180
199
  // Set the Current Temperature
181
- this.TemperatureSensor.getCharacteristic(Characteristic.CurrentTemperature).updateValue(this.CurrentTemperature);
200
+ this.TemperatureSensor.getCharacteristic(Characteristic.CurrentTemperature).updateValue(this.CurrentTemperature)
201
+
202
+ // Set the Battery Level
203
+ this.BatteryService.setCharacteristic(Characteristic.BatteryLevel, this.BatteryLevel)
204
+
205
+ // Set the Status Low Battery
206
+ if (this.BatteryLevel <= 10) {
207
+ this.BatteryService.setCharacteristic(Characteristic.StatusLowBattery, Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW)
208
+ } else {
209
+ this.BatteryService.setCharacteristic(Characteristic.StatusLowBattery, Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL)
210
+ }
211
+ return response
212
+ } else {
213
+ if (response.data == 'Restricted Access') {
214
+ this.log.error('Restricted Access', response.data)
215
+ } else if (response.data == 'Login Token Expired') {
216
+ this.log.error('Login Token Expired', response.data)
217
+ } else {
218
+ this.log.error('Could not connect.', 'Check http://' + this.hostname + ' to make sure the device is still reachable & no captcha is showing.')
219
+ this.log.error(response.data)
220
+ }
221
+ }
222
+ } catch (err) {
223
+ this.log.error('Error retrieving temperature & battery \n%s', err)
224
+ }
225
+ },
182
226
 
183
- // Set the Battery Level
184
- this.BatteryService.setCharacteristic(Characteristic.BatteryLevel, this.BatteryLevel);
227
+ _getValue: function (CharacteristicName, callback) {
228
+ this.log.debug('GET', CharacteristicName)
229
+ callback(null)
230
+ },
185
231
 
186
- // Set the Status Low Battery
187
- if(this.BatteryLevel <= 10) {this.BatteryService.setCharacteristic(Characteristic.StatusLowBattery, Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW);}
188
- else {this.BatteryService.setCharacteristic(Characteristic.StatusLowBattery, Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL);}
189
- return response
190
- }
191
- else {
192
- if(response.data == "Restricted Access") {this.log.error("Restricted Access", response.data);}
193
- else if(response.data == "Login Token Expired") {this.log.error("Login Token Expired", response.data);}
194
- else {
195
- this.log.error("Could not connect.", "Check http://" + this.hostname + " to make sure the device is still reachable & no captcha is showing.");
196
- this.log.error(response.data);}
197
- }
198
-
199
- } catch (err) { this.log.error('Error retrieving temperature & battery \n%s', err)}
200
- },
201
-
202
- _getValue: function(CharacteristicName, callback) {
203
- this.log.debug("GET", CharacteristicName);
204
- callback(null);
205
- },
206
-
207
- _setValue: function(CharacteristicName, value, callback) {
208
- this.log.debug("SET", CharacteristicName, value);
209
- callback();
210
- }
211
-
212
- };
232
+ _setValue: function (CharacteristicName, value, callback) {
233
+ this.log.debug('SET', CharacteristicName, value)
234
+ callback()
235
+ },
236
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-ismartgate-sensor",
3
3
  "displayName": "ismartgate sensor",
4
- "version": "1.4.3",
4
+ "version": "1.4.4",
5
5
  "author": "John Valiquette",
6
6
  "dependencies": {
7
7
  "axios": "^1.7.7"
@@ -9,8 +9,8 @@
9
9
  "deprecated": false,
10
10
  "description": "Homebridge plug-in for iSmartGate HomeKit devices to expose their Temperature & Battery sensor, which would otherwise be hidden.",
11
11
  "engines": {
12
- "homebridge": "^1.8.0 || ^2.0.0-beta.0",
13
- "node": "^18.20.0 || ^20.17.0 || ^22.9.0"
12
+ "homebridge": "^1.11.0 || ^2.0.0-beta.0",
13
+ "node": "^20.19.0 || ^22.19.0 ||^24.11.0"
14
14
  },
15
15
  "keywords": [
16
16
  "homebridge-plugin",