homebridge-lockstate 1.0.2 → 1.0.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/index.js +95 -1
- package/package.json +2 -56
package/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
var Service,
|
|
1
|
+
var Service,Characteristic,Homebridge,recv_Value,Log
|
|
2
|
+
recv_Value=0;
|
|
2
3
|
const request = require('request')
|
|
3
4
|
const packageJson = require('./package.json')
|
|
4
5
|
const Net = require('net')
|
|
@@ -48,6 +49,99 @@ function lockstate(log, config) {
|
|
|
48
49
|
|
|
49
50
|
this.log(this.name)
|
|
50
51
|
this.service = new Service.LockMechanism(this.name)
|
|
52
|
+
|
|
53
|
+
this.ip = {
|
|
54
|
+
'host': config.ip || '127.0.0.1',
|
|
55
|
+
'port': config.port || 502
|
|
56
|
+
}
|
|
57
|
+
this.socket = new Net.Socket();
|
|
58
|
+
// Connect
|
|
59
|
+
|
|
60
|
+
//this.socket.connect(this.ip);
|
|
61
|
+
//this.socket = Net.createConnection({
|
|
62
|
+
// "port": config.port,
|
|
63
|
+
//"host": config.ip,
|
|
64
|
+
//"noDelay": true,
|
|
65
|
+
// "keepAlive": true
|
|
66
|
+
//});
|
|
67
|
+
|
|
68
|
+
Homebridge.on("didFinishLaunching", () => {
|
|
69
|
+
this.socket.connect(this.ip);
|
|
70
|
+
this.log("Connecting to", this.ip.host);
|
|
71
|
+
});
|
|
72
|
+
this.socket.on('connect', () => {
|
|
73
|
+
log("Socket connected");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
this.socket.on('error', (error) => {
|
|
77
|
+
if (error) {
|
|
78
|
+
log(error);
|
|
79
|
+
}
|
|
80
|
+
log("error-Connection error");
|
|
81
|
+
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
//this.socket = Net.createConnection({
|
|
84
|
+
// "port": config.port,
|
|
85
|
+
// "host": config.ip,
|
|
86
|
+
// "noDelay": true,
|
|
87
|
+
// "keepAlive": true
|
|
88
|
+
//});
|
|
89
|
+
//this.socket.connect(this.ip);���dz���
|
|
90
|
+
log("error-Reconnecting to",);
|
|
91
|
+
}, 10000);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
this.socket.on('data', (data) => {
|
|
95
|
+
|
|
96
|
+
var temp_value = data[0]
|
|
97
|
+
if (temp_value & 0x80 ) {
|
|
98
|
+
|
|
99
|
+
temp_value =temp_value &0x7f;
|
|
100
|
+
if (temp_value <= 100 && temp_value >= 0){
|
|
101
|
+
|
|
102
|
+
recv_Value =temp_value;
|
|
103
|
+
|
|
104
|
+
this.log("socket-data:%s", recv_Value);
|
|
105
|
+
|
|
106
|
+
if (recv_Value ==0)
|
|
107
|
+
{
|
|
108
|
+
this.currentState = STATE_UNSECURED
|
|
109
|
+
this.targetState = STATE_UNSECURED
|
|
110
|
+
this.service.getCharacteristic(Characteristic.LockTargetState).updateValue(STATE_UNSECURED);
|
|
111
|
+
this.service.getCharacteristic(Characteristic.LockCurrentState).updateValue(STATE_UNSECURED);
|
|
112
|
+
}
|
|
113
|
+
else{
|
|
114
|
+
this.currentState = STATE_SECURED
|
|
115
|
+
this.targetState = STATE_SECURED
|
|
116
|
+
|
|
117
|
+
this.service.getCharacteristic(Characteristic.LockTargetState).updateValue(STATE_SECURED);
|
|
118
|
+
this.service.getCharacteristic(Characteristic.LockCurrentState).updateValue(STATE_SECURED);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
this.socket.on('close', (error) => {
|
|
126
|
+
if (error) {
|
|
127
|
+
this.log(error);
|
|
128
|
+
}
|
|
129
|
+
this.log("Connection lost");
|
|
130
|
+
this.flagscontect = false;
|
|
131
|
+
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
//this.socket = Net.createConnection({
|
|
134
|
+
// "port": config.port,
|
|
135
|
+
// "host": config.ip,
|
|
136
|
+
// "noDelay": true,
|
|
137
|
+
// "keepAlive": true
|
|
138
|
+
//});
|
|
139
|
+
this.socket.connect(this.ip);
|
|
140
|
+
this.log("Reconnecting to", this.ip.host);
|
|
141
|
+
}, 9000);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
|
|
51
145
|
}
|
|
52
146
|
|
|
53
147
|
lockstate.prototype = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-lockstate",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "lock",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -14,59 +14,5 @@
|
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
17
|
-
}
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"ajv": "^6.12.6",
|
|
20
|
-
"asn1": "^0.2.6",
|
|
21
|
-
"assert-plus": "^1.0.0",
|
|
22
|
-
"asynckit": "^0.4.0",
|
|
23
|
-
"aws-sign2": "^0.7.0",
|
|
24
|
-
"aws4": "^1.13.2",
|
|
25
|
-
"bcrypt-pbkdf": "^1.0.2",
|
|
26
|
-
"caseless": "^0.12.0",
|
|
27
|
-
"combined-stream": "^1.0.8",
|
|
28
|
-
"core-util-is": "^1.0.2",
|
|
29
|
-
"crc": "^3.4.0",
|
|
30
|
-
"dashdash": "^1.14.1",
|
|
31
|
-
"debug": "^3.2.7",
|
|
32
|
-
"delayed-stream": "^1.0.0",
|
|
33
|
-
"ecc-jsbn": "^0.1.2",
|
|
34
|
-
"extend": "^3.0.2",
|
|
35
|
-
"extsprintf": "^1.3.0",
|
|
36
|
-
"fast-deep-equal": "^3.1.3",
|
|
37
|
-
"fast-json-stable-stringify": "^2.1.0",
|
|
38
|
-
"forever-agent": "^0.6.1",
|
|
39
|
-
"form-data": "^2.3.3",
|
|
40
|
-
"getpass": "^0.1.7",
|
|
41
|
-
"har-schema": "^2.0.0",
|
|
42
|
-
"har-validator": "^5.1.5",
|
|
43
|
-
"http-signature": "^1.2.0",
|
|
44
|
-
"is-typedarray": "^1.0.0",
|
|
45
|
-
"isstream": "^0.1.2",
|
|
46
|
-
"jsbn": "^0.1.1",
|
|
47
|
-
"jsmodbus": "^4.0.10",
|
|
48
|
-
"json-schema": "^0.4.0",
|
|
49
|
-
"json-schema-traverse": "^0.4.1",
|
|
50
|
-
"json-stringify-safe": "^5.0.1",
|
|
51
|
-
"jsprim": "^1.4.2",
|
|
52
|
-
"mime-db": "^1.52.0",
|
|
53
|
-
"mime-types": "^2.1.35",
|
|
54
|
-
"ms": "^2.1.3",
|
|
55
|
-
"oauth-sign": "^0.9.0",
|
|
56
|
-
"performance-now": "^2.1.0",
|
|
57
|
-
"psl": "^1.15.0",
|
|
58
|
-
"punycode": "^2.3.1",
|
|
59
|
-
"qs": "^6.5.3",
|
|
60
|
-
"request": "^2.88.2",
|
|
61
|
-
"safe-buffer": "^5.2.1",
|
|
62
|
-
"safer-buffer": "^2.1.2",
|
|
63
|
-
"sshpk": "^1.18.0",
|
|
64
|
-
"tough-cookie": "^2.5.0",
|
|
65
|
-
"tunnel-agent": "^0.6.0",
|
|
66
|
-
"tweetnacl": "^0.14.5",
|
|
67
|
-
"uri-js": "^4.4.1",
|
|
68
|
-
"uuid": "^3.4.0",
|
|
69
|
-
"verror": "^1.10.0"
|
|
70
|
-
},
|
|
71
|
-
"devDependencies": {}
|
|
17
|
+
}
|
|
72
18
|
}
|