diff --git a/models/device.model.js b/models/device.model.js index 63b2de7..a228ade 100644 --- a/models/device.model.js +++ b/models/device.model.js @@ -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(), diff --git a/services/device.service.js b/services/device.service.js index 601379c..7795bac 100644 --- a/services/device.service.js +++ b/services/device.service.js @@ -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 } }