Skip to content

Commit

Permalink
fixed lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hb9tvk committed Jun 16, 2024
1 parent ba94fdb commit c560515
Showing 1 changed file with 131 additions and 131 deletions.
262 changes: 131 additions & 131 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const axios = require('axios');
// current poll period: 5min (300000ms)
const UPDATE_PERIOD=300000;
let adapter;
let authToken="";
let gw="";
let authToken='';
let gw='';
let currentComfortTemp=0;
let boilerInterval;

Expand All @@ -39,19 +39,19 @@ function updateState(StateID, value) {
// Main loop, fetch data from boiler
function updateBoiler() {

adapter.log.debug("updateBoiler()");
adapter.log.debug('updateBoiler()');

if (authToken=="") {
adapter.log.debug("Not logged in yet, attempting login");
if (authToken=='') {
adapter.log.debug('Not logged in yet, attempting login');
loginBoiler();
return;
}
if (gw=="") {
if (gw=='') {
adapter.log.debug('Gateway not set yet, waiting...');
return;
}
let url='https://www.ariston-net.remotethermo.com/api/v2/velis/slpPlantData/' +

const url='https://www.ariston-net.remotethermo.com/api/v2/velis/slpPlantData/' +
gw + '?umSys=si';

axios.get(url, {
Expand All @@ -60,35 +60,35 @@ function updateBoiler() {
}
}).then(function (response) {
if (response.status==200) {
adapter.log.debug("Got waterTemp from ariston-net: " + response.data.waterTemp);
adapter.log.debug('Got waterTemp from ariston-net: ' + response.data.waterTemp);
// update state with values received from API
updateState("ariston-remotethermo.0.boiler.waterTemp", response.data.waterTemp);
updateState("ariston-remotethermo.0.boiler.comfortTemp", response.data.comfortTemp);
updateState("ariston-remotethermo.0.boiler.mode", response.data.mode);
updateState("ariston-remotethermo.0.boiler.opMode", response.data.opMode);
updateState("ariston-remotethermo.0.boiler.boostOn", response.data.boostOn);
updateState("ariston-remotethermo.0.boiler.hpState", response.data.hpState);
updateState("ariston-remotethermo.0.boiler.on", response.data.on);
updateState('ariston-remotethermo.0.boiler.waterTemp', response.data.waterTemp);
updateState('ariston-remotethermo.0.boiler.comfortTemp', response.data.comfortTemp);
updateState('ariston-remotethermo.0.boiler.mode', response.data.mode);
updateState('ariston-remotethermo.0.boiler.opMode', response.data.opMode);
updateState('ariston-remotethermo.0.boiler.boostOn', response.data.boostOn);
updateState('ariston-remotethermo.0.boiler.hpState', response.data.hpState);
updateState('ariston-remotethermo.0.boiler.on', response.data.on);
} else if (response.status==405) {
adapter.log.info("updateBoiler(): Authentication expired, re-login");
loginBoiler();
} else {
adapter.log.error("updateBoiler(): Unexpected HTTP response code: " + response.status);
}
})
.catch(function (error) {
if (error.response.status==429) {
var secs=error.response.data.match(/\d+/)[0];
adapter.log.info(`updateBoiler(): Got throttled ${secs} seconds`);
adapter.log.debug(`updateBoiler(): Rescheduling updateBoiler ${secs} seconds`);
setTimeout(() => { updateBoiler(); },(parseInt(secs)+1)*1000);
} else if (error.response.status==405) {
adapter.log.info("updateBoiler(): Authentication expired, re-login 2");
adapter.log.info('updateBoiler(): Authentication expired, re-login');
loginBoiler();
} else {
adapter.log.error("updateBoiler(): Unexpected HTTP response code: " + error.response.status);
adapter.log.error('updateBoiler(): Unexpected HTTP response code: ' + response.status);
}
})
.catch(function (error) {
if (error.response.status==429) {
const secs=error.response.data.match(/\d+/)[0];
adapter.log.info(`updateBoiler(): Got throttled ${secs} seconds`);
adapter.log.debug(`updateBoiler(): Rescheduling updateBoiler ${secs} seconds`);
setTimeout(() => { updateBoiler(); },(parseInt(secs)+1)*1000);
} else if (error.response.status==405) {
adapter.log.info('updateBoiler(): Authentication expired, re-login 2');
loginBoiler();
} else {
adapter.log.error('updateBoiler(): Unexpected HTTP response code: ' + error.response.status);
}
});
}

function getGateway() {
Expand All @@ -103,155 +103,155 @@ function getGateway() {
if (response.status==200) {
gw=response.data[0].gw;
adapter.log.info(`Got GatewayID: ${gw}`);
adapter.setStateAsync("ariston-remotethermo.0.boiler.gw",
adapter.setStateAsync('ariston-remotethermo.0.boiler.gw',

Check failure on line 106 in main.js

View workflow job for this annotation

GitHub Actions / check-and-lint

Trailing spaces not allowed
{val: response.data[0].gw, ack: true});
// everything's ready now, fetch status from API
updateBoiler();
} else {
adapter.log.error("getGateway(): Unexpected HTTP return code " + response.status);
adapter.log.error('getGateway(): Unexpected HTTP return code ' + response.status);
}
}).catch(function (error) {
if (error.response.status==429) {
var secs=error.response.data.match(/\d+/)[0];
const secs=error.response.data.match(/\d+/)[0];
adapter.log.info(`getGateway(): Got throttled ${secs} seconds`);
adapter.log.debug(`Rescheduling getGateway ${secs} seconds`);
setTimeout(() => { getGateway(); },(parseInt(secs)+1)*1000);
} else {
adapter.log.error("getGateway(): Unexpected HTTP return code " + response.status);
adapter.log.error('getGateway(): Unexpected HTTP return code ' + error.response.status);
}
})
});
}

function updateComfortTemp(newTemp) {

if (gw=="") return;
if (gw=='') return;

let update={
"new": {
"comfort": newTemp,
"reduced": 0.0
const update={
'new': {
'comfort': newTemp,
'reduced': 0.0
},
"old": {
"comfort": currentComfortTemp,
"reduced": 0.0
'old': {
'comfort': currentComfortTemp,
'reduced': 0.0
}
};

let url="https://www.ariston-net.remotethermo.com/api/v2/velis/slpPlantData/" +
gw + "/temperatures?umSys=si";
const url='https://www.ariston-net.remotethermo.com/api/v2/velis/slpPlantData/' +
gw + '/temperatures?umSys=si';
axios.post(url, update, {headers: {'Ar.authtoken': authToken}})
.then(function (response) {
if (response.status==200) {
adapter.log.info("Update comfortTemp successful");
adapter.setStateAsync("ariston-remotethermo.0.boiler.comfortTemp",
{ack: true});
}
})
.catch(function (error) {
if (error.response.status==429) {
var secs=error.response.data.match(/\d+/)[0];
adapter.log.info(`updateComfortTemp(): Got throttled ${secs} seconds`);
adapter.log.debug(`updateComfortTemp(): Rescheduling ${secs} seconds`);
setTimeout(() => { updateComfortTemp(newTemp);},(parseInt(secs)+1) * 1000);
} else {
adapter.log.error("updateComfortTemp(): Unexpected HTTP return code " + error.response.status);
}
});
.then(function (response) {
if (response.status==200) {
adapter.log.info('Update comfortTemp successful');
adapter.setStateAsync('ariston-remotethermo.0.boiler.comfortTemp',
{ack: true});
currentComfortTemp=newTemp;
}
})
.catch(function (error) {
if (error.response.status==429) {
const secs=error.response.data.match(/\d+/)[0];
adapter.log.info(`updateComfortTemp(): Got throttled ${secs} seconds`);
adapter.log.debug(`updateComfortTemp(): Rescheduling ${secs} seconds`);
setTimeout(() => { updateComfortTemp(newTemp);},(parseInt(secs)+1) * 1000);
} else {
adapter.log.error('updateComfortTemp(): Unexpected HTTP return code ' + error.response.status);
}
});
}

function onOff(target) {

if (gw=="") return;
if (gw=='') return;

adapter.log.debug("OnOff: " + target.toString());
adapter.log.debug('OnOff: ' + target.toString());

let url="https://www.ariston-net.remotethermo.com/api/v2/velis/slpPlantData/" +
gw + "/switch";
const url='https://www.ariston-net.remotethermo.com/api/v2/velis/slpPlantData/' +
gw + '/switch';
axios.post(url, target.toString(), {headers: {'Ar.authtoken': authToken, 'Content-Type': 'application/json'}})
.then(function (response) {
if (response.status==200) {
if (target) {
adapter.log.info("Boiler switched on");
.then(function (response) {
if (response.status==200) {
if (target) {
adapter.log.info('Boiler switched on');
} else {
adapter.log.info('Boiler switched off');
adapter.setStateAsync('ariston-remotethermo.0.boiler.on',
{ack: true});
}
}
})
.catch(function (error) {
if (error.response.status==429) {
const secs=error.response.data.match(/\d+/)[0];
adapter.log.info(`onOff(): Got throttled ${secs} seconds`);
adapter.log.debug(`onOff(): Rescheduling ${secs} seconds`);
setTimeout(() => { onOff(target); },(parseInt(secs)+1) * 1000);
} else {
adapter.log.info("Boiler switched off");
adapter.setStateAsync("ariston-remotethermo.0.boiler.on",
{ack: true});
adapter.log.error('onOff(): Unexpected HTTP return code ' + error.response.status);
}
}
})
.catch(function (error) {
if (error.response.status==429) {
var secs=error.response.data.match(/\d+/)[0];
adapter.log.info(`onOff(): Got throttled ${secs} seconds`);
adapter.log.debug(`onOff(): Rescheduling ${secs} seconds`);
setTimeout(() => { onOff(target); },(parseInt(secs)+1) * 1000);
} else {
adapter.log.error("onOff(): Unexpected HTTP return code " + error.response.status);
}
});
});
}

function boost(target) {
if (gw=="") return;

let state="false";
if (target=true) state="true";
if (gw=='') return;

let url="https://www.ariston-net.remotethermo.com/api/v2/velis/slpPlantData/" +
gw + "/boost";
let state='false';
if (target==true) state='true';

const url='https://www.ariston-net.remotethermo.com/api/v2/velis/slpPlantData/' +
gw + '/boost';
axios.post(url, state, {headers: {'Ar.authtoken': authToken}})
.then(function (response) {
if (response.status==200) {
if (target)
adapter.log.info("Boiler boost on");
else
adapter.log.info("Boiler boost off");
adapter.setStateAsync("ariston-remotethermo.0.boiler.boostOn",
.then(function (response) {
if (response.status==200) {
if (target)
adapter.log.info('Boiler boost on');
else
adapter.log.info('Boiler boost off');
adapter.setStateAsync('ariston-remotethermo.0.boiler.boostOn',
{ack: true});
}
})
.catch(function (error) {
if (error.response.status==429) {
var secs=error.response.data.match(/\d+/)[0];
adapter.log.info(`boost(): Got throttled ${secs} seconds`);
adapter.log.debug(`boost(): Rescheduling ${secs} seconds`);
setTimeout(() => {boost(target);},(parseInt(secs)+1) * 1000);
} else {
adapter.log.error("boost(): Unexpected HTTP return code " + error.response.status);
}
});
}
})
.catch(function (error) {
if (error.response.status==429) {
const secs=error.response.data.match(/\d+/)[0];
adapter.log.info(`boost(): Got throttled ${secs} seconds`);
adapter.log.debug(`boost(): Rescheduling ${secs} seconds`);
setTimeout(() => {boost(target);},(parseInt(secs)+1) * 1000);
} else {
adapter.log.error('boost(): Unexpected HTTP return code ' + error.response.status);
}
});
}

function loginBoiler() {

if (adapter.config.password=="" || adapter.config.email=="") {
adapter.log.error("Login Data missing...");
if (adapter.config.password=='' || adapter.config.email=='') {
adapter.log.error('Login Data missing...');
return;
}

axios.post('https://www.ariston-net.remotethermo.com/api/v2/accounts/login', {
usr: adapter.config.email,
pwd: adapter.config.password,
imp: false,
notTrack: true,
appInfo: {
os: 2,
appVer: "5.6.772.40151",
appId: "com.remotethermo.aristonnet"
}
})
.then(function (response) {
if (response.status==200 && 'token' in response.data) {
adapter.log.info("Login Successful, got token");
authToken=response.data.token;
// now fetch gateway ID
getGateway();
appVer: '5.6.772.40151',
appId: 'com.remotethermo.aristonnet'
}
})
.catch(function (error) {
adapter.log.error("boost(): Unexpected HTTP return code " + error.response.status);

});
.then(function (response) {
if (response.status==200 && 'token' in response.data) {
adapter.log.info('Login Successful, got token');
authToken=response.data.token;
// now fetch gateway ID
getGateway();
}
})
.catch(function (error) {
adapter.log.error('boost(): Unexpected HTTP return code ' + error.response.status);
});
}

/**
Expand Down Expand Up @@ -282,14 +282,14 @@ function startAdapter(options) {
if (state) {
// The state was changed
adapter.log.debug(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
if (id == "ariston-remotethermo.0.boiler.comfortTemp" && state.ack == false) {
if (id == 'ariston-remotethermo.0.boiler.comfortTemp' && state.ack == false) {
adapter.log.info(`New comfort temp requested: ${state.val}`);
updateComfortTemp(state.val);
}
if (id == "ariston-remotethermo.0.boiler.on" && state.ack == false) {
if (id == 'ariston-remotethermo.0.boiler.on' && state.ack == false) {
onOff(state.val);
}
if (id == "ariston-remotethermo.0.boiler.boostOn" && state.ack == false) {
if (id == 'ariston-remotethermo.0.boiler.boostOn' && state.ack == false) {
boost(state.val);
}
} else {
Expand Down

0 comments on commit c560515

Please sign in to comment.