Skip to content

Commit

Permalink
added object priority and alarm object updates only in case of an new…
Browse files Browse the repository at this point in the history
… alarm or when an alarm was closed
  • Loading branch information
TKnpl committed Jan 28, 2021
1 parent 60b1fc1 commit 6b5c479
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Furthermore please chose an updating interval for calling the API server. 30 sec

## Changelog

### 0.0.7
* (TKnpl) added object 'priority' and 'alarm' object updates only in case of an new alarm or when an alarm was closed

### 0.0.6
* (TKnpl) state handling while active alarm and connection check improved, fixed object types

Expand Down
6 changes: 5 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"common": {
"name": "divera247",
"version": "0.0.6",
"version": "0.0.7",
"news": {
"0.0.7": {
"en": "added object priority and alarm object updates only in case of an new alarm or when an alarm was closed",
"de": "Objekt Priorität/Sonderrechte hinzugefügt und Alarm wird nur noch bei neuem oder Schließung eines Alarms aktualisiert"
},
"0.0.6": {
"en": "state handling while active alarm and connection check improved, fixed object types",
"de": "state handling bei aktivem Alarm und connection check verbessert, Fehler bei Objekttypen behoben"
Expand Down
29 changes: 26 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const axios = require('axios');
const adapterName = require('./package.json').name.split('.').pop();

let lastAlarmId = null;
let lastAlarmStatus = false;

class Divera247 extends utils.Adapter {

Expand Down Expand Up @@ -122,6 +123,19 @@ class Divera247 extends utils.Adapter {
native: {},
});

// Creating the Object 'priority' -> response JSON key 'data.priority'
this.setObjectNotExistsAsync('priority', {
type: 'state',
common: {
name: 'Priorität/Sonderrechte',
type: 'boolean',
role: 'indicator',
read: true,
write: false
},
native: {},
});

// Creating the Object 'lastUpdate' -> current timestamp
this.setObjectNotExistsAsync('lastUpdate', {
type: 'state',
Expand All @@ -136,12 +150,15 @@ class Divera247 extends utils.Adapter {
});

// Initialisation of the states
this.setState('alarm', { val: false, ack: true });
this.setState('title', { val: null, ack: true });
this.setState('text', { val: null, ack: true });
this.setState('address', { val: null, ack: true });
this.setState('lat', { val: null, ack: true });
this.setState('lng', { val: null, ack: true });
this.setState('date', { val: null, ack: true });
this.setState('priority', { val: null, ack: true });
this.setState('lastUpdate', { val: null, ack: true });

// Registration of an interval calling the main function for this adapter
let repeatingFunctionCall = setInterval(() => {
Expand Down Expand Up @@ -215,18 +232,24 @@ class Divera247 extends utils.Adapter {

this.log.debug('Received data from Divera-API (' + response.status + '): ' + JSON.stringify(content));

// Setting the states
this.setState('alarm', { val: content.success, ack: true });
// Setting the update state
this.setState('lastUpdate', { val: Date.now(), ack: true });
// Setting the alarm specific states when a alarm is active and the alarm id is different to the last id

// Setting the alarm specific states when a new alarm is active
if (content.success && lastAlarmId != content.data.id) {
lastAlarmId = content.data.id;
lastAlarmStatus = content.success;
this.setState('alarm', { val: content.success, ack: true });
this.setState('title', { val: content.data.title, ack: true });
this.setState('text', { val: content.data.text, ack: true });
this.setState('address', { val: content.data.address, ack: true });
this.setState('lat', { val: content.data.lat, ack: true });
this.setState('lng', { val: content.data.lng, ack: true });
this.setState('date', { val: content.data.date * 1000, ack: true });
this.setState('priority', { val: content.data.priority, ack: true });
} else if (content.success != lastAlarmStatus) {
lastAlarmStatus = content.success;
this.setState('alarm', { val: content.success, ack: true });
}
}.bind(this)
).catch(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.divera247",
"version": "0.0.6",
"version": "0.0.7",
"description": "Adapter zur Alarmierungssoftware Divera 24/7",
"author": {
"name": "tknpl",
Expand Down

0 comments on commit 6b5c479

Please sign in to comment.