Skip to content

Commit 55b0b65

Browse files
committedJan 6, 2019
add comapct mode compatibility
-bump gulp version + fix for new gulp version -rm unnecessary escape char in regex
1 parent 9052c3a commit 55b0b65

File tree

5 files changed

+83
-50
lines changed

5 files changed

+83
-50
lines changed
 

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ A value smaller than 250 probably will send the command only once.
5555
After sending the state will be set to 0 again.
5656

5757
## Changelog
58+
### 1.2.0 (2018-01-06)
59+
* (foxriver76) compact mode compatibility added
5860

5961
### 1.1.5 (2018-12-28)
6062
* (Pmant) fix hold key (for values > 250ms)

‎gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,4 +485,4 @@ gulp.task('updateReadme', function (done) {
485485
done();
486486
});
487487

488-
gulp.task('default', ['updatePackages', 'updateReadme']);
488+
gulp.task('default', gulp.series('updatePackages', 'updateReadme'));

‎harmony.js

+64-45
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,72 @@
1111

1212
const HarmonyHubDiscover = require('@harmonyhub/discover').Explorer;
1313
const utils = require('@iobroker/adapter-core');
14-
const adapter = new utils.Adapter('harmony');
1514
const HarmonyWS = require('harmonyhubws');
1615
const hubs = {};
16+
let adapter;
1717
let discover;
18-
const FORBIDDEN_CHARS = /[\]\[*,;'"`<>\\? ]/g;
18+
const FORBIDDEN_CHARS = /[\][*,;'"`<>\\? ]/g;
1919
const fixId = (id) => id.replace(FORBIDDEN_CHARS, '_');
2020
let manualDiscoverHubs;
2121
let subnet;
2222
let discoverInterval;
2323

24-
adapter.on('stateChange', (id, state) => {
25-
if (!id || !state || state.ack) {
26-
return;
27-
}
28-
const hub = id.split('.')[2];
29-
if (!hubs[hub]) return;
30-
const semaphore = hubs[hub].semaphore;
31-
if (semaphore === undefined) {
32-
adapter.log.warn('state changed in offline hub');
33-
return;
34-
}
35-
if (semaphore.current > 0) {
36-
adapter.log.info('hub busy, stateChange delayed: ' + id + '=' + state.val);
37-
}
38-
semaphore.take(() => {
39-
setBlocked(hub, true);
40-
processStateChange(hub, id, state, () => {
41-
if (semaphore.current === 1) {
42-
setBlocked(hub, false);
43-
}
44-
semaphore.leave();
24+
25+
function startAdapter(options) {
26+
options = options || {};
27+
Object.assign(options, {
28+
name: 'harmony'
29+
});
30+
adapter = new utils.Adapter(options);
31+
32+
adapter.on('stateChange', (id, state) => {
33+
if (!id || !state || state.ack) {
34+
return;
35+
}
36+
const hub = id.split('.')[2];
37+
if (!hubs[hub]) return;
38+
const semaphore = hubs[hub].semaphore;
39+
if (semaphore === undefined) {
40+
adapter.log.warn('state changed in offline hub');
41+
return;
42+
}
43+
if (semaphore.current > 0) {
44+
adapter.log.info('hub busy, stateChange delayed: ' + id + '=' + state.val);
45+
}
46+
semaphore.take(() => {
47+
setBlocked(hub, true);
48+
processStateChange(hub, id, state, () => {
49+
if (semaphore.current === 1) {
50+
setBlocked(hub, false);
51+
}
52+
semaphore.leave();
53+
});
4554
});
4655
});
47-
});
56+
57+
// callback has to be called under any circumstances
58+
adapter.on('unload', callback => {
59+
try {
60+
adapter.log.info('[END] Terminating');
61+
if (discover) {
62+
discover.stop();
63+
} // endIf
64+
discover = null;
65+
for (const hub in Object.keys(hubs)) {
66+
clientStop(hub);
67+
} // endFor
68+
callback();
69+
} catch (e) {
70+
callback();
71+
} // endTryCatch
72+
});
73+
74+
adapter.on('ready', () => {
75+
main();
76+
});
77+
78+
return adapter;
79+
} // endStartAdapter
4880

4981
function processStateChange(hub, id, state, callback) {
5082
const tmp = id.split('.');
@@ -139,27 +171,6 @@ function switchActivity(hub, activityLabel, value, callback) {
139171
}
140172
}
141173

142-
// callback has to be called under any circumstances
143-
adapter.on('unload', callback => {
144-
try {
145-
adapter.log.info('[END] Terminating');
146-
if (discover) {
147-
discover.stop();
148-
} // endIf
149-
discover = null;
150-
for (const hub in Object.keys(hubs)) {
151-
clientStop(hub);
152-
} // endFor
153-
callback();
154-
} catch (e) {
155-
callback();
156-
} // endTryCatch
157-
});
158-
159-
adapter.on('ready', () => {
160-
main();
161-
});
162-
163174
function main() {
164175
manualDiscoverHubs = adapter.config.devices || [];
165176
subnet = adapter.config.subnet || '255.255.255.255';
@@ -574,3 +585,11 @@ function setConnected(hub, bool) {
574585
adapter.setState(hub + '.hubConnected', {val: bool, ack: true});
575586
}
576587
}
588+
589+
// If started as allInOne/compact mode => return function to create instance
590+
if (module && module.parent) {
591+
module.exports = startAdapter;
592+
} else {
593+
// or start the instance directly
594+
startAdapter();
595+
}

‎io-package.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"common": {
33
"name": "harmony",
4-
"version": "1.1.5",
4+
"version": "1.2.0",
55
"title": "Logitech Harmony",
66
"desc": {
77
"en": "Control your harmony activities from ioBroker",
@@ -12,6 +12,17 @@
1212
"Pmant <patrickmo@gmx.de>"
1313
],
1414
"news": {
15+
"1.2.0": {
16+
"en": "compact mode compatibility added",
17+
"de": "Kompaktmodus-Kompatibilität hinzugefügt",
18+
"ru": "добавлена ​​совместимость с компактным режимом",
19+
"pt": "compatibilidade de modo compacto adicionada",
20+
"nl": "compatibiliteit met compacte modus toegevoegd",
21+
"fr": "Compatibilité en mode compact ajoutée",
22+
"it": "aggiunta la compatibilità in modalità compatta",
23+
"es": "compatibilidad de modo compacto agregado",
24+
"pl": "Dodano kompatybilność w trybie kompaktowym"
25+
},
1526
"1.1.5": {
1627
"en": "fix hold key (for values > 250ms)",
1728
"de": "fix Taste gedrückt halten (für Werte > 250ms)"
@@ -93,6 +104,7 @@
93104
"icon": "harmony.png",
94105
"extIcon": "https://raw.githubusercontent.com/pmant/ioBroker.harmony/master/admin/harmony.png"
95106
},
107+
"compact": true,
96108
"native": {
97109
"user": "guest",
98110
"password": "default",

‎package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iobroker.harmony",
3-
"version": "1.1.5",
3+
"version": "1.2.0",
44
"engines": {
55
"node": ">=6.0.0"
66
},
@@ -22,12 +22,12 @@
2222
},
2323
"dependencies": {
2424
"@harmonyhub/discover": "^1.0.5",
25-
"@iobroker/adapter-core": "^1.0.1",
25+
"@iobroker/adapter-core": "^1.0.3",
2626
"harmonyhubws": "^1.0.4",
2727
"semaphore": "~1.0.3"
2828
},
2929
"devDependencies": {
30-
"gulp": "^3.9.1",
30+
"gulp": "^4.0.0",
3131
"mocha": "^4.1.0",
3232
"chai": "^4.1.2",
3333
"eslint": "^5.9.0"

0 commit comments

Comments
 (0)
Please sign in to comment.