Compare commits

...

1 Commits

Author SHA1 Message Date
Arnaud Nelissen
a1d7a7452a Added "label" to device model 2025-10-08 17:55:22 +02:00
2 changed files with 45 additions and 6 deletions

View File

@@ -14,6 +14,7 @@ const DeviceModel = joi.object({
relayTemperature: joi.number().optional(),
relayConfigurationTimestamp: joi.number().optional(),
vsoft: joi.string().optional(),
label: joi.string().optional(),
inventory: joi.array().items( joi.object({
msn: joi.string().required(),
configurationTimestamp: joi.number().optional(),

View File

@@ -1,6 +1,44 @@
const dbcontroller = require('../db');
const util = require('../util');
const deviceUsesPrograms = function(device) {
switch (device.msn.slice(0,2).toUpperCase() || 'xx') {
case '1F':
case '20':
case '51':
case '53':
case '55':
case '5A':
case '7A': return false;
default: break;
}
if (device.programs != undefined) { return true; }
if (device.programs == undefined && device.slots == undefined) { return true; }
return false;
}
const deviceUsesSlots = function(device) {
switch (device.msn.slice(0,2).toUpperCase() || 'xx') {
case '1F':
case '20':
case '51':
case '53':
case '55':
case '5A':
case '7A': return true;
default: break;
}
if (device.slots != undefined) { return true; }
if (device.programs == undefined && device.slots == undefined) { return true; }
return false;
}
const postRequestToDo = async function (msn, body) {
try {
await dbcontroller.addDevice(body, null)
@@ -30,23 +68,23 @@ const getRequestToDo = async function (msn) {
var todo = { serialNumber : msn }
///// Programs
if (device.programs != undefined) {
if (child.programmingTimestamp != undefined && deviceUsesPrograms(child)) {
timestamp = child.programmingTimestamp || -1
if (timestamp < device.programs.timestamp) { todo.programs = 1 }
if ((device.programs == undefined) || (timestamp < device.programs.timestamp)) { todo.programs = 1 }
else if (timestamp > device.programs.timestamp) { todo.programs = 2 }
}
///// Configuration
if (device.configuration != undefined) {
if (child.configurationTimestamp != undefined) {
timestamp = child.configurationTimestamp || child.relayConfigurationTimestamp || -1
if (timestamp < device.configuration.timestamp) { todo.configuration = 1 }
if ((device.configuration == undefined) || (timestamp < device.configuration.timestamp)) { todo.configuration = 1 }
else if (timestamp > device.configuration.timestamp) { todo.configuration = 2 }
}
///// Slots
if (device.slots != undefined) {
if (child.programmingTimestamp != undefined && deviceUsesSlots(child)) {
timestamp = child.programmingTimestamp || -1
if (timestamp < device.slots.timestamp) { todo.slots = 1 }
if ((device.slots == undefined) || (timestamp < device.slots.timestamp)) { todo.slots = 1 }
else if (timestamp > device.slots.timestamp) { todo.slots = 2 }
}