update test data for dashboard

This commit is contained in:
proddy
2024-10-11 22:00:39 +01:00
parent e36f6db59d
commit 38f42445aa

View File

@@ -4351,7 +4351,6 @@ router
t: element.t, t: element.t,
nodes: getDashboardEntityData(id) nodes: getDashboardEntityData(id)
}; };
// only add to dashboard if we have values // only add to dashboard if we have values
if ((dashboard_object.nodes ?? []).length > 0) { if ((dashboard_object.nodes ?? []).length > 0) {
dashboard_data.push(dashboard_object); dashboard_data.push(dashboard_object);
@@ -4374,7 +4373,7 @@ router
sensor_data = emsesp_sensordata.ts.map((item, index) => ({ sensor_data = emsesp_sensordata.ts.map((item, index) => ({
id: DeviceTypeUniqueID.TEMPERATURESENSOR_UID * 100 + index, id: DeviceTypeUniqueID.TEMPERATURESENSOR_UID * 100 + index,
dv: { dv: {
id: item.n, id: '00' + item.n,
v: item.t, // value is called t in ts (temperature) v: item.t, // value is called t in ts (temperature)
u: item.u u: item.u
} }
@@ -4395,12 +4394,11 @@ router
sensor_data = sensor_data.map((item, index) => ({ sensor_data = sensor_data.map((item, index) => ({
id: DeviceTypeUniqueID.ANALOGSENSOR_UID * 100 + index, id: DeviceTypeUniqueID.ANALOGSENSOR_UID * 100 + index,
dv: { dv: {
id: item.n, id: '00' + item.n,
v: item.v, v: item.v,
u: item.u u: item.u
} }
})); }));
dashboard_object = { dashboard_object = {
id: DeviceTypeUniqueID.ANALOGSENSOR_UID, id: DeviceTypeUniqueID.ANALOGSENSOR_UID,
t: DeviceType.ANALOGSENSOR, t: DeviceType.ANALOGSENSOR,
@@ -4417,9 +4415,10 @@ router
let scheduler_data2 = scheduler_data.map((item, index) => ({ let scheduler_data2 = scheduler_data.map((item, index) => ({
id: DeviceTypeUniqueID.SCHEDULER_UID * 100 + index, id: DeviceTypeUniqueID.SCHEDULER_UID * 100 + index,
dv: { dv: {
id: item.name, id: '00' + item.name,
v: item.active v: item.active ? 'on' : 'off',
// u: item.u // don't need uom c: item.name,
l: ['off', 'on']
} }
})); }));
dashboard_object = { dashboard_object = {
@@ -4431,22 +4430,39 @@ router
if ((dashboard_object.nodes ?? []).length > 0) { if ((dashboard_object.nodes ?? []).length > 0) {
dashboard_data.push(dashboard_object); dashboard_data.push(dashboard_object);
} }
//
} else { } else {
// for testing // for testing only
// single object
const element = emsesp_coredata.devices[3]; // pick the 4th device // add the custom entity data
const id = element.id;
dashboard_object = { dashboard_object = {
id: id, id: DeviceTypeUniqueID.CUSTOM_UID, // unique ID for custom entities
n: element.n, t: DeviceType.CUSTOM,
t: element.t, nodes: getDashboardEntityData(99)
nodes: getDashboardEntityData(id)
}; };
// only add to dashboard if we have values
if ((dashboard_object.nodes ?? []).length > 0) {
dashboard_data.push(dashboard_object);
}
let scheduler_data = emsesp_schedule.schedule.filter((item) => item.name);
let scheduler_data2 = scheduler_data.map((item, index) => ({
id: DeviceTypeUniqueID.SCHEDULER_UID * 100 + index,
dv: {
id: '00' + item.name,
v: item.active ? 'on' : 'off',
c: item.name,
l: ['off', 'on']
}
}));
dashboard_object = {
id: DeviceTypeUniqueID.SCHEDULER_UID,
t: DeviceType.SCHEDULER,
nodes: scheduler_data2
};
// only add to dashboard if we have values
if ((dashboard_object.nodes ?? []).length > 0) { if ((dashboard_object.nodes ?? []).length > 0) {
dashboard_data.push(dashboard_object); dashboard_data.push(dashboard_object);
} }
console.log('dashboard_data: ', dashboard_data);
} }
// console.log('dashboard_data: ', dashboard_data); // console.log('dashboard_data: ', dashboard_data);
@@ -4498,24 +4514,6 @@ router
// Scheduler // Scheduler
.post(EMSESP_SCHEDULE_ENDPOINT, async (request: any) => { .post(EMSESP_SCHEDULE_ENDPOINT, async (request: any) => {
const content = await request.json(); const content = await request.json();
// check if we're changing active from the Dashboard
if (content.schedule.id === 0) {
console.log(
"Toggle schedule '" +
content.schedule.name +
"' to " +
content.schedule.active
);
// find the schedule in emsesp_schedule via the name and toggle the active
const objIndex = emsesp_schedule.schedule.findIndex(
(obj) => obj.name === content.schedule.name
);
if (objIndex !== -1) {
emsesp_schedule.schedule[objIndex].active = content.schedule.active;
}
return status(200);
}
emsesp_schedule = content; emsesp_schedule = content;
console.log('schedule saved', emsesp_schedule); console.log('schedule saved', emsesp_schedule);
return status(200); return status(200);
@@ -4557,6 +4555,10 @@ router
const value = content.v; const value = content.v;
const id = content.id; const id = content.id;
console.log(
'write device value, id: ' + id + ' command: ' + command + ' value: ' + value
);
var objIndex; var objIndex;
if (id === 1) { if (id === 1) {
objIndex = emsesp_devicedata_1.nodes.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_1.nodes.findIndex((obj) => obj.c == command);
@@ -4598,16 +4600,27 @@ router
objIndex = emsesp_devicedata_10.nodes.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_10.nodes.findIndex((obj) => obj.c == command);
emsesp_devicedata_10.nodes[objIndex].v = value; emsesp_devicedata_10.nodes[objIndex].v = value;
} }
if (id === 99) { if (id === DeviceTypeUniqueID.CUSTOM_UID) {
// custom entities // custom entities
objIndex = emsesp_devicedata_99.nodes.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_99.nodes.findIndex((obj) => obj.c == command);
emsesp_devicedata_99.nodes[objIndex].v = value; emsesp_devicedata_99.nodes[objIndex].v = value;
} }
if (id === DeviceTypeUniqueID.SCHEDULER_UID) {
// toggle scheduler
// find the schedule in emsesp_schedule via the name and toggle the active
const objIndex = emsesp_schedule.schedule.findIndex(
(obj) => obj.name === command
);
if (objIndex !== -1) {
emsesp_schedule.schedule[objIndex].active = value;
console.log("Toggle schedule '" + command + "' to " + value);
}
}
// await delay(1000); // wait to show spinner // await delay(1000); // wait to show spinner
console.log( // console.log(
'Device Value updated. command:' + command + ' value:' + value + ' id:' + id // 'Device Value updated. command:' + command + ' value:' + value + ' id:' + id
); // );
return status(200); return status(200);
}) })