Skip to content

Commit

Permalink
Fix session ID fetching and add extended data
Browse files Browse the repository at this point in the history
retrieval
  • Loading branch information
DEV2DEV-DE committed Nov 27, 2023
1 parent 751174c commit da9bb03
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Jablotron extends utils.Adapter {
*/
async fetchSessionId(username, password) {
try {
const firstStart = !this.sessionId;
const url = `${baseUrl}/userAuthorize.json`;
const data = {
'login': username,
Expand All @@ -83,14 +84,15 @@ class Jablotron extends utils.Adapter {
'Accept': 'application/json',
'Accept-Language': 'en'
};
if (!this.sessionId) this.log.debug('Fetching new session id');
if (firstStart) this.log.debug('Fetching new session id');
const response = await axios.post(url, data, { headers });
if (!this.sessionId) this.log.info('Logged in to jablonet api');
if (firstStart) this.log.info('Logged in to jablonet api');
const cookie = response.headers['set-cookie'];
if (cookie) {
const sessionId = cookie.toString().split(';')[0];
this.log.debug('Session-ID: ' + sessionId);
await this.parseResponse(response.data['data']['service-data']);
// if (firstStart) await this.getExtendedData(headers, response.data['data']['service-data']['service-id']);
return sessionId;
} else {
this.log.error('No session id found');
Expand All @@ -105,6 +107,32 @@ class Jablotron extends utils.Adapter {
}
}

async getExtendedData(headers, serviceId) {
let payload = {
'connect-device': true,
'list-type': 'FULL',
'service-id': serviceId,
'service-states': true
};
headers['Cookie'] = this.sessionId;
let url = `${baseUrl}/JA100/sectionsGet.json`;
let response = await axios.post(url, payload, { headers });
this.log.debug('sectionsGet: ' + JSON.stringify(response.data));
url = `${baseUrl}/JA100/programmableGatesGet.json`;
response = await axios.post(url, payload, { headers });
this.log.debug('programmableGatesGet: ' + JSON.stringify(response.data));
url = `${baseUrl}/JA100/thermoDevicesGet.json`;
response = await axios.post(url, payload, { headers });
this.log.debug('thermoDevicesGet: ' + JSON.stringify(response.data));
payload = {
'list-type': 'EXTENDED',
'visibility': 'DEFAULT'
};
url = `${baseUrl}/JA100/serviceListGet.json`;
response = await axios.post(url, payload, { headers });
this.log.debug('serviceListGet: ' + JSON.stringify(response.data));
}

Check failure on line 134 in main.js

View workflow job for this annotation

GitHub Actions / check-and-lint

Expected indentation of 1 tab but found 0

async getCurrentStatus() {
this.fetchSessionId(this.config.username, this.config.password);
}
Expand Down

0 comments on commit da9bb03

Please sign in to comment.