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.
- package/CHANGELOG.md +6 -1
- package/index.js +160 -136
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/index.js
CHANGED
|
@@ -1,58 +1,52 @@
|
|
|
1
|
-
let
|
|
2
|
-
|
|
1
|
+
let axios = require('axios')
|
|
2
|
+
//mdns = require('mdns-js'); ///"mdns-js": "^1.0.3",
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
Accessory,
|
|
6
|
-
Characteristic,
|
|
7
|
-
Service;
|
|
4
|
+
var API, Accessory, Characteristic, Service
|
|
8
5
|
|
|
9
|
-
module.exports = function(homebridge) {
|
|
10
|
-
API = homebridge
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
16
|
-
}
|
|
12
|
+
homebridge.registerAccessory('homebridge-ismartgate-sensor', 'iSmartGate', iSmartGate)
|
|
13
|
+
}
|
|
17
14
|
|
|
18
15
|
function iSmartGate(log, config) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
+
this.BatteryService = new Service.Battery(this.name)
|
|
45
40
|
|
|
46
41
|
// Accessory Information service
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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(
|
|
89
|
-
|
|
90
|
-
|
|
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(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
setInterval(
|
|
97
|
+
function () {
|
|
98
|
+
this.response = this._login()
|
|
99
|
+
}.bind(this),
|
|
100
|
+
10800000
|
|
101
|
+
)
|
|
96
102
|
|
|
97
103
|
// Return the Accessory
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
111
|
+
withCredentials: true,
|
|
111
112
|
method: 'post',
|
|
112
113
|
url: `http://${this.hostname}/index.php`,
|
|
113
114
|
headers: {
|
|
114
|
-
|
|
115
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
115
116
|
'Accept-Encoding': 'gzip,deflate,compress',
|
|
116
117
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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) {
|
|
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
|
-
|
|
134
|
+
this.log.info('Logged into iSmartGate succesfully')
|
|
132
135
|
this.log.debug('signin response', response.headers)
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
this.cookie = response.headers['set-cookie']
|
|
137
|
+
return response
|
|
135
138
|
}
|
|
136
|
-
} catch (err) {
|
|
139
|
+
} catch (err) {
|
|
140
|
+
this.log.error('Error retrieving token \n%s', err)
|
|
141
|
+
}
|
|
137
142
|
},
|
|
138
143
|
|
|
139
|
-
|
|
144
|
+
_refresh: async function () {
|
|
140
145
|
try {
|
|
141
|
-
|
|
146
|
+
this.log.debug('Start refreshing temperature & battery')
|
|
142
147
|
let response = await axios({
|
|
143
|
-
|
|
148
|
+
withCredentials: true,
|
|
144
149
|
method: 'get',
|
|
145
150
|
url: `http://${this.hostname}/isg/temperature.php`,
|
|
146
|
-
|
|
147
|
-
|
|
151
|
+
headers: {
|
|
152
|
+
Cookie: this.cookie,
|
|
153
|
+
},
|
|
154
|
+
params: {
|
|
155
|
+
door: 1,
|
|
148
156
|
},
|
|
149
|
-
|
|
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) {
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
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
|
-
|
|
184
|
-
|
|
227
|
+
_getValue: function (CharacteristicName, callback) {
|
|
228
|
+
this.log.debug('GET', CharacteristicName)
|
|
229
|
+
callback(null)
|
|
230
|
+
},
|
|
185
231
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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.
|
|
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
|
-
|
|
13
|
-
|
|
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",
|