Hallo zusammen,
ich möchte das Thema mal wieder aus der Versenkung holen:
Durch Zufall habe ich mitbekommen, das es mittlerweile auch ein NPM Package der Library gibt. (https://www.npmjs.com/package/sucks)
Doch leider hielt sich mein Erfolg damit zu hantieren wieder einmal Stark in Grenzen.
Ich bin recht einfach vorgegangen: Sucks, node-machine-id sowie xmpp als zusätzliche NPM Pakete im JS Adapter angegeben. Anschließend ein neues Script angelegt und mit folgendem Code befüllt und auch angepasst:
const sucks = require('sucks')
, EcoVacsAPI = sucks.EcoVacsAPI
, VacBot = sucks.VacBot
, nodeMachineId = require('node-machine-id')
, http = require('http')
, countries = sucks.countries;
let account_id = "email@domain.com"
, password = "a1b2c3d4"
, password_hash = EcoVacsAPI.md5(password)
, device_id = EcoVacsAPI.md5(nodeMachineId.machineIdSync())
, country = null
, continent = null;
httpGetJson('http://ipinfo.io/json').then((json) => {
country = json['country'].toLowerCase();
continent = countries[country.toUpperCase()].continent.toLowerCase();
let api = new EcoVacsAPI(device_id, country, continent);
api.connect(account_id, password_hash).then(() => {
api.devices().then((devices) => {
let vacuum = devices[0];
let vacbot = new VacBot(api.uid, EcoVacsAPI.REALM, api.resource, api.user_access_token, vacuum, continent);
vacbot.on("ready", (event) => {
vacbot.run("batterystate");
vacbot.on("BatteryInfo", (battery) => {
console.log("Battery level: %d\%", Math.round(battery*100));
});
});
vacbot.connect_and_wait_until_ready();
});
}).catch((e) => {
console.error("Failure in connecting!");
});
});
function httpGetJson(url) {
return new Promise((resolve, reject) => {
http.get(url, (res) => {
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => { rawData += chunk; });
res.on('end', function(){
try {
const json = JSON.parse(rawData);
resolve(json);
} catch (e) {
reject(e);
}
});
}).on('error', (e) => {
reject(e);
});
});
}
Doch leider bekam ich lediglich diverse Fehlermeldungen sowie einen ewig neustartenden JS-Adapter. Bei Bedarf kann ich die Logs gerne mal posten.