homebridge-smartsystem 6.8.8 → 6.8.9

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/README.md CHANGED
@@ -312,6 +312,7 @@ Homebridge UI version
312
312
  - 6: 26 aug / removed double error handlers on cloudSocket
313
313
  - 7: 28 aug / restart if no free connections
314
314
  - 8: 28 aug / less logging (through logConfig) for device set/get functions
315
+ - 9: corrected reading the local config file + dump it in the logs
315
316
 
316
317
  ## Hardware
317
318
  A Raspberry Pi that connects to a Duotecno IP Node
@@ -10,7 +10,6 @@ const accessory_1 = require("./accessory");
10
10
  // - has security, so when opening you need to authenticate
11
11
  // - TargetDoorState -> Characteristic.CurrentDoorState.OPEN, .STOPPED, .CLOSED
12
12
  //
13
- //
14
13
  class GarageDoor extends accessory_1.Accessory {
15
14
  constructor(homebridge, unit) {
16
15
  super(homebridge, unit);
@@ -50,7 +49,7 @@ class GarageDoor extends accessory_1.Accessory {
50
49
  else if (state == this.homebridge.Characteristic.CurrentDoorState.STOPPED)
51
50
  return types_1.UnitMotorCmd.kStop;
52
51
  else
53
- return 0;
52
+ return null;
54
53
  }
55
54
  getDoorState(next) {
56
55
  try {
@@ -10,7 +10,6 @@ import { Accessory } from "./accessory";
10
10
  // - has security, so when opening you need to authenticate
11
11
  // - TargetDoorState -> Characteristic.CurrentDoorState.OPEN, .STOPPED, .CLOSED
12
12
  //
13
- //
14
13
 
15
14
 
16
15
 
@@ -61,7 +60,7 @@ export class GarageDoor extends Accessory {
61
60
  return this.homebridge.Characteristic.CurrentDoorState.STOPPED; // ????
62
61
  }
63
62
 
64
- HB2DT(state): UnitMotorCmd {
63
+ HB2DT(state): UnitMotorCmd | null {
65
64
  if (state == this.homebridge.Characteristic.CurrentDoorState.OPEN)
66
65
  return UnitMotorCmd.kOpen;
67
66
 
@@ -72,8 +71,7 @@ export class GarageDoor extends Accessory {
72
71
  return UnitMotorCmd.kStop;
73
72
 
74
73
  else
75
- return 0;
76
-
74
+ return null;
77
75
  }
78
76
 
79
77
  getDoorState(next) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-smartsystem",
3
3
  "displayname": "Duotecno Bridge",
4
- "version": "6.8.8",
4
+ "version": "6.8.9",
5
5
  "description": "SmartServer (Proxy TCP sockets to the cloud, Smappee MQTT, Duotecno IP Nodes, Homekit interface)",
6
6
  "main": "index.js",
7
7
  "author": "Johan Coppieters",
package/server/proxy.js CHANGED
@@ -13,6 +13,7 @@ exports.kEmptyProxy = {
13
13
  debug: false,
14
14
  kind: "solo" // default running under PM2 or other process manager -> don't restart yourself
15
15
  };
16
+ const config = Object.assign({}, exports.kEmptyProxy);
16
17
  function setProxyConfig(c) {
17
18
  // set the proxy config
18
19
  if (c) {
@@ -24,19 +25,17 @@ function setProxyConfig(c) {
24
25
  config.debug = !!c.debug;
25
26
  config.kind = c.kind || exports.kEmptyProxy.kind;
26
27
  }
27
- else {
28
- config = Object.assign({}, exports.kEmptyProxy);
29
- }
30
28
  return config;
31
29
  }
32
30
  exports.setProxyConfig = setProxyConfig;
33
- let config;
34
31
  try {
35
- setProxyConfig(require('../config-proxy.json'));
32
+ const configPath = require.resolve('../config-proxy.json');
33
+ console.log(`Using config file at: ${configPath}`);
34
+ setProxyConfig(require(configPath));
36
35
  }
37
36
  catch (e) {
38
37
  setProxyConfig();
39
- console.log("No config-proxy.json found, using default values from homebridge or other.");
38
+ log("No config-proxy.json found, using default values from homebridge or other.");
40
39
  }
41
40
  let connectionChecker = null;
42
41
  const gCloudConnections = [];
@@ -102,8 +101,9 @@ function cleanStart(restart = false) {
102
101
  }
103
102
  if (restart) {
104
103
  if (config.uniqueId) {
104
+ log(`[PROXY] → [CLOUD] Starting proxy with config: ${JSON.stringify(config, null, 2)}`);
105
105
  makeNewCloudConnection(config.masterAddress, config.masterPort, config.cloudServer, config.cloudPort, config.uniqueId);
106
- // check every 5 second for a free connection
106
+ // check every 10 second for a free connection
107
107
  connectionChecker = setInterval(() => {
108
108
  const freeConnection = gCloudConnections.find((ctx) => (!ctx.deviceSocket) && ctx.cloudSocket && (ctx.cloudSocket.readyState === 'open'));
109
109
  if (freeConnection) {
@@ -113,7 +113,7 @@ function cleanStart(restart = false) {
113
113
  error(`[PROXY] → [CLOUD] No free connections available, restarting proxy. ***************************`);
114
114
  cleanStart(true);
115
115
  }
116
- }, 5000);
116
+ }, 10 * 1000);
117
117
  }
118
118
  else {
119
119
  log(`[PROXY] → [CLOUD] Not restarting, no unique ID configured, not starting the proxy.`);
@@ -312,8 +312,10 @@ function restart() {
312
312
  // Graceful shutdown handler
313
313
  function handleShutdown(signal) {
314
314
  log(`[PROXY] → [SYSTEM] Received ${signal}, shutting down gracefully...`);
315
- if (connectionChecker)
315
+ if (connectionChecker) {
316
316
  clearInterval(connectionChecker);
317
+ connectionChecker = null;
318
+ }
317
319
  // Close all cloud connections
318
320
  gCloudConnections.forEach(ctx => ctx.cleanupSockets());
319
321
  gCloudConnections.splice(0, gCloudConnections.length);
package/server/proxy.ts CHANGED
@@ -26,6 +26,8 @@ export const kEmptyProxy: ProxyConfig = {
26
26
  kind: "solo" // default running under PM2 or other process manager -> don't restart yourself
27
27
  }
28
28
 
29
+ const config = {...kEmptyProxy};
30
+
29
31
  export function setProxyConfig(c?: ProxyConfig): ProxyConfig {
30
32
  // set the proxy config
31
33
  if (c) {
@@ -36,22 +38,23 @@ export function setProxyConfig(c?: ProxyConfig): ProxyConfig {
36
38
  config.uniqueId = c.uniqueId || kEmptyProxy.uniqueId;
37
39
  config.debug = !!c.debug;
38
40
  config.kind = c.kind || kEmptyProxy.kind;
39
- } else {
40
- config = {...kEmptyProxy};
41
41
  }
42
42
  return config;
43
43
  }
44
44
 
45
- let config: ProxyConfig;
45
+
46
46
  try {
47
- setProxyConfig(require('../config-proxy.json'));
47
+ const configPath = require.resolve('../config-proxy.json');
48
+ console.log(`Using config file at: ${configPath}`);
49
+ setProxyConfig(require(configPath));
50
+
48
51
  } catch (e) {
49
52
  setProxyConfig();
50
- console.log("No config-proxy.json found, using default values from homebridge or other.");
53
+ log("No config-proxy.json found, using default values from homebridge or other.");
51
54
  }
52
55
 
53
56
 
54
- let connectionChecker: NodeJS.Timer | null = null;
57
+ let connectionChecker: NodeJS.Timeout | null = null;
55
58
 
56
59
  const gCloudConnections: Array<Context> = [];
57
60
  const kDebug = config.debug || false; // enable debug mode from config
@@ -130,9 +133,10 @@ export function cleanStart(restart: boolean = false) {
130
133
 
131
134
  if (restart) {
132
135
  if (config.uniqueId) {
136
+ log(`[PROXY] → [CLOUD] Starting proxy with config: ${JSON.stringify(config, null, 2)}`);
133
137
  makeNewCloudConnection(config.masterAddress, config.masterPort, config.cloudServer, config.cloudPort, config.uniqueId);
134
138
 
135
- // check every 5 second for a free connection
139
+ // check every 10 second for a free connection
136
140
  connectionChecker = setInterval(() => {
137
141
  const freeConnection = gCloudConnections.find((ctx: Context) =>
138
142
  (!ctx.deviceSocket) && ctx.cloudSocket && (ctx.cloudSocket.readyState === 'open')
@@ -143,7 +147,7 @@ export function cleanStart(restart: boolean = false) {
143
147
  error(`[PROXY] → [CLOUD] No free connections available, restarting proxy. ***************************`);
144
148
  cleanStart(true);
145
149
  }
146
- }, 5000);
150
+ }, 10 * 1000);
147
151
 
148
152
  } else {
149
153
  log(`[PROXY] → [CLOUD] Not restarting, no unique ID configured, not starting the proxy.`);
@@ -387,7 +391,10 @@ function restart() {
387
391
  function handleShutdown(signal: string) {
388
392
  log(`[PROXY] → [SYSTEM] Received ${signal}, shutting down gracefully...`);
389
393
 
390
- if (connectionChecker)clearInterval(connectionChecker);
394
+ if (connectionChecker) {
395
+ clearInterval(connectionChecker);
396
+ connectionChecker = null;
397
+ }
391
398
 
392
399
  // Close all cloud connections
393
400
  gCloudConnections.forEach(ctx => ctx.cleanupSockets());