Skip to content

Commit 4b20912

Browse files
authored
Merge pull request #151 from Grizzelbee/Development
Development
2 parents 35bdd61 + dc5d406 commit 4b20912

File tree

5 files changed

+291
-568
lines changed

5 files changed

+291
-568
lines changed

io-package.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
{
22
"common": {
33
"name": "dysonairpurifier",
4-
"version": "2.1.2",
4+
"version": "2.1.3",
55
"news": {
6+
"2.1.3": {
7+
"en": "Bugfix release!\nHostaddress is used properly when given.\nOscillationAngle \"Breeze\" is working now\nStrange delay and jumping of boolean switches is fixed",
8+
"de": "Bugfix-Release! \nHostadresse wird korrekt verwendet, wenn sie angegeben wird. \nOscillationAngle \"Breeze\" funktioniert jetzt \nSeltsame Verzögerung und Springen von Booleschen Schaltern wurde behoben",
9+
"ru": "Выпуск исправления ошибок \n Hostaddress используется правильно, если задан. \n OscillationAngle \"Breeze\" теперь работает \n Странная задержка и скачки логических переключателей исправлены",
10+
"pt": "Versão de correção de bug \n Hostaddress é usado corretamente quando fornecido. \n OscillationAngle \"Breeze\" está funcionando agora \n Atraso estranho e saltos de interruptores booleanos foram corrigidos",
11+
"nl": "Bugfix release\nHostaddress wordt correct gebruikt wanneer gegeven.\nOscillationAngle \"Breeze\" werkt nu\nVreemde vertraging en springen van boolean switches is opgelost",
12+
"fr": "Version de correction de bug \n L'adresse d'hôte est utilisée correctement lorsqu'elle est donnée. \n L'angle d'oscillation \"Breeze\" fonctionne maintenant \n Le délai étrange et le saut des commutateurs booléens sont corrigés",
13+
"it": "Rilascio bugfix\nL'indirizzo host viene utilizzato correttamente quando viene fornito.\nOscillationAngle \"Breeze\" funziona ora\nLo strano ritardo e il salto degli interruttori booleani sono stati corretti",
14+
"es": "Versión de corrección de errores \n Hostaddress se usa correctamente cuando se proporciona. \n OscillationAngle \"Breeze\" está funcionando ahora \n Se corrigió el retraso extraño y el salto de los interruptores booleanos",
15+
"pl": "Wydanie poprawki błędu \n Adres hosta jest używany poprawnie, gdy jest podany. \n Kąt oscylacyjny \"Breeze\" teraz działa \n Dziwne opóźnienie i przeskakiwanie przełączników binarnych zostało naprawione",
16+
"zh-cn": "修正版本\n主机地址在给出时正确使用。\nOscillationAngle“微风”现在正在工作\n奇怪的延迟和布尔开关的跳跃是固定的"
17+
},
618
"2.1.2": {
719
"en": "New: Removed NO2 from general AirQuality to be more compliant to dyson-app\n Upd: Code cleanup\n Upd: Removed delay between sending a command and new values getting displayed (max 30 Secs)",
820
"de": "Neu: NO2 aus der allgemeinen AirQuality entfernt, um konformer mit der Dyson-App zu sein\n Upd: Code-Bereinigung\n Upd: Verzögerung zwischen dem Senden eines Befehls und der Anzeige neuer Werte entfernt (max. 30 Sek.)",

main.js

+56-29
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,40 @@ class dysonAirPurifier extends utils.Adapter {
157157
await dysonUtils.getAngles(this, dysonAction, id, state)
158158
.then((result) => {
159159
this.log.debug(`Result of getAngles: ${JSON.stringify(result)}`);
160-
result.ancp = (result.ancp.val==='CUST'? 90 : Number.parseInt(result.ancp.val));
161-
this.log.debug(`Result of parseInt(result.ancp.val): ${result.ancp}, typeof: ${typeof result.ancp }`);
162-
result.osal = Number.parseInt(result.osal.val);
163-
result.osau = Number.parseInt(result.osau.val);
164-
if (result.osal + result.ancp > 355) {
165-
result.osau = 355;
166-
result.osal = 355 - result.ancp;
167-
} else if (result.osau - result.ancp < 5) {
168-
result.osal = 5;
169-
result.osau = 5 + result.ancp;
160+
switch (result.ancp.val) {
161+
case 'CUST': result.ancp = 90;
162+
break;
163+
case 'BRZE':result.ancp = 'BRZE';
164+
break;
165+
default: result.ancp = Number.parseInt(result.ancp.val);
166+
}
167+
if (result.ancp === 'BRZE'){
168+
messageData = {
169+
//['osal']: '0180',
170+
//['osau']: '0180',
171+
['ancp']: 'BRZE',
172+
['oson']: 'ON'
173+
};
170174
} else {
171-
result.osau = result.osal + result.ancp;
175+
this.log.debug(`Result of parseInt(result.ancp.val): ${result.ancp}, typeof: ${typeof result.ancp }`);
176+
result.osal = Number.parseInt(result.osal.val);
177+
result.osau = Number.parseInt(result.osau.val);
178+
if (result.osal + result.ancp > 355) {
179+
result.osau = 355;
180+
result.osal = 355 - result.ancp;
181+
} else if (result.osau - result.ancp < 5) {
182+
result.osal = 5;
183+
result.osau = 5 + result.ancp;
184+
} else {
185+
result.osau = result.osal + result.ancp;
186+
}
187+
messageData = {
188+
['osal']: dysonUtils.zeroFill(result.osal, 4),
189+
['osau']: dysonUtils.zeroFill(result.osau, 4),
190+
['ancp']: 'CUST',
191+
['oson']: 'ON'
192+
};
172193
}
173-
messageData = {
174-
['osal']: dysonUtils.zeroFill(result.osal, 4),
175-
['osau']: dysonUtils.zeroFill(result.osau, 4),
176-
['ancp']: 'CUST',
177-
['oson']: 'ON'
178-
};
179194
})
180195
.catch(() => {
181196
this.log.error('An error occurred while trying to retrieve the oscillation angles.');
@@ -221,12 +236,18 @@ class dysonAirPurifier extends utils.Adapter {
221236
devices[mqttDevice].ProductType + '/' + thisDevice + '/command',
222237
JSON.stringify(message)
223238
);
224-
// refresh data asap to avoid 30 Sec gap
225-
devices[mqttDevice].mqttClient.publish(
226-
devices[mqttDevice].ProductType + '/' + devices[mqttDevice].Serial + '/command', JSON.stringify({
227-
msg: 'REQUEST-CURRENT-STATE',
228-
time: new Date().toISOString()
229-
}));
239+
// refresh data with a delay of 250 ms to avoid 30 Sec gap
240+
/*
241+
setTimeout(() => {
242+
this.log.info('requesting new state of device (' + thisDevice + ').');
243+
devices[mqttDevice].mqttClient.publish(
244+
devices[mqttDevice].ProductType + '/' + thisDevice + '/command', JSON.stringify({
245+
msg: 'REQUEST-CURRENT-STATE',
246+
time: new Date().toISOString()
247+
}));
248+
}, 250);
249+
250+
*/
230251
}
231252
}
232253
}
@@ -348,6 +369,7 @@ class dysonAirPurifier extends utils.Adapter {
348369
this.log.debug('Got Host-Address-object [' + JSON.stringify(hostAddress) + '] for device: ' + device.Serial);
349370
if (hostAddress && hostAddress.val && hostAddress.val !== '') {
350371
this.log.debug('Found valid Host-Address [' + hostAddress.val + '] for device: ' + device.Serial);
372+
device.hostAddress = hostAddress.val;
351373
this.createOrExtendObject(device.Serial + '.Hostaddress', {
352374
type: 'state',
353375
common: {
@@ -371,7 +393,7 @@ class dysonAirPurifier extends utils.Adapter {
371393
'type': 'string'
372394
},
373395
native: {}
374-
}, device.Serial);
396+
}, '');
375397
}
376398
} catch(error){
377399
this.log.error('[CreateOrUpdateDevice] Error: ' + error + ', Callstack: ' + error.stack);
@@ -415,7 +437,7 @@ class dysonAirPurifier extends utils.Adapter {
415437
return;
416438
}
417439
// Handle all other message types
418-
this.log.debug('Processing Message: ' + ((typeof message === 'object')? JSON.stringify(message) : message) );
440+
this.log.debug(`Processing item [${JSON.stringify(row)}] of Message: ${((typeof message === 'object')? JSON.stringify(message) : message)}` );
419441
const deviceConfig = await this.getDatapoint(row);
420442
if ( deviceConfig === undefined){
421443
this.log.debug(`Skipped creating unknown data field for Device:[${device.Serial}], Field: [${row}] Value:[${((typeof( message[row] ) === 'object')? JSON.stringify(message[row]) : message[row])}]`);
@@ -456,8 +478,12 @@ class dysonAirPurifier extends utils.Adapter {
456478
break;
457479
}
458480
} else if (deviceConfig[3]==='boolean' && deviceConfig[5].startsWith('switch')) {
459-
value = (message[deviceConfig[0]] === 'ON' || message[deviceConfig[0]] === 'HUMD');
481+
// testValue should be the 2nd value in an array or if it's no array, the value itself
482+
const testValue = ( typeof message[deviceConfig[0]] === 'object'? message[deviceConfig[0]][1] : message[deviceConfig[0]] );
483+
this.log.debug(`${deviceConfig[1]} is a bool switch. Current state: [${testValue}]`);
484+
value = (testValue === 'ON' || testValue === 'HUMD');
460485
} else {
486+
// It's no bool switch
461487
value = message[deviceConfig[0]];
462488
}
463489
// during state-change message only changed values are being updated
@@ -715,13 +741,14 @@ class dysonAirPurifier extends utils.Adapter {
715741
for (const thisDevice in devices) {
716742
await this.CreateOrUpdateDevice(devices[thisDevice]);
717743
// Initializes the MQTT client for local communication with the thisDevice
718-
if (!devices[thisDevice].hostAddress || devices[thisDevice].hostAddress === '' || devices[thisDevice].hostAddress === 'undefined' || typeof devices[thisDevice].hostAddress === undefined) {
744+
this.log.debug(`Result of CreateOrUpdateDevice: [${JSON.stringify( devices[thisDevice] )}]`);
745+
if (!devices[thisDevice].hostAddress || devices[thisDevice].hostAddress === '' || devices[thisDevice].hostAddress === 'undefined' || typeof devices[thisDevice].hostAddress === 'undefined') {
719746
adapter.log.info('No host address given. Trying to connect to the device with it\'s default hostname [' + devices[thisDevice].Serial + ']. This should work if you haven\'t changed it and if you\'re running a DNS.');
720747
devices[thisDevice].hostAddress = devices[thisDevice].Serial;
721748
}
722749
// subscribe to changes on host address to re-init adapter on changes
723-
this.log.debug('Subscribing for state changes on :' + devices[thisDevice].Serial + '.Hostaddress');
724-
this.subscribeStates(devices[thisDevice].Serial + '.Hostaddress');
750+
this.log.debug('Subscribing for state changes on :' + devices[thisDevice].Serial + '.hostAddress');
751+
this.subscribeStates(devices[thisDevice].Serial + '.hostAddress');
725752
// connect to device
726753
adapterLog.info(`Trying to connect to device [${devices[thisDevice].Serial}] via MQTT on host address [${devices[thisDevice].hostAddress}].`);
727754
devices[thisDevice].mqttClient = mqtt.connect('mqtt://' + devices[thisDevice].hostAddress, {

0 commit comments

Comments
 (0)