Skip to content

Commit

Permalink
0.04
Browse files Browse the repository at this point in the history
  • Loading branch information
hash99 committed Feb 25, 2019
1 parent a19d115 commit 02648cb
Show file tree
Hide file tree
Showing 8 changed files with 375 additions and 278 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ Client_id
### 0.0.3
* (hash99) adapter conform

### 0.0.4
* (hash99) add devices configuration



## Next Steps
Device Integration rdevcie type related Button-Creation
Expand Down
4 changes: 2 additions & 2 deletions io-package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"common": {
"name": "mieleathome",
"version": "0.0.3",
"version": "0.0.4",
"news": {
"0.0.3": {
"en": "initial adapter",
Expand Down Expand Up @@ -34,7 +34,7 @@
"es": "Adaptador de plantilla ioBroker"
},
"authors": [
"Helmut Horras <[email protected]>"
"hash99 <[email protected]>"
],
"platform": "Javascript/Node.js",
"mode": "daemon",
Expand Down
463 changes: 232 additions & 231 deletions main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json
100644 → 100755

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.mieleathome",
"version": "0.0.3",
"version": "0.0.4",
"description": "mieleathome",
"author": {
"name": "hash99",
Expand Down
43 changes: 43 additions & 0 deletions utils/devices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var devices = require("./devices.json");
devices = JSON.stringify(devices);
var devjson = JSON.parse(devices);
class mieledevice {
readProcessAction(dtype) {
var arr = new Array();
var j = 0;
for (var i = 0; i < devjson.devices.length; i++)
{
if (devjson.devices[i].type.includes(dtype)||devjson.devices[i].type.includes('*'))
{
arr[j] = devjson.devices[i].processAction;
j++;
}
}
return arr;
}
readDevice(dtype) {
//console.log('readDevice');
//console.log(devjson);
var arr = new Array();
var j = 0;
//console.log(devjson.devices.length);
for (var i = 0; i < devjson.devices.length; i++)
{
//console.log(devjson.devices[i]);
if (devjson.devices[i].type.includes(dtype)||devjson.devices[i].type.includes('*'))
{
//console.log(devjson.devices[i].type);
//console.log('Lauf' + i + j + arr);
arr[j] = new Array(2);
arr[j][0] = devjson.devices[i].processAction;
arr[j][1] = devjson.devices[i].condition;
arr[j][2] = devjson.devices[i].requestbody;
j++;
}
}
//console.log(arr);
return arr;
}
log() { console.log('Test');}
}
module.exports = mieledevice;
88 changes: 62 additions & 26 deletions utils/devices.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,64 @@
{
"devices": [
{
"processAction": "START",
"type": [1,2,7,24],
"condition": "(fullRemoteControl==true) && (status==4)",
"requestbody": "{\"processAction\":1}"
},
{
"processAction": "STOP",
"type": [ 1,2,7,12,13,17,18,24,31,45,67],
"condition": "((status==4)||(status==5)||(status==6))",
"requestbody": "{\"processAction\":2}"
},
{
"processAction": "PAUSE",
"type": "*",
"condition": "",
"requestbody": "{\"processAction\":3}"
},
{
"processAction": "DEVICENAME",
"type": "*",
"condition": "",
"requestbody": "{\"deviceName\":devicename}"
}
]
"devices": [
{
"type": [1,2,7,24],
"condition": "(fullRemoteControl==true) && (status==4)",
"processAction": "START",
"requestbody": "{\"processAction\":1}"
},
{
"type": [1,2,7,12,13,17,18,24,31,45,67],
"condition": "((status==4)||(status==5)||(status==6))",
"processAction": "STOP",
"requestbody": "{\"processAction\":2}"
},
{
"type": "*",
"condition": "true",
"processAction": "PAUSE",
"requestbody": "{\"processAction\":3}"
},
{
"type": [20,21,68],
"condition": "(status==5)",
"processAction": "START_SUPERFREEZING",
"requestbody": "{\"processAction\":4}"
},
{
"type": [20,21,68],
"condition": "(status==13)||(status==146)",
"processAction": "STOP_SUPERFREEZING",
"requestbody": "{\"processAction\":5}"
},
{
"type": [20,21,68],
"condition": "(status==5)",
"processAction": "START_SUPERCOOLING",
"requestbody": "{\"processAction\":6}"
},
{
"type": [20,21,68],
"condition": "(status==13)||(status==146)",
"processAction": "STOP_SUPERCOOLING",
"requestbody": "{\"processAction\":7}"
},
{
"type": [17,18,32,33,34,68],
"condition": "(status==5)",
"processAction": "LIGHT_ENABLE",
"requestbody": "{\"light\":1}"
},
{
"type": [17,18,32,33,34,68],
"condition": "(status==5)",
"processAction": "LIGHT_DISABLE",
"requestbody": "{\"light\":2}"
},
{
"type": "*",
"condition": "",
"processAction": "DEVICENAME",
"requestbody": "{\"deviceName\":devicename}"
}
]
}
47 changes: 30 additions & 17 deletions utils/mieleathome.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
var request = require("request");
var req_sync = require('sync-request');
var BaseURL = 'https://api.mcs3.miele.com/';
var mieledevice = require('./devices.js');


class mieleathome {

Expand All @@ -17,12 +19,13 @@ class mieleathome {
this.Password = Password;
this.Client_ID = Client_ID;
this.Client_Secret = Client_Secret;
this.device = new mieledevice();
}

log (msg) {
console.log(msg);
}
/*
GetToken (Password,Username,Client_ID,Client_Secret,callback) {
var options = {
url: 'https://api.mcs3.miele.com/thirdparty/token/',
Expand Down Expand Up @@ -137,6 +140,7 @@ class mieleathome {
});
}
*/
//****************************************************************************************
NGetToken(callback) {
var options = {
Expand Down Expand Up @@ -263,6 +267,15 @@ class mieleathome {
return undefined;
}
}
NGetDevicefRCValue(Access_Token,Method,Path,deviceID){
var res = req_sync(Method, BaseURL+Path+deviceID+'/state', {headers: { "Authorization": "Bearer "+Access_Token,
"accept": 'application/json' }, timeout: 60000} );
if (res.statusCode === 200) {
return JSON.parse(res.getBody('utf-8')).remoteEnable.fullRemoteControl;
} else {console.log(res.statusCode);
return undefined;
}
}

NSetLightEnable(Refresh_Token,Access_Token,deviceID,callback){
var path = 'v1/devices/' + deviceID + '/actions';
Expand Down Expand Up @@ -300,25 +313,25 @@ class mieleathome {
}

}
NSetStart(Refresh_Token,Access_Token,deviceID,callback){
NSetProcessAction(Refresh_Token,Access_Token,processAction,deviceID,Type,callback){
var status = this.NGetDeviceStatusValue(Access_Token,'GET','v1/devices/',deviceID);
var fullRemoteControl = this.NGetDevicefRCValue(Access_Token,'GET','v1/devices/',deviceID);
var dfunctions = this.device.readDevice(parseFloat(Type));
for ( var i = 0; i<dfunctions.length; i++)
{
//adapter.log.info('Function:' + Pfad + dfunctions[i][0] + dfunctions[i][1] + dfunctions[i][2]);
if (dfunctions[i][0] == processAction) {
if (dfunctions[i][1]) {
var path = 'v1/devices/' + deviceID + '/actions';
var body = {"processAction":1};
var status = this.NGetDeviceStatusValue(Access_Token,'GET','v1/devices/',deviceID);
//console.log('Status-Value'+ status);
if (status == "4"){
/* console.log('status erfüllt');
console.log('Body:'+body);
console.log('Path:'+path);
console.log('rtoken'+Refresh_Token);
console.log('atoken'+Access_Token); */
this.NSendRequest(Refresh_Token,path,'PUT',Access_Token,body,function(err,data,atoken,rtoken){
var body = {"light":2};
this.NSendRequest(Refresh_Token,path,'PUT',Access_Token,body,function(err,data,atoken,rtoken){
if(!err){return callback(err,data,atoken,rtoken)}
});
}
else
{return callback('Status ne 5',null, null, null)
}

}
}
}

}
}

Expand Down

0 comments on commit 02648cb

Please sign in to comment.