homebridge-lockstate 1.0.2 → 1.0.5

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 (2) hide show
  1. package/index.js +99 -1
  2. package/package.json +2 -56
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
- var Service, Characteristic, Homebridge
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,103 @@ 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
+ else {
124
+ arr = [0];
125
+ this.socket.write(new Uint8Array(arr));
126
+ }
127
+ });
128
+
129
+ this.socket.on('close', (error) => {
130
+ if (error) {
131
+ this.log(error);
132
+ }
133
+ this.log("Connection lost");
134
+ this.flagscontect = false;
135
+
136
+ setTimeout(() => {
137
+ //this.socket = Net.createConnection({
138
+ // "port": config.port,
139
+ // "host": config.ip,
140
+ // "noDelay": true,
141
+ // "keepAlive": true
142
+ //});
143
+ this.socket.connect(this.ip);
144
+ this.log("Reconnecting to", this.ip.host);
145
+ }, 9000);
146
+ });
147
+
148
+
51
149
  }
52
150
 
53
151
  lockstate.prototype = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-lockstate",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
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
  }