Skip to content

Commit

Permalink
Implemented improvements mentioned in review
Browse files Browse the repository at this point in the history
  • Loading branch information
DEV2DEV-DE committed Dec 3, 2023
1 parent cb5fef1 commit 257a442
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 120 deletions.
4 changes: 0 additions & 4 deletions .commitmessage

This file was deleted.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ https://www.jablotron.com/de/katalog-produktu/alarme/jablotron-100/


## Changelog
### **WORK IN PROGRESS**
* Implemented improvements mentioned in review

### 0.0.2 (2023-11-30)
* Provide an appropriate role for any state
* Readme extended
Expand Down
19 changes: 10 additions & 9 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Jablotron extends utils.Adapter {
const serviceId = service['service-id'];
await this.createChannel(`services.${serviceId}`, `Service ${serviceId}`);
for (const state in service) {
await this.createState(`services.${serviceId}.${state}`, `${state}`, true, false, service[state]);
await this.doCreateState(`services.${serviceId}.${state}`, `${state}`, true, false, service[state]);
}
await this.getSections(headers, cookie, serviceId);
await this.getProgrammableGates(headers, cookie, serviceId);
Expand All @@ -154,7 +154,7 @@ class Jablotron extends utils.Adapter {
* @returns {Promise<void>}
*/
async recurringRefresh() {
this.timeout = setTimeout(() => {
this.timeout = this.setTimeout(() => {
this.log.debug('Fetch data from jablonet.net');
this.getExtendedData(headers, this.sessionId);
this.recurringRefresh();
Expand Down Expand Up @@ -208,11 +208,11 @@ class Jablotron extends utils.Adapter {
const id = sections[section]['cloud-component-id'];
await this.createChannel(`services.${serviceId}.sections.${id}`, `${id}`);
for (const key in sections[section]) {
await this.createState(`services.${serviceId}.sections.${id}.${key}`, `${key}`, true, false, sections[section][key]);
await this.doCreateState(`services.${serviceId}.sections.${id}.${key}`, `${key}`, true, false, sections[section][key]);
}
const state = states.find(state => state['cloud-component-id'] === id);
if (state) { // es wurde ein state zur section gefunden
await this.createState(`services.${serviceId}.sections.${id}.state`, 'state', true, false, state.state);
await this.doCreateState(`services.${serviceId}.sections.${id}.state`, 'state', true, false, state.state);
}
}
} catch (error) {
Expand Down Expand Up @@ -246,10 +246,10 @@ class Jablotron extends utils.Adapter {
const id = gates[gate]['cloud-component-id'];
await this.createChannel(`services.${serviceId}.programmable-gates.${id}`, `${id}`);
for (const key in gates[gate]) {
await this.createState(`services.${serviceId}.programmable-gates.${id}.${key}`, `${key}`, true, false, gates[gate][key]);
await this.doCreateState(`services.${serviceId}.programmable-gates.${id}.${key}`, `${key}`, true, false, gates[gate][key]);
const state = states.find(state => state['cloud-component-id'] === id);
if (state) { // es wurde ein state zum gate gefunden
await this.createState(`services.${serviceId}.programmable-gates.${id}.state`, 'state', true, false, state.state);
await this.doCreateState(`services.${serviceId}.programmable-gates.${id}.state`, 'state', true, false, state.state);
}
}
}
Expand Down Expand Up @@ -318,11 +318,12 @@ class Jablotron extends utils.Adapter {
* @param {boolean} write
* @param {any} value
*/
async createState(id, name, read, write, value) {
let type = undefined;
let role = 'state';
async doCreateState(id, name, read, write, value) {
let type = '';
let role = '';
switch (typeof (value)) {
case 'object': type = 'object';
role = 'json';
value = JSON.stringify(value);
break;
case 'string': type = 'string';
Expand Down
Loading

0 comments on commit 257a442

Please sign in to comment.