Skip to content

Commit

Permalink
update db recordings
Browse files Browse the repository at this point in the history
  • Loading branch information
tp1de committed Oct 18, 2023
1 parent f4cb1b9 commit 9b9262f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ English documentation: https://github.com/tp1de/ioBroker.ems-esp/blob/main/doc/e
Placeholder for the next version (at the beginning of the line):
### **WORK IN PROGRESS**
-->
### **WORK IN PROGRESS**
* Update energy statistics and recordings for history and influxdb

### 2.5.1 (2023-10-13)
* correct hourly recordings timestamps for km200 (timezone difference)

Expand Down
11 changes: 10 additions & 1 deletion lib/ems.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,16 @@ async function energy(db,idr,idw,end,intervall,step,t) {
}

} else {
try {await adapter.sendToAsync(db,"storeState", {id: adapt+idw, state: recs});} catch(e) {}

for (let i = 0; i < recs.length;i++){
if (!unloaded ) {
let status;
try {status = await adapter.sendToAsync(db,"update", {id: adapt+idw, state: recs[i]}); } catch(e) {}
if (status.success == false) try {status = await adapter.sendToAsync(db,"storeState", {id: adapt+idw, state: recs[i]});} catch(e) {}
}
}

//try {await adapter.sendToAsync(db,"storeState", {id: adapt+idw, state: recs});} catch(e) {}
}

const v = [];
Expand Down
15 changes: 11 additions & 4 deletions lib/km200.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,24 @@ async function recsw(field,d,t) {
}

if (db.substring(0,8) == "influxdb" ) {
//await adapter.sendToAsync(db,"DELETE FROM '"+adapter.namespace+"."+field + "'"); // only Influxdb < V2

for (let i = 0; i < d.length;i++){
if (!unloaded ) {try {await adapter.sendToAsync(db,"storeState", d[i]);} catch(e) {}}
if (!unloaded ) {
let status;
try {status = await adapter.sendToAsync(db,"update", d[i])} catch(e) {}
if (status.success == false) try {status = await adapter.sendToAsync(db,"storeState", d[i]);} catch(e) {}
}
}
}


if (db.substring(0,7) == "history" ) {
//await adapter.sendToAsync(db,"deleteAll",[{id:field}]);
for (let i = 0; i < d.length;i++){
if (!unloaded ) {try {await adapter.sendToAsync(db,"storeState", d[i]);} catch(e) {} }
if (!unloaded ) {
let status;
try {status = await adapter.sendToAsync(db,"update", d[i])} catch(e) {}
if (status.success == false) try {status = await adapter.sendToAsync(db,"storeState", d[i]);} catch(e) {}
}
}
}

Expand Down

0 comments on commit 9b9262f

Please sign in to comment.