Skip to content

Commit

Permalink
Adkustments ems-esp 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
tp1de committed Jan 24, 2022
1 parent 2520940 commit ead2241
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions lib/ems.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const request = require("request");

let unloaded = false;

let emsesp,ems_token ="",ems_http_wait = 100, ems_poll_wait,ems_polling = 60;
let emsesp,ems_token ="",ems_http_wait = 100, ems_polling = 60;
let ems_version = "V2";
let km200_structure = true;

Expand Down Expand Up @@ -296,21 +296,6 @@ async function ems_get(url) {return new Promise(function(resolve,reject) {
});
});}

async function ems_apiversion(emsesp) {
let ems_version;
try {const data = await ems_get(emsesp+"/api/system");ems_version = "V3";}catch(error) {ems_version = "V2";}
return(ems_version);
}

async function ems_put(url,value) {
const headers = {"Content-Type": "application/json","Authorization": "Bearer " + ems_token};
const body =JSON.stringify({"value": value});
request.post({url, headers: headers, body}, function(error,response) {
try {const resp= JSON.parse(response.body).message;}
catch(error) {const resp = "";}
return (response);
});
}

async function write_state(statename,value,def) {
if (!unloaded) {
Expand Down Expand Up @@ -462,18 +447,6 @@ async function write_state(statename,value,def) {
}
} catch(e) {}

/*
if (ems_version == "V3") {
let obj = await adapter.getObjectAsync(statename1);
if (obj != undefined) {
if (obj.native.ems_type == "enum") {
for (let iii = 0; iii < obj.native.ems_enum.length;iii++) {
if (obj.native.ems_enum[iii] == value) value = iii; // When field value is returned as text --> transform into number
}
}
}
}
*/
try {
const state = await adapter.getStateAsync(statename1);
if(state == null) {adapter.setState(statename1, {ack: true, val: value});}
Expand Down

0 comments on commit ead2241

Please sign in to comment.