daikin-controller-cloud
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -32,3 +32,5 @@ /** | ||
proxyListenBind: '0.0.0.0', // optional: set this to bind the proxy to a special IP, default is '0.0.0.0' | ||
proxyDataDir: __dirname // Directory to store certificates and other proxy relevant data to | ||
proxyDataDir: __dirname, // Directory to store certificates and other proxy relevant data to | ||
communicationTimeout: 10000, // Amount of ms to wait for request and responses before timeout | ||
communicationRetries: 3 // Amount of retries when connection timed out | ||
}; | ||
@@ -35,0 +37,0 @@ |
@@ -31,3 +31,5 @@ /** | ||
proxyListenBind: '0.0.0.0', // optional: set this to bind the proxy to a special IP, default is '0.0.0.0' | ||
proxyDataDir: process.cwd() // Directory to store certificates and other proxy relevant data to | ||
proxyDataDir: process.cwd(), // Directory to store certificates and other proxy relevant data to | ||
communicationTimeout: 10000, // Amount of ms to wait for request and responses before timeout | ||
communicationRetries: 3 // Amount of retries when connection timed out | ||
}; | ||
@@ -34,0 +36,0 @@ |
112
index.js
@@ -24,2 +24,4 @@ const EventEmitter = require('events'); | ||
* @param {string} [options.logLevel=info] Loglevel to use - in fact only "debug" has a meaning to log some more details | ||
* @param {number} options.communicationTimeout=10000 Timeout in ms for Requests & Responses to Cloud | ||
* @param {number} options.communicationRetries=3 Number of Retries if Authentication Requests timed out | ||
*/ | ||
@@ -38,3 +40,5 @@ constructor(tokenSet, options) { | ||
proxyDataDir: path.join(__dirname), | ||
logger: null | ||
logger: null, | ||
communicationRetries: 3, | ||
communicationTimeout: 10000 | ||
}; | ||
@@ -44,2 +48,8 @@ if (!this.options.logLevel) { | ||
} | ||
if (!this.options.communicationRetries) { | ||
this.options.communicationRetries = 3; | ||
} | ||
if (!this.options.communicationTimeout) { | ||
this.options.communicationTimeout = 10000; | ||
} | ||
@@ -95,2 +105,11 @@ if (tokenSet && !(tokenSet instanceof TokenSet)) { | ||
] | ||
}, | ||
timeout: { | ||
response: this.options.communicationTimeout, | ||
request: this.options.communicationTimeout | ||
}, | ||
retry: { | ||
retries: this.options.communicationRetries, | ||
errorCodes: ['ETIMEDOUT'], | ||
methods: ['GET', 'POST'] | ||
} | ||
@@ -202,2 +221,11 @@ }); | ||
] | ||
}, | ||
timeout: { | ||
response: this.options.communicationTimeout, | ||
request: this.options.communicationTimeout | ||
}, | ||
retry: { | ||
retries: this.options.communicationRetries, | ||
errorCodes: ['ETIMEDOUT'], | ||
methods: ['GET', 'POST'] | ||
} | ||
@@ -331,3 +359,12 @@ }); | ||
const response = await got(this.proxy._generateInitialUrl(), { | ||
followRedirect: false | ||
followRedirect: false, | ||
timeout: { | ||
response: this.options.communicationTimeout, | ||
request: this.options.communicationTimeout | ||
}, | ||
retry: { | ||
retries: this.options.communicationRetries, | ||
errorCodes: ['ETIMEDOUT'], | ||
methods: ['GET', 'POST'] | ||
} | ||
}); | ||
@@ -348,3 +385,14 @@ | ||
try { | ||
const response = await got(location, { followRedirect: false }) | ||
const response = await got(location, { | ||
followRedirect: false, | ||
timeout: { | ||
response: this.options.communicationTimeout, | ||
request: this.options.communicationTimeout | ||
}, | ||
retry: { | ||
retries: this.options.communicationRetries, | ||
errorCodes: ['ETIMEDOUT'], | ||
methods: ['GET', 'POST'] | ||
} | ||
}) | ||
location = response.headers['location']; | ||
@@ -365,3 +413,12 @@ | ||
const body = await got('https://cdns.gigya.com/js/gigya.js', { | ||
searchParams: {'apiKey': '3_xRB3jaQ62bVjqXU1omaEsPDVYC0Twi1zfq1zHPu_5HFT0zWkDvZJS97Yw1loJnTm'} | ||
searchParams: { 'apiKey': '3_xRB3jaQ62bVjqXU1omaEsPDVYC0Twi1zfq1zHPu_5HFT0zWkDvZJS97Yw1loJnTm' }, | ||
timeout: { | ||
response: this.options.communicationTimeout, | ||
request: this.options.communicationTimeout | ||
}, | ||
retry: { | ||
retries: this.options.communicationRetries, | ||
errorCodes: ['ETIMEDOUT'], | ||
methods: ['GET', 'POST'] | ||
} | ||
}).text(); | ||
@@ -383,3 +440,13 @@ let regex = /"(\d+-\d-\d+)"/g | ||
'sdk': 'js_latest', | ||
'format': 'json'} | ||
'format': 'json' | ||
}, | ||
timeout: { | ||
response: this.options.communicationTimeout, | ||
request: this.options.communicationTimeout | ||
}, | ||
retry: { | ||
retries: this.options.communicationRetries, | ||
errorCodes: ['ETIMEDOUT'], | ||
methods: ['GET', 'POST'] | ||
} | ||
}); | ||
@@ -405,3 +472,4 @@ ssoCookies = response.headers['set-cookie']; | ||
'content-type': 'application/x-www-form-urlencoded', | ||
'cookie': cookies}, | ||
'cookie': cookies | ||
}, | ||
searchParams: { | ||
@@ -420,4 +488,14 @@ 'loginID': userName, | ||
'sdkBuild': '12208', | ||
'format': 'json'}, | ||
'format': 'json' | ||
}, | ||
'method': 'POST', | ||
timeout: { | ||
response: this.options.communicationTimeout, | ||
request: this.options.communicationTimeout | ||
}, | ||
retry: { | ||
retries: this.options.communicationRetries, | ||
errorCodes: ['ETIMEDOUT'], | ||
methods: ['GET', 'POST'] | ||
} | ||
}).json(); | ||
@@ -450,2 +528,11 @@ | ||
'cookie': cookies | ||
}, | ||
timeout: { | ||
response: this.options.communicationTimeout, | ||
request: this.options.communicationTimeout | ||
}, | ||
retry: { | ||
retries: this.options.communicationRetries, | ||
errorCodes: ['ETIMEDOUT'], | ||
methods: ['GET', 'POST'] | ||
} | ||
@@ -478,3 +565,12 @@ }).text(); | ||
body: params.toString(), | ||
followRedirect: false | ||
followRedirect: false, | ||
timeout: { | ||
response: this.options.communicationTimeout, | ||
request: this.options.communicationTimeout | ||
}, | ||
retry: { | ||
retries: this.options.communicationRetries, | ||
errorCodes: ['ETIMEDOUT'], | ||
methods: ['GET', 'POST'] | ||
} | ||
}); | ||
@@ -481,0 +577,0 @@ daikinunified = response.headers['location']; |
@@ -32,2 +32,3 @@ /** | ||
Object.keys(obj).forEach(sub => { | ||
if (!sub || !obj[sub]) return; | ||
const subKeys = Object.keys(obj[sub]); | ||
@@ -102,2 +103,11 @@ if (sub === 'meta' || subKeys.includes('value') || subKeys.includes('settable') || subKeys.includes('unit')) { // we found end leaf | ||
/** | ||
* Get the info if device is connected to cloud | ||
* | ||
* @returns {boolean} Connected status | ||
*/ | ||
isCloudConnectionUp() { | ||
return this.desc.isCloudConnectionUp.value; | ||
} | ||
/** | ||
* Get a current data object (includes value and meta information). | ||
@@ -225,2 +235,2 @@ * Without any parameter the full internal data structure is returned and | ||
module.exports = DaikinCloudDevice; | ||
module.exports = DaikinCloudDevice; |
{ | ||
"name": "daikin-controller-cloud", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Interact with Daikin Cloud devices and retrieve Tokens", | ||
@@ -14,10 +14,10 @@ "author": "Apollon77 <iobroker@fischer-ka.de>", | ||
"finalhandler": "^1.1.2", | ||
"got": "^11.8.2", | ||
"got": "^11.8.3", | ||
"http-mitm-proxy": "^0.9.0", | ||
"openid-client": "^4.7.4", | ||
"serve-static": "^1.14.1" | ||
"openid-client": "^4.9.1", | ||
"serve-static": "^1.14.2" | ||
}, | ||
"devDependencies": { | ||
"@alcalzone/release-script": "^2.2.1", | ||
"pkg": "^5.3.1" | ||
"@alcalzone/release-script": "^3.5.2", | ||
"pkg": "^5.5.2" | ||
}, | ||
@@ -24,0 +24,0 @@ "repository": { |
@@ -35,2 +35,11 @@ # daikin-controller-cloud | ||
Calling tokensaver.js without any parameters will open a proxy where you can login to the Daikin Cloud and the tokens will be fetched. | ||
Alternatively execute | ||
`node tokensaver.js "mydaikin@email.com" "my-daikin-password"` | ||
(replace data with your daikin cloud login credentials) and we try to fetch the tokens without the proxy. | ||
## Code-Usage example | ||
@@ -52,2 +61,6 @@ See example folder, check the settings (add your own IP at minimum!) and start it with `node example.js`. | ||
## Changelog: | ||
### 0.2.1 (2022-02-20) | ||
* (uKL) Expose isCloudConnectionUp as own method on device | ||
* (uKL) prevent crash when some data from devices are still null after new addition to cloud | ||
* (DrHauss ) Added timeout and retry to got requests | ||
@@ -54,0 +67,0 @@ ### 0.2.0 (2021-07-30) |
Sorry, the diff of this file is not supported yet
669645
1183
78
Updatedgot@^11.8.3
Updatedopenid-client@^4.9.1
Updatedserve-static@^1.14.2