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