save field values with other save data

This commit is contained in:
sparks-alec
2022-12-11 04:45:12 -05:00
parent 419bf52ebb
commit 72601b3c97
3 changed files with 13 additions and 8 deletions
+7 -6
View File
@@ -49,7 +49,7 @@ function registerDevice(newDevice) {
port: newDevice.port,
addresses: newDevice.addresses,
data: {},
fields: {},
fields: newDevice.fields || {},
pinIndex: false,
lastDrawn: 0,
lastHeartbeat: 0,
@@ -68,13 +68,15 @@ function registerDevice(newDevice) {
devices[id].plugin = PLUGINS.all[newDevice.type];
if(PLUGINS.all[newDevice.type].config.fields){
PLUGINS.all[newDevice.type].config.fields.forEach(field => {
if (
Object.keys(devices[id].fields).length == 0 &&
PLUGINS.all[newDevice.type].config.fields
) {
PLUGINS.all[newDevice.type].config.fields.forEach((field) => {
devices[id].fields[field.key] = field.value;
});
}
VIEW.addDeviceToList(devices[id]);
initDeviceConnection(id);
return true;
@@ -86,7 +88,7 @@ function initDeviceConnection(id) {
infoUpdate(device, 'status', 'new');
if(device.port === undefined){
if (device.port === undefined) {
device.port = device.plugin.config.defaultPort;
}
@@ -138,7 +140,6 @@ function initDeviceConnection(id) {
device.send = (address, args) => {
device.connection.send({ address, args });
};
} else if (plugins[type].config.connectionType === 'TCPsocket') {
device.connection = new net.Socket();