iobroker.lovelace 4.0.7 → 4.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/io-package.json +5 -5
- package/lib/modules/history.js +48 -3
- package/lib/server.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -471,6 +471,9 @@ After that checkout modified version in `./build` folder. Then.
|
|
|
471
471
|
PLACEHOLDER for next version:
|
|
472
472
|
### **WORK IN PROGRESS**
|
|
473
473
|
-->
|
|
474
|
+
### 4.0.8 (2023-12-12)
|
|
475
|
+
* (Garfonso) re-add legacy history for custom cards
|
|
476
|
+
|
|
474
477
|
### 4.0.7 (2023-12-12)
|
|
475
478
|
* (Garfonso) history should be working again.
|
|
476
479
|
|
|
@@ -485,9 +488,6 @@ After that checkout modified version in `./build` folder. Then.
|
|
|
485
488
|
### 4.0.4 (2023-12-09)
|
|
486
489
|
* (Garfonso) fix: crash
|
|
487
490
|
|
|
488
|
-
### 4.0.3 (2023-12-09)
|
|
489
|
-
* (Garfonso) fix: tests.
|
|
490
|
-
|
|
491
491
|
## License
|
|
492
492
|
|
|
493
493
|
Copyright 2019-2023, bluefox <dogafox@gmail.com>
|
package/io-package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"common": {
|
|
3
3
|
"name": "lovelace",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.8",
|
|
5
5
|
"news": {
|
|
6
|
+
"4.0.8": {
|
|
7
|
+
"en": "re-add legacy history for custom cards",
|
|
8
|
+
"de": "re-add die alten history methoden für benutzerdefinierte karten"
|
|
9
|
+
},
|
|
6
10
|
"4.0.7": {
|
|
7
11
|
"en": "history should be working again.",
|
|
8
12
|
"de": "history sollte wieder funktionieren.",
|
|
@@ -71,10 +75,6 @@
|
|
|
71
75
|
"pl": "naprawa",
|
|
72
76
|
"uk": "виправити: аварійний",
|
|
73
77
|
"zh-cn": "fix:坠落"
|
|
74
|
-
},
|
|
75
|
-
"4.0.1": {
|
|
76
|
-
"en": "fix: hideHeader object is writable",
|
|
77
|
-
"de": "fix: hideHeader-Objekt ist schreibbar"
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
80
|
"title": "Visualization with Lovelace-UI",
|
package/lib/modules/history.js
CHANGED
|
@@ -195,11 +195,25 @@ function sendHistoryResponse(ws, id, historyData, parameters) {
|
|
|
195
195
|
start_time: startTime,
|
|
196
196
|
end_time: endTime
|
|
197
197
|
};
|
|
198
|
-
console.log('Sending history message for ' + JSON.stringify(parameters));
|
|
199
|
-
console.log(JSON.stringify(response, null, 2));
|
|
198
|
+
//console.log('Sending history message for ' + JSON.stringify(parameters));
|
|
199
|
+
//console.log(JSON.stringify(response, null, 2));
|
|
200
200
|
ws.send(JSON.stringify(response));
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
+
/**
|
|
204
|
+
* convert .ts of state e to ISOString with try/catch and now as fallback.
|
|
205
|
+
* @param {state} e
|
|
206
|
+
* @returns {string}
|
|
207
|
+
* @private
|
|
208
|
+
*/
|
|
209
|
+
function _convertStateTStoISOString(e) {
|
|
210
|
+
try {
|
|
211
|
+
return new Date(e.lu || e.lc).toISOString();
|
|
212
|
+
} catch (error) {
|
|
213
|
+
return new Date().toISOString();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
203
217
|
class HistoryModule {
|
|
204
218
|
constructor(options) {
|
|
205
219
|
this.adapter = options.adapter;
|
|
@@ -207,6 +221,36 @@ class HistoryModule {
|
|
|
207
221
|
this.subcribeIdsToParameters = {};
|
|
208
222
|
}
|
|
209
223
|
|
|
224
|
+
async processRequest(req, res) {
|
|
225
|
+
//this.adapter.log.debug(`Get history for ${req.query.filter_entity_id} from ${req.params.start} to ${req.query.end_time} LEGACY`);
|
|
226
|
+
|
|
227
|
+
const entityIDs = req.query.filter_entity_id.split(',').map(id => id.trim());
|
|
228
|
+
const entities = [];
|
|
229
|
+
for (const id of entityIDs) {
|
|
230
|
+
const entity = this.entityData.entityId2Entity[id];
|
|
231
|
+
entities.push(entity || id);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const newResult = await getHistory(this.adapter, entities, new Date(req.params.start).getTime(), new Date(req.query.end_time).getTime(), req.query.noAttributes, req._user || this.adapter.config.defaultUser);
|
|
235
|
+
const oldResult = [];
|
|
236
|
+
for (const [entity_id, states] of Object.entries(newResult)) {
|
|
237
|
+
const entityResult = [];
|
|
238
|
+
for (const state of states) {
|
|
239
|
+
const ts = _convertStateTStoISOString(state);
|
|
240
|
+
entityResult.push({
|
|
241
|
+
entity_id,
|
|
242
|
+
state: String(state.s),
|
|
243
|
+
last_changed: ts,
|
|
244
|
+
last_updated: ts,
|
|
245
|
+
attributes: state.a
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
oldResult.push(entityResult);
|
|
249
|
+
}
|
|
250
|
+
//console.log('Legacy history result: ' + JSON.stringify(oldResult, null, 2));
|
|
251
|
+
res.json(oldResult);
|
|
252
|
+
}
|
|
253
|
+
|
|
210
254
|
//{"type":"history/history_during_period","start_time":"2022-07-08T08:09:12.022Z","end_time":"2022-07-08T09:09:12.022Z","significant_changes_only":false,"include_start_time_state":true,"minimal_response":true,"no_attributes":true,"entity_ids":["binary_sensor.TestFeuerAlarm"],"id":29}
|
|
211
255
|
async processMessage(ws, message) {
|
|
212
256
|
if (message.type && message.type.startsWith('history/')) {
|
|
@@ -255,7 +299,7 @@ class HistoryModule {
|
|
|
255
299
|
return;
|
|
256
300
|
}
|
|
257
301
|
|
|
258
|
-
console.log('Getting history ' + JSON.stringify(message));
|
|
302
|
+
//console.log('Getting history ' + JSON.stringify(message));
|
|
259
303
|
const entities = [];
|
|
260
304
|
for (const id of parameters.entityIds) {
|
|
261
305
|
const entity = this.entityData.entityId2Entity[id];
|
|
@@ -269,6 +313,7 @@ class HistoryModule {
|
|
|
269
313
|
return false;
|
|
270
314
|
}
|
|
271
315
|
|
|
316
|
+
|
|
272
317
|
onStateChange(id, state, websocketServer) {
|
|
273
318
|
if (state) {
|
|
274
319
|
//check if the state update needs to be added to any logbook:
|
package/lib/server.js
CHANGED
|
@@ -1868,6 +1868,9 @@ class WebServer {
|
|
|
1868
1868
|
this._app.use('/lovelace/', express.static(getRootPath()));
|
|
1869
1869
|
this._app.use(express.static(getRootPath()));
|
|
1870
1870
|
|
|
1871
|
+
this._app.get('/api/history/period/:start', async (req, res) => {
|
|
1872
|
+
this._modules.history.processRequest(req, res);
|
|
1873
|
+
});
|
|
1871
1874
|
this._app.get('/api/camera_proxy_stream/:entity_id', async (req, res) => {
|
|
1872
1875
|
this.log.debug(`Get image for ${req.params.entity_id} token=${req.query.token || req.query.signed}`);
|
|
1873
1876
|
try {
|