Skip to content

Commit

Permalink
Merge pull request #280 from Grizzelbee/development
Browse files Browse the repository at this point in the history
v3.1.9
  • Loading branch information
Grizzelbee authored May 13, 2024
2 parents f91697b + d876be8 commit 56822ba
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 17 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ Thumbs.db

# i18n intermediate files
admin/i18n/flat.txt
admin/i18n/*/flat.txt
admin/i18n/*/flat.txt

# ioBroker dev-server
.dev-server/
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# exclude all dot-files and directories
.*

.git
.idea
node_modules/
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,17 @@ All states report whether there is a failure or not. `True` means a failure, `fa

### **WORK IN PROGRESS**

### 3.1.9 (2024-05-13) (Marching on)

- (arcticon) Fix: [#278](https://github.com/Grizzelbee/ioBroker.dysonairpurifier/issues/278) Changeable fields are working again.

### 3.1.8 (2024-05-10) (Marching on)

- (arcticon) Upd: Dependencies got updated
- (grizzelbee) Chg: code refactoring
- (arcticon) Chg: code refactoring
- (arcticon) Chg: [#273](https://github.com/Grizzelbee/ioBroker.dysonairpurifier/issues/273) Performance improvements
- (arcticon) Chg: [#274](https://github.com/Grizzelbee/ioBroker.dysonairpurifier/issues/274) Update of outdated certificate
- (arcticon) Chg: [#273](https://github.com/Grizzelbee/ioBroker.dysonairpurifier/issues/273) Performance improvements
- (arcticon) Chg: [#274](https://github.com/Grizzelbee/ioBroker.dysonairpurifier/issues/274) Update of outdated certificate

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

Expand Down
2 changes: 2 additions & 0 deletions dyson-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ module.exports.deleteUnusedFields = async function (self, device) {
if (!err && oldObj) {
self.log.info(`Deleting deprecated field: ${id}`);
self.delObject(id);
} else {
self.log.debug(`deprecated field: ${id} not found - nothing to do.`);
}
});
}
Expand Down
17 changes: 15 additions & 2 deletions dysonConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ const datapoints = new Map([
writeable: true, // TODO: Should this be writable?
role: 'value',
unit: '',
displayValues: { '0675': 'Hard', '1350': 'Medium', '2025': 'Soft' }
displayValues: { '0675': 'Hard', 1350: 'Medium', 2025: 'Soft' }
}
],
[
Expand Down Expand Up @@ -1413,11 +1413,24 @@ function getDatapoint(searchValue) {
return datapoints.get(searchValue);
}

const nameToDysoncodeTranslation = new Map(
Array.from(datapoints.entries()).map(([key, { name }]) => [name, key])
);

/**
* @param {string} name - name to search for.
* @returns {string | undefined} returns the dyson code
*/
function getNameToDysoncodeTranslation(name) {
return nameToDysoncodeTranslation.get(name);
}

module.exports = {
API_BASE_URI,
HTTP_HEADERS,
PRODUCTS,
FIELDSTODELETE,
SPECIAL_PROPERTIES,
getDatapoint
getDatapoint,
getNameToDysoncodeTranslation
};
40 changes: 40 additions & 0 deletions dysonConstants.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

const { expect } = require('chai');

const {
getDatapoint,
getNameToDysoncodeTranslation
} = require('./dysonConstants');

describe('dysonConstants', () => {
describe('getDatapoint', () => {
context('given a dyson code', () => {
it('returns the corresponding datapoint', () => {
const datapoint = getDatapoint('fpwr');
expect(datapoint).to.be.an('object');
});
});
context('given a non dyson code', () => {
it('returns undefined', () => {
const datapoint = getDatapoint('MainPower');
expect(datapoint).to.equal(undefined);
});
});
});

describe('getNameToDysoncodeTranslation', () => {
context('given a dyson code', () => {
it('returns undefined', () => {
const datapoint = getNameToDysoncodeTranslation('fpwr');
expect(datapoint).to.equal(undefined);
});
});
context('given a non dyson code', () => {
it('returns the corresponding dyson code', () => {
const datapoint = getNameToDysoncodeTranslation('MainPower');
expect(datapoint).to.be.a('string');
});
});
});
});
15 changes: 14 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
{
"common": {
"name": "dysonairpurifier",
"version": "3.1.8",
"version": "3.1.9",
"news": {
"3.1.9": {
"en": "Changeable fields are working again.",
"de": "Änderbare Felder funktionieren wieder.",
"ru": "Изменяемые поля снова работают.",
"pt": "Os campos alteráveis ​​estão funcionando novamente.",
"nl": "Veranderlijke velden werken weer.",
"fr": "Les champs modifiables fonctionnent à nouveau.",
"it": "I campi modificabili funzionano di nuovo.",
"es": "Los campos modificables están funcionando nuevamente.",
"pl": "Zmienne pola znów działają.",
"uk": "Змінні поля знову працюють.",
"zh-cn": "可变字段再次发挥作用。"
},
"3.1.8": {
"en": "Dependencies got updated\nCode refactoring\nPerformance improvements\nUpdate of outdated certificate",
"de": "Abhängigkeiten wurden aktualisiert\nCode-Refactoring\nLeistungsverbesserungen\nAktualisierung des veralteten Zertifikats",
Expand Down
27 changes: 17 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const dysonUtils = require('./dyson-utils.js');
const {
getDatapoint,
PRODUCTS,
SPECIAL_PROPERTIES
SPECIAL_PROPERTIES,
getNameToDysoncodeTranslation
} = require('./dysonConstants.js');

// Variable definitions
Expand Down Expand Up @@ -313,13 +314,16 @@ class dysonAirPurifier extends utils.Adapter {
return;
}

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

Expand All @@ -328,7 +332,10 @@ class dysonAirPurifier extends utils.Adapter {
// this is to translate between the needed states for ioBroker and the device
// boolean switches are better for visualizations and other adapters like text2command
if (typeof ActionData !== 'undefined') {
if (ActionData[3] === 'boolean' && ActionData[5].startsWith('switch')) {
if (
ActionData.type === 'boolean' &&
ActionData.role.startsWith('switch')
) {
// current state is TRUE!
if (state.val) {
// handle special action "humidification" where ON is not ON but HUME
Expand Down Expand Up @@ -800,8 +807,7 @@ class dysonAirPurifier extends utils.Adapter {
? message[dysonCode][1]
: message[dysonCode];
//this.log.debug(`${getDataPointName(deviceConfig)} is a bool switch. Current state: [${testValue}]`);
value =
['ON', 'HUMD', 'HEAT'].includes(testValue); // testValue === 'ON' || testValue === 'HUMD' || testValue === 'HEAT';
value = ['ON', 'HUMD', 'HEAT'].includes(testValue); // testValue === 'ON' || testValue === 'HUMD' || testValue === 'HEAT';
} else if (
deviceConfig.type === 'boolean' &&
deviceConfig.role.startsWith('indicator')
Expand Down Expand Up @@ -1513,7 +1519,8 @@ class dysonAirPurifier extends utils.Adapter {
*/
onUnload(callback) {
try {
for (const thisDevice of devices) {
for (const DEVICE in devices) {
const thisDevice = devices[DEVICE];
clearTimeout(thisDevice.updateIntervalHandle);
this.log.info(`Cleaned up timeout for ${thisDevice.Serial}.`);
// todo unsubscribe to any subscribes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.dysonairpurifier",
"version": "3.1.8",
"version": "3.1.9",
"description": "dyson air purifiers and fans",
"author": {
"name": "grizzelbee",
Expand Down

0 comments on commit 56822ba

Please sign in to comment.