Skip to content

Commit

Permalink
Merge pull request #16 from Grizzelbee/Dev_0.5.1
Browse files Browse the repository at this point in the history
Quick fix: Version 0.5.1
  • Loading branch information
Grizzelbee authored Oct 27, 2020
2 parents cdfd58c + 0a8b846 commit 7161646
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 41 deletions.
7 changes: 5 additions & 2 deletions io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"common": {
"name": "dysonairpurifier",
"version": "0.5.0",
"version": "0.5.1",
"news": {
"0.5.1": {
"en": "bugfix for missing clearTimeout."
},
"0.5.0": {
"en": "enhancements, bugfixes and initial support for heater.",
"de": "Verbesserungen, Bugfixes und anfängliche Unterstützung für die Heizung.",
Expand Down Expand Up @@ -117,7 +120,7 @@
"license": "MIT",
"platform": "Javascript/Node.js",
"main": "main.js",
"icon": "admin/dyson_logo.svg",
"icon": "dyson_logo.svg",
"enabled": true,
"extIcon": "https://github.com/Grizzelbee/ioBroker.dysonairpurifier/blob/master/admin/dyson_logo.svg",
"readme": "https://github.com/Grizzelbee/ioBroker.dysonairpurifier/blob/master/readme.md",
Expand Down
79 changes: 42 additions & 37 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const utils = require('@iobroker/adapter-core');
const axios = require('axios');
const crypto = require('crypto');
const mqtt = require('mqtt');
const {parse, stringify} = require('flatted');
const {stringify} = require('flatted');
const path = require('path');
const https = require('https');
const rootCas = require('ssl-root-cas').create();
Expand All @@ -21,7 +21,7 @@ const adapterName = require('./package.json').name.split('.').pop();

// Variable definitions
let devices=[]; // Array that contains all local devices
const ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
// const ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
const apiUri = 'https://appapi.cp.dyson.com';
const supportedProductTypes = ['358', '438', '455', '469', '475', '520', '527'];
const products = { '358':'Dyson Pure Humidify+Cool',
Expand Down Expand Up @@ -101,24 +101,7 @@ class dysonAirPurifier extends utils.Adapter {
}


/*
* Function zeroFill
* Formats a number as a string with leading zeros
*
* @param number {number} Value thats needs to be filled up with leading zeros
* @param width {number} width of the complete new string incl. number and zeros
*
* @returns The given number filled up with leading zeros to a given width
*/
zeroFill( number, width )
{
width -= number.toString().length;
if ( width > 0 )
{
return new Array( width + (/\./.test( number ) ? 2 : 1) ).join( '0' ) + number;
}
return number + ""; // always return a string
}


/*
* Function onStateChange
Expand Down Expand Up @@ -159,6 +142,7 @@ class dysonAirPurifier extends utils.Adapter {
value = Number(((value*10) + 273.15) * (9/5) + 32).toFixed(2);
break;
}
messageData = {[dysonAction]: this.zeroFill(value, 4)};
break;
}
this.log.info('SENDING this data to device: ' + JSON.stringify(messageData));
Expand All @@ -181,21 +165,6 @@ class dysonAirPurifier extends utils.Adapter {
}
}

/*
* Function getDatapoint
* returns the configDetails for any datapoint
*
* @param searchValue {string} dysonCode to search for.
*/
async getDatapoint( searchValue ){
this.log.debug("getDatapoint("+searchValue+")");
for(let row=0; row < datapoints.length; row++){
if (datapoints[row].find( element => element === searchValue)){
this.log.debug("FOUND: " + datapoints[row]);
return datapoints[row];
}
}
}

/*
* Function CreateOrUpdateDevice
Expand Down Expand Up @@ -290,7 +259,7 @@ class dysonAirPurifier extends utils.Adapter {
this.log.debug('Querying Host-Address of device: ' + device.Serial);
await this.getStateAsync(device.Serial + '.Hostaddress')
.then((state) => {
if (state && state.val != '') {
if (state && state.val !== '') {
this.log.debug('Found valid Host-Address.val [' + state.val + '] for device: ' + device.Serial);
device.hostAddress = state.val;
this.createOrExtendObject(device.Serial + '.Hostaddress', {
Expand Down Expand Up @@ -534,7 +503,7 @@ class dysonAirPurifier extends utils.Adapter {
*/
clearIntervalHandle(updateIntervalHandle){
if (updateIntervalHandle) {
clearInterval(updateIntervalHandle);
clearTimeout(updateIntervalHandle);
return null;
} else {
return updateIntervalHandle;
Expand Down Expand Up @@ -809,6 +778,42 @@ class dysonAirPurifier extends utils.Adapter {
return result;
}

/*
* Function getDatapoint
* returns the configDetails for any datapoint
*
* @param searchValue {string} dysonCode to search for.
*/
async getDatapoint( searchValue ){
this.log.debug("getDatapoint("+searchValue+")");
for(let row=0; row < datapoints.length; row++){
if (datapoints[row].find( element => element === searchValue)){
this.log.debug("FOUND: " + datapoints[row]);
return datapoints[row];
}
}
}

/*
* Function zeroFill
* Formats a number as a string with leading zeros
*
* @param number {number} Value thats needs to be filled up with leading zeros
* @param width {number} width of the complete new string incl. number and zeros
*
* @returns The given number filled up with leading zeros to a given width
*/
zeroFill( number, width )
{
width -= number.toString().length;
if ( width > 0 )
{
return new Array( width + (/\./.test( number ) ? 2 : 1) ).join( '0' ) + number;
}
return number + ""; // always return a string
}


/***********************************************
* dyson API functions *
***********************************************/
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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": "0.5.0",
"version": "0.5.1",
"description": "ioBroker Adapter for dyson air purifiers and fans",
"author": {
"name": "Hanjo Hingsen",
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ Then stop the adapter, place the IP into field Hostaddress and restart the adapt
### known issues:
* No automatic IP detection of devices

### 0.5.1 (2020-10-27) (Heart of the hurricance)
* (grizzelbee) Fix: Added missing clearTimeout


### 0.5.0 (2020-10-27) (Heart of the hurricance)
* (grizzelbee) Fix: [#13](https://github.com/Grizzelbee/ioBroker.dysonairpurifier/issues/13) - Filter life value is now displayed in percent not in hours
Expand Down

0 comments on commit 7161646

Please sign in to comment.