Skip to content

Commit 56822ba

Browse files
authored
Merge pull request #280 from Grizzelbee/development
v3.1.9
2 parents f91697b + d876be8 commit 56822ba

9 files changed

+102
-17
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ Thumbs.db
1212

1313
# i18n intermediate files
1414
admin/i18n/flat.txt
15-
admin/i18n/*/flat.txt
15+
admin/i18n/*/flat.txt
16+
17+
# ioBroker dev-server
18+
.dev-server/

.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# exclude all dot-files and directories
2+
.*
3+
14
.git
25
.idea
36
node_modules/

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,17 @@ All states report whether there is a failure or not. `True` means a failure, `fa
185185

186186
### **WORK IN PROGRESS**
187187

188+
### 3.1.9 (2024-05-13) (Marching on)
189+
190+
- (arcticon) Fix: [#278](https://github.com/Grizzelbee/ioBroker.dysonairpurifier/issues/278) Changeable fields are working again.
191+
188192
### 3.1.8 (2024-05-10) (Marching on)
189193

190194
- (arcticon) Upd: Dependencies got updated
191195
- (grizzelbee) Chg: code refactoring
192196
- (arcticon) Chg: code refactoring
193-
- (arcticon) Chg: [#273](https://github.com/Grizzelbee/ioBroker.dysonairpurifier/issues/273) Performance improvements
194-
- (arcticon) Chg: [#274](https://github.com/Grizzelbee/ioBroker.dysonairpurifier/issues/274) Update of outdated certificate
197+
- (arcticon) Chg: [#273](https://github.com/Grizzelbee/ioBroker.dysonairpurifier/issues/273) Performance improvements
198+
- (arcticon) Chg: [#274](https://github.com/Grizzelbee/ioBroker.dysonairpurifier/issues/274) Update of outdated certificate
195199

196200
### 3.1.7 (2024-04-24) (Marching on)
197201

dyson-utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ module.exports.deleteUnusedFields = async function (self, device) {
407407
if (!err && oldObj) {
408408
self.log.info(`Deleting deprecated field: ${id}`);
409409
self.delObject(id);
410+
} else {
411+
self.log.debug(`deprecated field: ${id} not found - nothing to do.`);
410412
}
411413
});
412414
}

dysonConstants.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ const datapoints = new Map([
772772
writeable: true, // TODO: Should this be writable?
773773
role: 'value',
774774
unit: '',
775-
displayValues: { '0675': 'Hard', '1350': 'Medium', '2025': 'Soft' }
775+
displayValues: { '0675': 'Hard', 1350: 'Medium', 2025: 'Soft' }
776776
}
777777
],
778778
[
@@ -1413,11 +1413,24 @@ function getDatapoint(searchValue) {
14131413
return datapoints.get(searchValue);
14141414
}
14151415

1416+
const nameToDysoncodeTranslation = new Map(
1417+
Array.from(datapoints.entries()).map(([key, { name }]) => [name, key])
1418+
);
1419+
1420+
/**
1421+
* @param {string} name - name to search for.
1422+
* @returns {string | undefined} returns the dyson code
1423+
*/
1424+
function getNameToDysoncodeTranslation(name) {
1425+
return nameToDysoncodeTranslation.get(name);
1426+
}
1427+
14161428
module.exports = {
14171429
API_BASE_URI,
14181430
HTTP_HEADERS,
14191431
PRODUCTS,
14201432
FIELDSTODELETE,
14211433
SPECIAL_PROPERTIES,
1422-
getDatapoint
1434+
getDatapoint,
1435+
getNameToDysoncodeTranslation
14231436
};

dysonConstants.test.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
const { expect } = require('chai');
4+
5+
const {
6+
getDatapoint,
7+
getNameToDysoncodeTranslation
8+
} = require('./dysonConstants');
9+
10+
describe('dysonConstants', () => {
11+
describe('getDatapoint', () => {
12+
context('given a dyson code', () => {
13+
it('returns the corresponding datapoint', () => {
14+
const datapoint = getDatapoint('fpwr');
15+
expect(datapoint).to.be.an('object');
16+
});
17+
});
18+
context('given a non dyson code', () => {
19+
it('returns undefined', () => {
20+
const datapoint = getDatapoint('MainPower');
21+
expect(datapoint).to.equal(undefined);
22+
});
23+
});
24+
});
25+
26+
describe('getNameToDysoncodeTranslation', () => {
27+
context('given a dyson code', () => {
28+
it('returns undefined', () => {
29+
const datapoint = getNameToDysoncodeTranslation('fpwr');
30+
expect(datapoint).to.equal(undefined);
31+
});
32+
});
33+
context('given a non dyson code', () => {
34+
it('returns the corresponding dyson code', () => {
35+
const datapoint = getNameToDysoncodeTranslation('MainPower');
36+
expect(datapoint).to.be.a('string');
37+
});
38+
});
39+
});
40+
});

io-package.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
{
22
"common": {
33
"name": "dysonairpurifier",
4-
"version": "3.1.8",
4+
"version": "3.1.9",
55
"news": {
6+
"3.1.9": {
7+
"en": "Changeable fields are working again.",
8+
"de": "Änderbare Felder funktionieren wieder.",
9+
"ru": "Изменяемые поля снова работают.",
10+
"pt": "Os campos alteráveis ​​estão funcionando novamente.",
11+
"nl": "Veranderlijke velden werken weer.",
12+
"fr": "Les champs modifiables fonctionnent à nouveau.",
13+
"it": "I campi modificabili funzionano di nuovo.",
14+
"es": "Los campos modificables están funcionando nuevamente.",
15+
"pl": "Zmienne pola znów działają.",
16+
"uk": "Змінні поля знову працюють.",
17+
"zh-cn": "可变字段再次发挥作用。"
18+
},
619
"3.1.8": {
720
"en": "Dependencies got updated\nCode refactoring\nPerformance improvements\nUpdate of outdated certificate",
821
"de": "Abhängigkeiten wurden aktualisiert\nCode-Refactoring\nLeistungsverbesserungen\nAktualisierung des veralteten Zertifikats",

main.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const dysonUtils = require('./dyson-utils.js');
3737
const {
3838
getDatapoint,
3939
PRODUCTS,
40-
SPECIAL_PROPERTIES
40+
SPECIAL_PROPERTIES,
41+
getNameToDysoncodeTranslation
4142
} = require('./dysonConstants.js');
4243

4344
// Variable definitions
@@ -313,13 +314,16 @@ class dysonAirPurifier extends utils.Adapter {
313314
return;
314315
}
315316

316-
// you can use the ack flag to detect if it is status (true) or command (false)
317-
// get the whole data field array
318-
const ActionData = getDatapoint(action);
319317
// if dysonAction is undefined it's an adapter internal action and has to be handled with the given Name
320318
// pick the dyson internal Action from the result row
321-
const dysonAction = ActionData?.[0] ?? action;
322-
this.log.debug(`onStateChange: Using dysonAction: [${dysonAction}]`);
319+
const dysonAction = getNameToDysoncodeTranslation(action);
320+
if (!dysonAction) {
321+
this.log.warn(`Unknown Dyson Action ${action}`);
322+
return;
323+
}
324+
// you can use the ack flag to detect if it is status (true) or command (false)
325+
// get the whole data field array
326+
const ActionData = getDatapoint(dysonAction);
323327
const value = state.val;
324328
let messageData = await this.#getMessageData(dysonAction, value, id, state);
325329

@@ -328,7 +332,10 @@ class dysonAirPurifier extends utils.Adapter {
328332
// this is to translate between the needed states for ioBroker and the device
329333
// boolean switches are better for visualizations and other adapters like text2command
330334
if (typeof ActionData !== 'undefined') {
331-
if (ActionData[3] === 'boolean' && ActionData[5].startsWith('switch')) {
335+
if (
336+
ActionData.type === 'boolean' &&
337+
ActionData.role.startsWith('switch')
338+
) {
332339
// current state is TRUE!
333340
if (state.val) {
334341
// handle special action "humidification" where ON is not ON but HUME
@@ -800,8 +807,7 @@ class dysonAirPurifier extends utils.Adapter {
800807
? message[dysonCode][1]
801808
: message[dysonCode];
802809
//this.log.debug(`${getDataPointName(deviceConfig)} is a bool switch. Current state: [${testValue}]`);
803-
value =
804-
['ON', 'HUMD', 'HEAT'].includes(testValue); // testValue === 'ON' || testValue === 'HUMD' || testValue === 'HEAT';
810+
value = ['ON', 'HUMD', 'HEAT'].includes(testValue); // testValue === 'ON' || testValue === 'HUMD' || testValue === 'HEAT';
805811
} else if (
806812
deviceConfig.type === 'boolean' &&
807813
deviceConfig.role.startsWith('indicator')
@@ -1513,7 +1519,8 @@ class dysonAirPurifier extends utils.Adapter {
15131519
*/
15141520
onUnload(callback) {
15151521
try {
1516-
for (const thisDevice of devices) {
1522+
for (const DEVICE in devices) {
1523+
const thisDevice = devices[DEVICE];
15171524
clearTimeout(thisDevice.updateIntervalHandle);
15181525
this.log.info(`Cleaned up timeout for ${thisDevice.Serial}.`);
15191526
// todo unsubscribe to any subscribes

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iobroker.dysonairpurifier",
3-
"version": "3.1.8",
3+
"version": "3.1.9",
44
"description": "dyson air purifiers and fans",
55
"author": {
66
"name": "grizzelbee",

0 commit comments

Comments
 (0)