Skip to content

Commit c874276

Browse files
Commented 'fox-rio-modify'
Commented the files in the 'fox-rio-modify' folder.
1 parent c01bb36 commit c874276

File tree

4 files changed

+44
-38
lines changed

4 files changed

+44
-38
lines changed

changelog.md

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,7 @@
11
# Changelog
22

33
**Commented Files**
4-
* ./databases/
5-
* device.database.js
6-
* ./fox-devices/
7-
* device.settings.js
8-
* _classes/
9-
* device.class.js
10-
* device-model.class.js
11-
* remote_io/
12-
* advantech.models.js
13-
* moxa.models.js
14-
* remote_io.settings.js
15-
* remote-io-factories.js
16-
* remote-io.index.js
17-
* sonoff.models.js
18-
* node-red-settings.js
19-
* service.main.js
20-
* settings.js
21-
22-
---
23-
24-
**./fox-devices/remote_io/remote-io-factories.js**
25-
* These variables are declared and assigned separately:
26-
* createRemoteIoModule
27-
* storedDeviceObject
28-
* connectedDeviceObject
29-
* registerRemoteIoNodeCallback
30-
* ioSet
31-
* parsedPrefix
32-
* parsedIndex
33-
* registerFunction
34-
35-
---
36-
37-
**./service.main.js - getHealth**
38-
* These variables are declared and assigned separately:
39-
* envFunc
40-
* databaseFunc
41-
* logFunc
4+
* ./fox-rio-modify/
5+
* rm-add-new.js
6+
* rm-delete-existing.js
7+
* rm-update-existing.js

fox-rio-modify/rm-add-new.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1+
// Script adds Remote IO device to database.
2+
3+
14
const rioEntryHelp = require("../fox-custom/rio-entry-help");
25
const rioDeviceStatus = require("../fox-custom/rio-device-status");
36

7+
8+
// Main function.
49
function addNewDeviceEntry(inpDeviceObj, rioDatabase, runDeviceList, addNewCallback)
510
{
11+
// Validate input.
612
rioEntryHelp.checkInputType(inpDeviceObj, function (inpTypeErr, inpTypeRes)
713
{
814
if (inpTypeErr !== null)
915
{
16+
// Input error.
1017
return addNewCallback(inpTypeErr, null);
1118
}
1219
else
1320
{
21+
// Prepare input.
1422
rioEntryHelp.setMaker(inpDeviceObj);
1523
handleDeviceEntryCreation(inpDeviceObj, rioDatabase, runDeviceList, addNewCallback);
1624
}
1725
});
1826
}
1927

2028

29+
30+
// Prepare database entry input.
2131
function handleDeviceEntryCreation(inpDevice, rioDbaseObject, runDevices, entryCreationCallback)
2232
{
2333
var newStoredDevice = rioEntryHelp.createStoredDevice(inpDevice);
@@ -26,30 +36,36 @@ function handleDeviceEntryCreation(inpDevice, rioDbaseObject, runDevices, entryC
2636
{
2737
if (eCreateErr !== null)
2838
{
39+
// Error
2940
return entryCreationCallback(eCreateErr, null);
3041
}
3142
else
3243
{
44+
// Preperation successful.
3345
insertNewDeviceObject(inpDevice, newStoredDevice.modelObject, rioDbaseObject, runDevices, entryCreationCallback);
3446
}
3547
});
3648
}
3749

3850

51+
// Insert entry into database.
3952
function insertNewDeviceObject(origInput, prepInput, rioDbaseObj, runDevListObject, insertNewCallback)
4053
{
4154
rioDbaseObj.createDeviceEntity(prepInput, function (insertEntryErr, insertEntryRes)
4255
{
4356
if (insertEntryErr !== null)
4457
{
58+
// Insert error.
4559
return insertNewCallback(insertEntryErr, null);
4660
}
4761
else if (prepInput.isEnabled === true)
4862
{
63+
// Enable new device.
4964
rioDeviceStatus.enableDevice(insertEntryRes, rioDbaseObj, runDevListObject, insertNewCallback);
5065
}
5166
else
5267
{
68+
// Success without enable.
5369
return insertNewCallback(null, insertEntryRes);
5470
}
5571
});

fox-rio-modify/rm-delete-existing.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Script deletes existing Remote IO device from database.
2+
3+
14
const rioDeviceStatus = require("../fox-custom/rio-device-status");
25

36

@@ -9,10 +12,12 @@ function deleteDeviceEntry(inpDeleteID, inpPerm, rioDatabase, runDeviceList, dro
912
{
1013
if (deleteDeviceErr !== null)
1114
{
15+
// Error.
1216
return dropCallback(deleteDeviceErr, null);
1317
}
1418
else
1519
{
20+
// Successful.
1621
return dropCallback(null, true);
1722
}
1823
});

fox-rio-modify/rm-update-existing.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
// Script updates existing Remote IO device in database.
2+
13
const series = require("run-series");
24
const rioEntryHelp = require("../fox-custom/rio-entry-help");
35
const rioDeviceStatus = require("../fox-custom/rio-device-status");
46

57

8+
9+
// Main function.
610
function updateExistingDeviceEntry(updatedDeviceObj, rioDatabase, runDeviceList, updateExistingCallback)
711
{
12+
// Validate input
813
series(
914
[
1015
rioEntryHelp.checkInputType.bind(null, updatedDeviceObj),
@@ -13,18 +18,25 @@ function updateExistingDeviceEntry(updatedDeviceObj, rioDatabase, runDeviceList,
1318
],
1419
function (existDeviceErr, existDeviceRes)
1520
{
21+
// Validation complete.
1622
if (existDeviceErr !== null)
1723
{
24+
// Error.
1825
return updateExistingCallback(existDeviceErr, null);
1926
}
2027
else
2128
{
29+
// Successful.
2230
handleUpdateCreation(updatedDeviceObj, rioDatabase, runDeviceList, updateExistingCallback);
2331
}
2432
});
2533
}
2634

2735

36+
37+
38+
39+
// Prepare update input.
2840
function handleUpdateCreation(updatedDevice, rioDbaseObject, runDevices, entryCreationCallback)
2941
{
3042
var modifiedStoredDevice = rioEntryHelp.createStoredDevice(updatedDevice);
@@ -33,31 +45,38 @@ function handleUpdateCreation(updatedDevice, rioDbaseObject, runDevices, entryCr
3345
{
3446
if (eCreateErr !== null)
3547
{
48+
// Error.
3649
return entryCreationCallback(eCreateErr, null);
3750
}
3851
else
3952
{
53+
// Successful.
4054
saveDeviceChanges(updatedDevice.id, modifiedStoredDevice.modelObject, rioDbaseObject, runDevices, entryCreationCallback);
4155
}
4256
});
4357
}
4458

4559

60+
// Save device changes.
4661
function saveDeviceChanges(newIdString, newDataObject, rioDbaseObj, runDevListObject, saveCallback)
4762
{
63+
// Call UPDATE.
4864
rioDbaseObj.updateDeviceEntity(newIdString, newDataObject, function (saveChangeErr, saveChangeRes)
4965
{
5066
if (saveChangeErr !== null)
5167
{
68+
// Update error.
5269
return saveCallback(saveChangeErr, null);
5370
}
5471
else if (newDataObject.isEnabled === true)
5572
{
73+
// Refresh device.
5674
rioDeviceStatus.disableDevice(newIdString, runDevListObject);
5775
rioDeviceStatus.enableDevice(newIdString, rioDbaseObj, runDevListObject, saveCallback);
5876
}
5977
else
6078
{
79+
// Disable device.
6180
rioDeviceStatus.disableDevice(newIdString, runDevListObject);
6281
return saveCallback(null, newIdString);
6382
}

0 commit comments

Comments
 (0)