updated for Dashboard

This commit is contained in:
proddy
2024-10-08 22:50:19 +02:00
parent 1681d99238
commit 59c4866530

View File

@@ -80,22 +80,22 @@ function updateMask(entity: any, de: any, dd: any) {
} }
// find in dd, either looking for fullname or custom name // find in dd, either looking for fullname or custom name
// console.log('looking for ' + fullname + ' in ' + dd.data); // console.log('looking for ' + fullname + ' in ' + dd.nodes);
const dd_objIndex = dd.data.findIndex( const dd_objIndex = dd.nodes.findIndex(
(obj: any) => obj.id.slice(2) === fullname (obj: any) => obj.id.slice(2) === fullname
); );
if (dd_objIndex !== -1) { if (dd_objIndex !== -1) {
let changed = new Boolean(false); let changed = new Boolean(false);
// see if the mask has changed // see if the mask has changed
const old_mask = parseInt(dd.data[dd_objIndex].id.slice(0, 2), 16); const old_mask = parseInt(dd.nodes[dd_objIndex].id.slice(0, 2), 16);
if (old_mask !== current_mask) { if (old_mask !== current_mask) {
changed = true; changed = true;
console.log('mask has changed to ' + current_mask.toString(16)); console.log('mask has changed to ' + current_mask.toString(16));
} }
// see if the custom name has changed // see if the custom name has changed
const old_custom_name = dd.data[dd_objIndex].cn; const old_custom_name = dd.nodes[dd_objIndex].cn;
console.log( console.log(
'comparing names, old (' + 'comparing names, old (' +
old_custom_name + old_custom_name +
@@ -113,8 +113,8 @@ function updateMask(entity: any, de: any, dd: any) {
// see if min or max has changed // see if min or max has changed
// get current min/max values if they exist // get current min/max values if they exist
const current_min = dd.data[dd_objIndex].min; const current_min = dd.nodes[dd_objIndex].min;
const current_max = dd.data[dd_objIndex].max; const current_max = dd.nodes[dd_objIndex].max;
let new_min = current_min; let new_min = current_min;
let new_max = current_max; let new_max = current_max;
if (has_min_max) { if (has_min_max) {
@@ -135,9 +135,9 @@ function updateMask(entity: any, de: any, dd: any) {
if (new_max) { if (new_max) {
de[de_objIndex].ma = new_max; de[de_objIndex].ma = new_max;
} }
dd.data[dd_objIndex].id = dd.nodes[dd_objIndex].id =
current_mask.toString(16).padStart(2, '0') + new_fullname; current_mask.toString(16).padStart(2, '0') + new_fullname;
dd.data[dd_objIndex].cn = new_fullname; dd.nodes[dd_objIndex].cn = new_fullname;
} }
} }
} }
@@ -906,7 +906,7 @@ const activity = {
// 99 - Custom // 99 - Custom
const emsesp_devicedata_1 = { const emsesp_devicedata_1 = {
data: [ nodes: [
{ {
v: '22(816) 01.05.2023 13:07 (1 min)', v: '22(816) 01.05.2023 13:07 (1 min)',
u: 0, u: 0,
@@ -1350,7 +1350,7 @@ const emsesp_devicedata_1 = {
}; };
const emsesp_devicedata_2 = { const emsesp_devicedata_2 = {
data: [ nodes: [
{ {
v: '(0)', v: '(0)',
u: 0, u: 0,
@@ -1364,7 +1364,7 @@ const emsesp_devicedata_2 = {
{ {
v: 18.2, v: 18.2,
u: 1, u: 1,
id: '00Chosen Room Temperature', id: '08Chosen Room Temperature',
c: 'hc1/seltemp', c: 'hc1/seltemp',
m: 5, m: 5,
x: 52, x: 52,
@@ -1373,7 +1373,7 @@ const emsesp_devicedata_2 = {
{ {
v: 22.6, v: 22.6,
u: 1, u: 1,
id: '00hc1 current room temperature' id: '08hc1 current room temperature'
}, },
{ {
v: 'auto', v: 'auto',
@@ -1393,7 +1393,7 @@ const emsesp_devicedata_2 = {
}; };
const emsesp_devicedata_3 = { const emsesp_devicedata_3 = {
data: [ nodes: [
{ {
v: '', v: '',
u: 0, u: 0,
@@ -1889,7 +1889,7 @@ const emsesp_devicedata_3 = {
}; };
const emsesp_devicedata_4 = { const emsesp_devicedata_4 = {
data: [ nodes: [
{ {
v: 16, v: 16,
u: 1, u: 1,
@@ -1905,7 +1905,7 @@ const emsesp_devicedata_4 = {
{ {
v: 'off', v: 'off',
u: 0, u: 0,
id: '02hc2 mode', id: '03hc2 mode',
c: 'hc2/mode', c: 'hc2/mode',
l: ['off', 'on', 'auto'] l: ['off', 'on', 'auto']
} }
@@ -1913,7 +1913,7 @@ const emsesp_devicedata_4 = {
}; };
const emsesp_devicedata_5 = { const emsesp_devicedata_5 = {
data: [ nodes: [
{ {
v: 30, v: 30,
u: 1, u: 1,
@@ -1960,7 +1960,7 @@ const emsesp_devicedata_5 = {
}; };
const emsesp_devicedata_6 = { const emsesp_devicedata_6 = {
data: [ nodes: [
{ {
v: 43.9, v: 43.9,
u: 1, u: 1,
@@ -2109,7 +2109,7 @@ const emsesp_devicedata_6 = {
}; };
const emsesp_devicedata_7 = { const emsesp_devicedata_7 = {
data: [ nodes: [
{ v: '', u: 0, id: '08reset', c: 'reset', l: ['-', 'maintenance', 'error'] }, { v: '', u: 0, id: '08reset', c: 'reset', l: ['-', 'maintenance', 'error'] },
{ v: 'off', u: 0, id: '08heating active' }, { v: 'off', u: 0, id: '08heating active' },
{ v: 'off', u: 0, id: '04tapwater active' }, { v: 'off', u: 0, id: '04tapwater active' },
@@ -2252,7 +2252,7 @@ const emsesp_devicedata_7 = {
}; };
const emsesp_devicedata_8 = { const emsesp_devicedata_8 = {
data: [ nodes: [
{ {
v: '', v: '',
u: 0, u: 0,
@@ -2292,22 +2292,22 @@ const emsesp_devicedata_8 = {
id: '00heating pump modulation' id: '00heating pump modulation'
}, },
{ {
v: 30.299999237060547, v: 30.29,
u: 1, u: 1,
id: '00outside temperature' id: '00outside temperature'
}, },
{ {
v: 18.700000762939453, v: 18.7,
u: 1, u: 1,
id: '00current flow temperature' id: '00current flow temperature'
}, },
{ {
v: 21.399999618530273, v: 21.39,
u: 1, u: 1,
id: '00return temperature' id: '00return temperature'
}, },
{ {
v: 18.700000762939453, v: 18.7,
u: 1, u: 1,
id: '00low loss header' id: '00low loss header'
}, },
@@ -2592,7 +2592,7 @@ const emsesp_devicedata_8 = {
id: '00brine out/condenser' id: '00brine out/condenser'
}, },
{ {
v: 21.399999618530273, v: 21.39,
u: 1, u: 1,
id: '00heat carrier return (TC0)' id: '00heat carrier return (TC0)'
}, },
@@ -2607,12 +2607,12 @@ const emsesp_devicedata_8 = {
id: '00condenser temperature (TC3)' id: '00condenser temperature (TC3)'
}, },
{ {
v: 51.599998474121094, v: 51.59,
u: 1, u: 1,
id: '00compressor temperature (TR1)' id: '00compressor temperature (TR1)'
}, },
{ {
v: 14.600000381469727, v: 14.6,
u: 1, u: 1,
id: '00refrigerant temperature liquid side (condenser output) (TR3)' id: '00refrigerant temperature liquid side (condenser output) (TR3)'
}, },
@@ -2622,32 +2622,32 @@ const emsesp_devicedata_8 = {
id: '00evaporator inlet temperature (TR4)' id: '00evaporator inlet temperature (TR4)'
}, },
{ {
v: 20.200000762939453, v: 20.2,
u: 1, u: 1,
id: '00compressor inlet temperature (TR5)' id: '00compressor inlet temperature (TR5)'
}, },
{ {
v: 54.599998474121094, v: 54.59,
u: 1, u: 1,
id: '00compressor outlet temperature (TR6)' id: '00compressor outlet temperature (TR6)'
}, },
{ {
v: 29.600000381469727, v: 29.6,
u: 1, u: 1,
id: '00air inlet temperature (TL2)' id: '00air inlet temperature (TL2)'
}, },
{ {
v: 13.899999618530273, v: 13.89,
u: 1, u: 1,
id: '00low pressure side temperature (PL1)' id: '00low pressure side temperature (PL1)'
}, },
{ {
v: 37.79999923706055, v: 37.79,
u: 1, u: 1,
id: '00high pressure side temperature (PH1)' id: '00high pressure side temperature (PH1)'
}, },
{ {
v: 25.600000381469727, v: 25.6,
u: 1, u: 1,
id: '00drain pan temp (TA4)' id: '00drain pan temp (TA4)'
}, },
@@ -2791,7 +2791,7 @@ const emsesp_devicedata_8 = {
s: '0.1' s: '0.1'
}, },
{ {
v: 0.10000000149011612, v: 0.1,
u: 22, u: 22,
id: '00aux heater limit start', id: '00aux heater limit start',
c: 'auxlimitstart', c: 'auxlimitstart',
@@ -3157,7 +3157,7 @@ const emsesp_devicedata_8 = {
l: ['off', 'on'] l: ['off', 'on']
}, },
{ {
v: 58.70000076293945, v: 58.7,
u: 1, u: 1,
id: '00dhw current intern temperature' id: '00dhw current intern temperature'
}, },
@@ -3226,7 +3226,7 @@ const emsesp_devicedata_8 = {
}; };
const emsesp_devicedata_9 = { const emsesp_devicedata_9 = {
data: [ nodes: [
{ {
v: 24, v: 24,
u: 1, u: 1,
@@ -3255,7 +3255,7 @@ const emsesp_devicedata_9 = {
}; };
const emsesp_devicedata_10 = { const emsesp_devicedata_10 = {
data: [ nodes: [
{ {
v: '26.06.2024 14:49', v: '26.06.2024 14:49',
u: 0, u: 0,
@@ -3744,7 +3744,7 @@ const emsesp_devicedata_10 = {
}; };
const emsesp_devicedata_99 = { const emsesp_devicedata_99 = {
data: [ nodes: [
{ {
v: 5, v: 5,
u: 1, u: 1,
@@ -3944,7 +3944,7 @@ const emsesp_deviceentities_2 = [
v: 18.2, v: 18.2,
n: 'Chosen Room Temperature', n: 'Chosen Room Temperature',
id: 'hc1/seltemp', id: 'hc1/seltemp',
m: 0, m: 8,
mi: 5, mi: 5,
ma: 52, ma: 52,
w: true w: true
@@ -3953,7 +3953,7 @@ const emsesp_deviceentities_2 = [
v: 22.6, v: 22.6,
n: 'hc1 current room temperature', n: 'hc1 current room temperature',
id: 'hc1/curtemp', id: 'hc1/curtemp',
m: 0, m: 8,
w: false w: false
}, },
{ {
@@ -3984,7 +3984,7 @@ const emsesp_deviceentities_4 = [
v: 'off', v: 'off',
n: 'hc2 mode', n: 'hc2 mode',
id: 'hc2/mode', id: 'hc2/mode',
m: 2, m: 3,
w: true w: true
} }
]; ];
@@ -4230,7 +4230,7 @@ function deviceData(id: number) {
} }
if (id == 8) { if (id == 8) {
// test changing the selected flow temp on a Bosch Compress 7000i AW Heat Pump (Boiler/HP) // test changing the selected flow temp on a Bosch Compress 7000i AW Heat Pump (Boiler/HP)
emsesp_devicedata_8.data[4].v = Math.floor(Math.random() * 100); emsesp_devicedata_8.nodes[4].v = Math.floor(Math.random() * 100);
return new Response(encoder.encode(emsesp_devicedata_8), { headers }); return new Response(encoder.encode(emsesp_devicedata_8), { headers });
} }
if (id == 9) { if (id == 9) {
@@ -4296,7 +4296,7 @@ function getDashboardEntityData(id: number) {
// filter device_data on // filter device_data on
// - only add favorite (mask has bit 8 set) except for Custom Entities (type 99) // - only add favorite (mask has bit 8 set) except for Custom Entities (type 99)
let new_data = (device_data as any).data let new_data = (device_data as any).nodes
.filter((item) => id === 99 || parseInt(item.id.slice(0, 2), 16) & 0x08) .filter((item) => id === 99 || parseInt(item.id.slice(0, 2), 16) & 0x08)
.map((item, index) => ({ .map((item, index) => ({
id: id * 100 + index, // mandatory unique id for table id: id * 100 + index, // mandatory unique id for table
@@ -4373,8 +4373,8 @@ router
// add the custom entity data // add the custom entity data
dashboard_object = { dashboard_object = {
id: 99, id: 99, // unique ID for custom entities
n: 'Custom Entities', n: 'Custom Entities', // this is translated in the C++ code
t: 4, // DeviceType::CUSTOM t: 4, // DeviceType::CUSTOM
nodes: getDashboardEntityData(99) nodes: getDashboardEntityData(99)
}; };
@@ -4429,20 +4429,20 @@ router
} else { } else {
// for testing // for testing
// single object // single object
// const element = emsesp_coredata.devices[3]; // pick the 4th device const element = emsesp_coredata.devices[3]; // pick the 4th device
// const id = element.id; const id = element.id;
// dashboard_object = { dashboard_object = {
// id: id, id: id,
// n: element.n, n: element.n,
// t: element.t, t: element.t,
// nodes: getDashboardEntityData(id) nodes: getDashboardEntityData(id)
// }; };
// 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);
// return dashboard_data; // if not using msgpack // return dashboard_data; // if not using msgpack
return new Response(encoder.encode(dashboard_data), { headers }); // msgpack it return new Response(encoder.encode(dashboard_data), { headers }); // msgpack it
}) })
@@ -4524,7 +4524,7 @@ router
}) })
.get(EMSESP_CUSTOMENTITIES_ENDPOINT, () => emsesp_customentities) .get(EMSESP_CUSTOMENTITIES_ENDPOINT, () => emsesp_customentities)
// Device Dashboard // Devices page
.post(EMSESP_WRITE_DEVICEVALUE_ENDPOINT, async (request: any) => { .post(EMSESP_WRITE_DEVICEVALUE_ENDPOINT, async (request: any) => {
const content = await request.json(); const content = await request.json();
const command = content.c; const command = content.c;
@@ -4533,49 +4533,49 @@ router
var objIndex; var objIndex;
if (id === 1) { if (id === 1) {
objIndex = emsesp_devicedata_1.data.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_1.nodes.findIndex((obj) => obj.c == command);
emsesp_devicedata_1.data[objIndex].v = value; emsesp_devicedata_1.nodes[objIndex].v = value;
} }
if (id === 2) { if (id === 2) {
objIndex = emsesp_devicedata_2.data.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_2.nodes.findIndex((obj) => obj.c == command);
emsesp_devicedata_2.data[objIndex].v = value; emsesp_devicedata_2.nodes[objIndex].v = value;
} }
if (id === 3) { if (id === 3) {
objIndex = emsesp_devicedata_3.data.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_3.nodes.findIndex((obj) => obj.c == command);
emsesp_devicedata_3.data[objIndex].v = value; emsesp_devicedata_3.nodes[objIndex].v = value;
} }
if (id === 4) { if (id === 4) {
objIndex = emsesp_devicedata_4.data.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_4.nodes.findIndex((obj) => obj.c == command);
emsesp_devicedata_4.data[objIndex].v = value; emsesp_devicedata_4.nodes[objIndex].v = value;
} }
if (id === 5) { if (id === 5) {
objIndex = emsesp_devicedata_5.data.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_5.nodes.findIndex((obj) => obj.c == command);
emsesp_devicedata_5.data[objIndex].v = value; emsesp_devicedata_5.nodes[objIndex].v = value;
} }
if (id === 6) { if (id === 6) {
objIndex = emsesp_devicedata_6.data.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_6.nodes.findIndex((obj) => obj.c == command);
emsesp_devicedata_6.data[objIndex].v = value; emsesp_devicedata_6.nodes[objIndex].v = value;
} }
if (id === 7) { if (id === 7) {
objIndex = emsesp_devicedata_7.data.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_7.nodes.findIndex((obj) => obj.c == command);
emsesp_devicedata_7.data[objIndex].v = value; emsesp_devicedata_7.nodes[objIndex].v = value;
} }
if (id === 8) { if (id === 8) {
objIndex = emsesp_devicedata_8.data.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_8.nodes.findIndex((obj) => obj.c == command);
emsesp_devicedata_8.data[objIndex].v = value; emsesp_devicedata_8.nodes[objIndex].v = value;
} }
if (id === 9) { if (id === 9) {
objIndex = emsesp_devicedata_9.data.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_9.nodes.findIndex((obj) => obj.c == command);
emsesp_devicedata_9.data[objIndex].v = value; emsesp_devicedata_9.nodes[objIndex].v = value;
} }
if (id === 10) { if (id === 10) {
objIndex = emsesp_devicedata_10.data.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_10.nodes.findIndex((obj) => obj.c == command);
emsesp_devicedata_10.data[objIndex].v = value; emsesp_devicedata_10.nodes[objIndex].v = value;
} }
if (id === 99) { if (id === 99) {
// custom entities // custom entities
objIndex = emsesp_devicedata_99.data.findIndex((obj) => obj.c == command); objIndex = emsesp_devicedata_99.nodes.findIndex((obj) => obj.c == command);
emsesp_devicedata_99.data[objIndex].v = value; emsesp_devicedata_99.nodes[objIndex].v = value;
} }
// await delay(1000); // wait to show spinner // await delay(1000); // wait to show spinner