mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
fix bug in masks
This commit is contained in:
@@ -442,7 +442,7 @@ const emsesp_devicedata_1 = {
|
|||||||
{
|
{
|
||||||
v: '(0)',
|
v: '(0)',
|
||||||
u: 0,
|
u: 0,
|
||||||
id: '08error code',
|
id: '08my custom error code',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: '14:54:39 06/06/2021',
|
v: '14:54:39 06/06/2021',
|
||||||
@@ -923,58 +923,60 @@ rest_server.post(EMSESP_DEVICEENTITIES_ENDPOINT, (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function updateMask(entity, de, dd) {
|
function updateMask(entity, de, dd) {
|
||||||
new_mask = parseInt(entity.slice(0, 2), 16)
|
const current_mask = parseInt(entity.slice(0, 2), 16)
|
||||||
const shortname_with_customname = entity.slice(2)
|
const shortname_with_customname = entity.slice(2)
|
||||||
const shortname = shortname_with_customname.split('|')[0]
|
const shortname = shortname_with_customname.split('|')[0]
|
||||||
const new_custom_name = shortname_with_customname.split('|')[1]
|
const new_custom_name = shortname_with_customname.split('|')[1]
|
||||||
|
|
||||||
// find in de
|
// find in de
|
||||||
de_objIndex = de.findIndex((obj) => obj.id == shortname)
|
de_objIndex = de.findIndex((obj) => obj.id === shortname)
|
||||||
if (de_objIndex !== -1) {
|
if (de_objIndex !== -1) {
|
||||||
// find in dd, either looking for fullname or custom name
|
|
||||||
if (de[de_objIndex].cn) {
|
if (de[de_objIndex].cn) {
|
||||||
fullname = de[de_objIndex].cn
|
fullname = de[de_objIndex].cn
|
||||||
} else {
|
} else {
|
||||||
fullname = de[de_objIndex].n
|
fullname = de[de_objIndex].n
|
||||||
}
|
}
|
||||||
dd_objIndex = dd.data.findIndex((obj) => obj.id.slice(2) == fullname)
|
|
||||||
|
// find in dd, either looking for fullname or custom name
|
||||||
|
dd_objIndex = dd.data.findIndex((obj) => 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.data[dd_objIndex].id.slice(0, 2), 16)
|
||||||
if (old_mask !== new_mask) {
|
if (old_mask !== current_mask) {
|
||||||
console.log('mask has changed')
|
|
||||||
new_mask = entity.slice(0, 2)
|
|
||||||
changed = true
|
changed = true
|
||||||
|
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.data[dd_objIndex].cn
|
||||||
if (old_custom_name !== new_custom_name) {
|
if (old_custom_name !== new_custom_name) {
|
||||||
console.log('name has changed')
|
|
||||||
changed = true
|
changed = true
|
||||||
new_fullname = new_custom_name
|
new_fullname = new_custom_name
|
||||||
|
console.log('name has changed to ' + new_custom_name)
|
||||||
} else {
|
} else {
|
||||||
new_fullname = fullname
|
new_fullname = fullname
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
console.log('Updating ' + dd.data[dd_objIndex].id + ' -> ' + new_mask + new_fullname)
|
console.log(
|
||||||
de[de_objIndex].m = new_mask
|
'Updating ' + dd.data[dd_objIndex].id + ' -> ' + current_mask.toString(16).padStart(2, '0') + new_fullname,
|
||||||
|
)
|
||||||
|
de[de_objIndex].m = current_mask
|
||||||
de[de_objIndex].cn = new_fullname
|
de[de_objIndex].cn = new_fullname
|
||||||
dd.data[dd_objIndex].id = new_mask + new_fullname
|
dd.data[dd_objIndex].id = current_mask.toString(16).padStart(2, '0') + new_fullname
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('dd:')
|
console.log('new dd:')
|
||||||
console.log(dd.data[dd_objIndex])
|
console.log(dd.data[dd_objIndex])
|
||||||
console.log('de:')
|
console.log('new de:')
|
||||||
console.log(de[de_objIndex])
|
console.log(de[de_objIndex])
|
||||||
} else {
|
} else {
|
||||||
console.log('error, not found')
|
console.log('error, dd not found')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("can't locate record for name " + shortname)
|
console.log("can't locate record for shortname " + shortname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user