Skip to content

Commit

Permalink
chore: release v0.4.8
Browse files Browse the repository at this point in the history
bugfix: Device status was partly recognized incorrectly
  • Loading branch information
Xenon-s committed Nov 13, 2020
1 parent d6bac77 commit 692c337
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 42 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ After clicking on "**Save and close**", a folder is now created under *Objects -
- the current state of the device
- the current live consumption (fetched from the *path consumption/energy*) and
- the message to the messengers
- averageConsumption (Can be used as an aid to determine your own threshold values)
- do not disturb (if activated, no messages are sent)
is displayed.
<br>
<br>
Expand Down Expand Up @@ -175,8 +177,11 @@ To find out more about the function, simply read about it here at "**default dev
### __WORK IN PROGRESS__
-->

### 0.4.8 (2020-11-13)
* (xenon-s) bugfix: Device status was partly recognized incorrectly

### 0.4.7 (2020-11-13)
* (xenon-) readme translated into english
* (xenon-s) readme translated into english

### 0.4.6 (2020-11-12)
* (xenon-s) Bugfix index_m
Expand Down
2 changes: 2 additions & 0 deletions README_GER.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ Nachdem nun auf "**Speichern und schliessen**" geklickt wurde, wird unter *Objek
- der aktuelle Zustand des devices
- der aktuelle Live-Verbrauch (wird aus dem *path consumption/energy* geholt) und
- die Nachricht an die Messenger
- averageConsumption (Kann als Hilfe genutzt werden um die eigenen Schwellwerte zu ermitteln)
- do not disturb (wenn aktiviert, werden keine Nachrichten versendet)
angezeigt wird.
<br>
<br>
Expand Down
3 changes: 2 additions & 1 deletion admin/index_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@
whatsapp: obj[i].idWhatsapp,
telegram: obj[i].idTelegram,
autoOff: obj[i].autoOff,
timer: obj[i].idTimer
timer: obj[i].idTimer,
id: obj[i].id
};
};
};
Expand Down
14 changes: 13 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{
"common": {
"name": "device-reminder",
"version": "0.4.7",
"version": "0.4.8",
"news": {
"0.4.8": {
"en": "bugfix: Device status was partly recognized incorrectly",
"de": "Bugfix: Gerätestatus wurde teilweise falsch erkannt",
"ru": "исправление: статус устройства частично распознавался неправильно",
"pt": "correção de bug: o status do dispositivo foi parcialmente reconhecido incorretamente",
"nl": "bugfix: apparaatstatus werd gedeeltelijk onjuist herkend",
"fr": "correction de bogue: l'état de l'appareil a été partiellement reconnu incorrectement",
"it": "bugfix: lo stato del dispositivo è stato parzialmente riconosciuto in modo errato",
"es": "corrección de errores: el estado del dispositivo se reconoció parcialmente incorrectamente",
"pl": "poprawka: stan urządzenia został częściowo rozpoznany nieprawidłowo",
"zh-cn": "错误修正:设备状态被部分错误地识别"
},
"0.4.7": {
"en": "readme translated into english",
"de": "Readme ins Englische übersetzt",
Expand Down
158 changes: 121 additions & 37 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ class Template extends utils.Adapter {
await this.setStateAsync(obj[i].pathLiveConsumption, 0, true);
await this.setStateAsync(obj[i].timeTotal, `00:00:00`, true);
await this.setStateAsync(obj[i].messageDP, ``, true);
await this.setStateAsync(obj[i].averageConsumption, 0, true);
await this.setStateAsync(obj[i].doNotDisturb, false, true);
await this.setStateAsync(obj[i].autoOffDP, obj[i].autoOff, true);
};
};

Expand All @@ -168,10 +171,11 @@ class Template extends utils.Adapter {
* @param {number} endCount
* @param {string | string} statusDevice
* @param {string | number} consumpLive
* @param {string | number} averageConsumption
* @param {string | number} runtime
* @param {string | string} messageDP
*/
constructor(obj, statusDevice, consumpLive, runtime, messageDP, startValue, endValue, startCount, endCount) {
constructor(obj, statusDevice, consumpLive, runtime, messageDP, autoOffDP, averageConsumption, doNotDisturb, objVal) {
// Attribute
// Vorgaben
// DPs
Expand All @@ -184,23 +188,26 @@ class Template extends utils.Adapter {
this.pathLiveConsumption = consumpLive;
this.timeTotal = runtime;
this.messageDP = messageDP;
this.averageConsumption = averageConsumption;
this.doNotDisturb = doNotDisturb;
this.autoOffDP = autoOffDP;
// boolean
this.startMessageSent = false;
this.endMessageSent = false;
this.started = false;
// boolean Benutzervorgaben
this.autoOff = obj.autoOff;
// number
this.verbrauch = null;
this.resultStart = null;
this.resultEnd = null;
this.resultStandby = null;
this.verbrauch = 0;
this.resultStart = 0;
this.resultEnd = 0;
this.resultStandby = 0;
// Verbrauchswerte
this.startValue = startValue;
this.endValue = endValue;
this.startValue = objVal.startVal;
this.endValue = objVal.endVal;
// Zaehler Abbruchbedingungen
this.startCount = startCount;
this.endCount = endCount;
this.startCount = objVal.startCount;
this.endCount = objVal.endCount;
// timeout
this.timeoutMsg = null;
this.startZeit = 0;
Expand Down Expand Up @@ -280,15 +287,19 @@ class Template extends utils.Adapter {
* @param {{ deviceName: string; deviceType: string; enabled: boolean; device.deviceIdName: string; pathConsumption: string; pathSwitch: string; startText: string; endText: string; idTelegram: string; idAlexa: string; idWhatsapp: string; idsayit: array; autoOff: boolean; }} obj
*/
//DPs erstellen
const statusDevice = (`${obj.name}.Zustand`);
const consumpLive = (`${obj.name}.Verbrauch aktuell`);
const runtime = (`${obj.name}.Laufzeit`);
const statusDevice = (`${obj.name}.Status`);
const consumpLive = (`${obj.name}.live consumption`);
const runtime = (`${obj.name}.runtime`);
const messageDP = (`${obj.name}.messageDP`);
const autoOffDP = (`${obj.name}.config.auto Off`);
const averageConsumption = (`${obj.name}.average consumption`);
const doNotDisturb = (`${obj.name}.config.do not disturb`);

//Only displaying data points
await this.setObjectNotExistsAsync(statusDevice, {
type: `state`,
common: {
name: `Zustand ${obj.name}`,
name: `Status ${obj.name}`,
type: `string`,
role: `indicator`,
read: true,
Expand All @@ -299,7 +310,7 @@ class Template extends utils.Adapter {
await this.setObjectNotExistsAsync(consumpLive, {
type: `state`,
common: {
name: `Verbrauch aktuell ${obj.name}`,
name: `live consumption ${obj.name}`,
type: `number`,
role: `indicator`,
unit: `W`,
Expand All @@ -311,7 +322,7 @@ class Template extends utils.Adapter {
await this.setObjectNotExistsAsync(runtime, {
type: `state`,
common: {
name: `Laufzeit ${obj.name}`,
name: `runtime ${obj.name}`,
type: `string`,
role: `indicator`,
read: true,
Expand All @@ -330,6 +341,42 @@ class Template extends utils.Adapter {
},
native: {},
});
await this.setObjectNotExistsAsync(averageConsumption, {
type: `state`,
common: {
name: `average consumption ${obj.name}`,
type: `number`,
role: `indicator`,
unit: `W`,
read: true,
write: false,
},
native: {},
});

//Adjustable data points
// await this.setObjectNotExistsAsync(autoOffDP, {
// type: `state`,
// common: {
// name: `auto Off ${obj.name}`,
// type: `boolean`,
// role: `indicator`,
// read: true,
// write: true,
// },
// native: {},
// });
await this.setObjectNotExistsAsync(doNotDisturb, {
type: `state`,
common: {
name: `do not disturb ${obj.name}`,
type: `boolean`,
role: `indicator`,
read: true,
write: true,
},
native: {},
});

// device type ermitteln und Objekt bauen
let devCusType;
Expand Down Expand Up @@ -362,14 +409,15 @@ class Template extends utils.Adapter {
};
};
};
this.log.debug(`RETURN ${JSON.stringify(objVal)}`);

const device = new Geraet(obj, statusDevice, consumpLive, runtime, messageDP, objVal.startVal, objVal.endVal, objVal.startCount, objVal.endCount);
const device = new Geraet(obj, statusDevice, consumpLive, runtime, messageDP, autoOffDP, averageConsumption, doNotDisturb, objVal);
objTemp = device;
arrDevices.push(device);

this.log.debug(`RETURN ${JSON.stringify(objTemp)}`);
this.log.debug(`arrDevices ${JSON.stringify(arrDevices)}`);
this.log.info(`Gerät ${JSON.stringify(objTemp.deviceName)} wurde erfolgreich angelegt`)
this.log.info(`Device ${JSON.stringify(objTemp.deviceName)} was successfully created`)
return objTemp;
};

Expand All @@ -389,15 +437,34 @@ class Template extends utils.Adapter {
const obj = arrObj[id];
const result = await this.getForeignStateAsync(obj.currentConsumption);
obj.verbrauch = result.val;

this.log.debug(`Verbrauchswert Live ${JSON.stringify(obj.verbrauch)} von ${JSON.stringify(obj.deviceName)}`);
this.log.debug(`Wert Verbrauch START: ${JSON.stringify(obj.resultStart)}`);

// confirm data point
let dnd = await this.getStateAsync(obj.doNotDisturb);
dnd = dnd.val;
await this.setStateAsync(obj.doNotDisturb, dnd, true); // Status in DP schreiben;

// device nicht gestartet, Zustand ermitteln wenn autoOff == false
await this.monitoringConsumption(obj)
if (obj.verbrauch <= 0.2) {
this.log.debug(`Verbrauch unter 0,2W`);
await this.monitoringConsumption(obj)
} else if (obj.verbrauch > 0.2 && !obj.started) {
if (obj.verbrauch < obj.startValue) {
await this.setStatus(obj, status = 2);
} else {
this.log.debug(`standby Berechnung abgebrochen`)
obj.arrStandby = [];
await this.setStatus(obj, status = 4);
};
};

// device wurde gestartet
this.log.debug(` WERTE für START${obj.verbrauch}; ${obj.startValue}; ${obj.started}`)
if (obj.verbrauch > obj.startValue && obj.started == false) {
obj.startZeit = Date.now(); // Startzeit loggen
this.log.debug(`STARTWERBERECHNUNG`);
this.calcStart(obj, "start", null); //Startwert berechnen und ueberpruefen
if (obj.resultStart > obj.startValue && obj.resultStart != null && obj.arrStart.length >= obj.startCount && obj.started == false) {
obj.started = true; // Vorgang started
Expand All @@ -409,9 +476,12 @@ class Template extends utils.Adapter {
clearTimeout(obj.timeoutMsg);
obj.timeoutMsg = null;
};
obj.timeoutMsg = setTimeout(async () => { //timeout starten
this.message(obj, "start");
}, 1000);

if (!dnd) {
obj.timeoutMsg = setTimeout(async () => { //timeout starten
this.message(obj, "start");
}, 1000);
};
};
obj.startMessageSent = true; // startMessage wurde versendet
obj.endMessageSent = false; // Ende Benachrichtigung freigeben
Expand All @@ -422,11 +492,12 @@ class Template extends utils.Adapter {
} else if (obj.verbrauch < (obj.startCount / 2) && obj.arrStart.length != 0 && obj.started == false) { // Wert mind > obj.startCount/2 & arrStart nicht leer und nicht started, sonst `Abbruch`
obj.arrStart = []; // array wieder leeren
this.log.debug(`Startphase abgebrochen, array Start wieder geloescht`);
await this.setStatus(obj, status = 2);
// await this.setStatus(obj, status = 2);
};

// device läuft, Live Verbrauch berechnen
if (obj.started) { // wurde geraet started?
this.log.debug(`ENDWERTBERECHNUNG`);
await this.calcStart(obj, "end", null); // endeberechnung durchfuehren
};
this.log.debug(`in Betrieb? Name: ${JSON.stringify(obj.deviceName)} Ergebnis ENDE: ${JSON.stringify(obj.resultEnd)} Wert ENDE: ${JSON.stringify(obj.endValue)} started: ${JSON.stringify(obj.started)} Arraylength: ${JSON.stringify(obj.arrEnd.length)} Zaehler Arr Ende: ${JSON.stringify(obj.endCount)} `);
Expand All @@ -453,10 +524,12 @@ class Template extends utils.Adapter {
clearTimeout(obj.timeoutMsg);
obj.timeoutMsg = null;
};
obj.timeoutMsg = setTimeout(async () => { //timeout starten
this.message(obj, "end");
this.log.debug(`${obj.endMessageText}`);
}, 1000);
if (!dnd) {
obj.timeoutMsg = setTimeout(async () => { //timeout starten
this.message(obj, "end");
this.log.debug(`${obj.endMessageText}`);
}, 1000);
};
};
obj.endMessageSent = true;
obj.startMessageSent = false;
Expand All @@ -465,7 +538,7 @@ class Template extends utils.Adapter {
};

async monitoringConsumption(obj) {
const val = 20;
const val = 10;
await this.calcStart(obj, "standby", val);
this.log.debug(`ERGEBNIS standby: ${obj.resultStandby}, Länge array standby: ${obj.arrStandby.length}`);
if (obj.resultStandby < 0.2 && obj.arrStandby.length >= val) { // verbrauch kleiner Vorgabe, Gerät wurde von Hand ausgeschaltet
Expand All @@ -481,10 +554,6 @@ class Template extends utils.Adapter {
// clear all arrays
obj.arrStart = [];
obj.arrEnd = [];
} else if (obj.resultStandby >= 0.2 && obj.arrStandby.length >= val && !obj.started) {
this.log.debug(`standby Berechnung abgebrochen`)
obj.arrStandby = [];
await this.setStatus(obj, status = 2);
};
};

Expand All @@ -511,15 +580,15 @@ class Template extends utils.Adapter {
this.log.debug(`value status: ${status}`);
switch (status) {
case 0: {
await this.setStateAsync(obj.pathStatus, `ausgeschaltet`, true); // Status in DP schreiben;
await this.setStateAsync(obj.pathStatus, `switched off`, true); // Status in DP schreiben;
break;
};
case 1: {
await this.setStateAsync(obj.pathStatus, `in Betrieb`, true); // Status in DP schreiben
await this.setStateAsync(obj.pathStatus, `in action`, true); // Status in DP schreiben
break;
};
case 2: {
await this.setStateAsync(obj.pathStatus, `Standby`, true); // Status in DP schreiben
await this.setStateAsync(obj.pathStatus, `standby`, true); // Status in DP schreiben
break;
};
case 3: {
Expand All @@ -532,10 +601,15 @@ class Template extends utils.Adapter {
};
await this.setStatus(obj, status = 0);
break;
}
default:
await this.setStateAsync(obj.pathStatus, `Initialisiere`, true); // Status in DP schreiben
};
case 4: {
await this.setStateAsync(obj.pathStatus, `initialize`, true); // Status in DP schreiben
break;
};
default: {
await this.setStateAsync(obj.pathStatus, `unknown status`, true); // Status in DP schreiben
break;
};
};
};

Expand All @@ -546,6 +620,8 @@ class Template extends utils.Adapter {
obj.arrStart.push(obj.verbrauch);
obj.resultStart = await this.calculation(obj.resultStart, obj.arrStart);
this.log.debug(`ergebnisTemp start: ${obj.resultStart}`);
await this.setStateAsync(obj.averageConsumption, obj.resultStart, true);
break;
};
case "end": {
obj.arrEnd.push(obj.verbrauch);
Expand All @@ -554,6 +630,8 @@ class Template extends utils.Adapter {
if (obj.arrEnd.length > obj.endCount) {
obj.arrEnd.shift();
};
await this.setStateAsync(obj.averageConsumption, obj.resultEnd, true);
break;
};
case "standby": {
obj.arrStandby.push(obj.verbrauch);
Expand All @@ -562,6 +640,12 @@ class Template extends utils.Adapter {
if (obj.arrStandby.length > valCount) {
obj.arrStandby.shift();
};
await this.setStateAsync(obj.averageConsumption, obj.resultStandby, true);
break;
};
default: {
this.log.warn(`Calculation could not be completed. Input is wrong. Report this to the developer`);
break;
};
};
};
Expand Down
Loading

0 comments on commit 692c337

Please sign in to comment.