Skip to content

Commit

Permalink
switch from stopInstance message handling to handle everything in unload
Browse files Browse the repository at this point in the history
  • Loading branch information
foxriver76 committed Jun 4, 2021
1 parent 6cb257e commit 05c467d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ gulpfile.js
!/README.md
/admin/i18n/*
lib/create-images-js.sh
admin/icons/removeBackground.js
test


4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ by ioBroker, when you have a running 'dummy' program on the CCU which depends on
Placeholder for the next version (at the beginning of the line):
### __WORK IN PROGRESS__
-->

### __WORK IN PROGRESS__
* (foxriver76) remove the stopInstance message handling and put everything in unload

### 1.14.38 (2021-05-11)
* (Jens Maus) fixed the VirtualDevices min/max/default assignment (fixes #332)
* (foxriver76) do not scale on normal '%' UNIT because its inconsistent (fixes #326)
Expand Down
2 changes: 1 addition & 1 deletion io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
"type": "iot-systems",
"connectionType": "local",
"dataSource": "push",
"supportStopInstance": true,
"stopTimeout": 1000,
"messagebox": true,
"dependencies": [
{
Expand Down
50 changes: 26 additions & 24 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,27 +542,7 @@ function startAdapter(options) {
return;
}

if (obj.command === 'stopInstance') {
if (rpcServer && rpcServer.server) {
try {
rpcServer.server.close(() => {
console.log('server closed.');
rpcServer.server.unref();
});
} catch {
// ignore
}
}
if (rpcClient && rpcClient.socket) {
try {
rpcClient.socket.destroy();
} catch {
// ignore
}
}
// force close
setTimeout(() => adapter.terminate ? adapter.terminate() : process.exit(), 3000);
} else if (obj.message.params === undefined || obj.message.params === null) {
if (obj.message.params === undefined || obj.message.params === null) {
try {
if (rpcClient && connected) {
// if device specific command, send it's ID and paramType
Expand Down Expand Up @@ -616,6 +596,7 @@ function startAdapter(options) {
clearInterval(connInterval);
connInterval = null;
}

if (connTimeout) {
clearTimeout(connTimeout);
connTimeout = null;
Expand All @@ -624,12 +605,33 @@ function startAdapter(options) {
if (adapter.config && rpcClient) {
adapter.log.info(`${adapter.config.type}rpc -> ${adapter.config.homematicAddress}:${adapter.config.homematicPort}${homematicPath} init ${JSON.stringify([daemonURL, ''])}`);
try {
// tell CCU that we are no longer the client under this URL - legacy idk if necessary
await rpcMethodCallAsync('init', [daemonURL, '']);
if (connected) {
adapter.log.info('Disconnected');
connected = false;
adapter.setState('info.connection', false, true);
}

if (rpcServer && rpcServer.server) {
try {
rpcServer.server.close(() => {
console.log('server closed.');
rpcServer.server.unref();
});
} catch {
// ignore
}
}

if (rpcClient && rpcClient.socket) {
try {
rpcClient.socket.destroy();
} catch {
// ignore
}
}

if (typeof callback === 'function') {
callback();
}
Expand All @@ -655,9 +657,9 @@ function startAdapter(options) {
}
} catch (e) {
if (adapter && adapter.log) {
adapter.log.error(`Unload error: ${e}`);
adapter.log.error(`Unload error: ${e.message}`);
} else {
console.log(e);
console.log(`Unload error: ${e.message}`);
}
if (typeof callback === 'function') {
callback();
Expand Down Expand Up @@ -1712,7 +1714,7 @@ function connect(isFirst) {
return void adapter.restart();
} // endCatch

// If we have bin-rpc, only need it here because bin-rpc cant have https
// If we have bin-rpc, only need it here because bin-rpc cannot have https
if (rpcClient.on) {
rpcClient.on('error', err => {
adapter.log.error(`Socket error: ${err}`);
Expand Down

0 comments on commit 05c467d

Please sign in to comment.