@kohost/api-client 1.0.0-alpha.1 → 1.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/.eslintrc.js +10 -0
  2. package/bitbucket-pipelines.yml +39 -0
  3. package/commands/Command.js +38 -0
  4. package/commands/SetAlarmCommand.js +21 -0
  5. package/commands/SetCourtesyCommand.js +21 -0
  6. package/commands/SetDimmerCommand.js +21 -0
  7. package/commands/SetLockCommand.js +21 -0
  8. package/commands/SetSceneControllerCommand.js +21 -0
  9. package/commands/SetSwitchCommand.js +21 -0
  10. package/commands/SetThermostatCommand.js +21 -0
  11. package/commands/SetWindowCoveringCommand.js +21 -0
  12. package/commands/VerifyDocumentCommand.js +24 -0
  13. package/commands/index.js +21 -0
  14. package/defs/deviceTypes.js +15 -0
  15. package/defs/formalDeviceTypes.js +6 -0
  16. package/defs/http.js +7 -0
  17. package/defs/index.js +11 -0
  18. package/errors/AppError.js +8 -0
  19. package/errors/AuthenticationError.js +9 -0
  20. package/errors/AuthorizationError.js +9 -0
  21. package/errors/DeviceCommError.js +9 -0
  22. package/errors/LoginError.js +9 -0
  23. package/errors/NotFoundError.js +9 -0
  24. package/errors/RequestError.js +9 -0
  25. package/errors/SystemCommError.js +9 -0
  26. package/errors/TokenExpiredError.js +9 -0
  27. package/errors/UnprocessableRequestError.js +9 -0
  28. package/errors/ValidationError.js +9 -0
  29. package/errors/index.js +15 -0
  30. package/events/Event.js +33 -0
  31. package/events/SystemCameraUpdatedEvent.js +17 -0
  32. package/events/SystemCourtesyUpdatedEvent.js +17 -0
  33. package/events/SystemDimmerUpdatedEvent.js +17 -0
  34. package/events/SystemLockUpdatedEvent.js +17 -0
  35. package/events/SystemReservationUpdatedEvent.js +17 -0
  36. package/events/SystemSceneControllerUpdatedEvent.js +17 -0
  37. package/events/SystemSourceUpdatedEvent.js +17 -0
  38. package/events/SystemSpaceUpdatedEvent.js +17 -0
  39. package/events/SystemSwitchUpdatedEvent.js +17 -0
  40. package/events/SystemThermostatUpdatedEvent.js +17 -0
  41. package/events/SystemUserUpdatedEvent.js +17 -0
  42. package/events/SystemWindowCoveringUpdatedEvent.js +17 -0
  43. package/events/index.js +28 -0
  44. package/http/handleResponseError.js +53 -0
  45. package/http/handleResponseSuccess.js +15 -0
  46. package/http/index.js +159 -0
  47. package/index.js +21 -71
  48. package/models/acl.js +29 -0
  49. package/models/admin/customer.js +28 -0
  50. package/models/admin/property.js +28 -0
  51. package/models/alarm.js +29 -0
  52. package/models/application.js +28 -0
  53. package/models/camera.js +29 -0
  54. package/models/courtesy.js +33 -0
  55. package/models/dimmer.js +49 -0
  56. package/models/discoveredDevice.js +30 -0
  57. package/models/gateway.js +37 -0
  58. package/models/index.js +56 -0
  59. package/models/integration.js +76 -0
  60. package/models/iotGateway.js +29 -0
  61. package/models/kohost.js +95 -0
  62. package/models/lock.js +33 -0
  63. package/models/mediaSource.js +29 -0
  64. package/models/motionSensor.js +29 -0
  65. package/models/reservation.js +36 -0
  66. package/models/room.js +185 -0
  67. package/models/scene.js +28 -0
  68. package/models/sceneController.js +29 -0
  69. package/models/space.js +99 -0
  70. package/models/switch.js +33 -0
  71. package/models/thermostat.js +80 -0
  72. package/models/ticket.js +91 -0
  73. package/models/user.js +58 -0
  74. package/models/windowCovering.js +49 -0
  75. package/package.json +27 -5
  76. package/prepare.js +4 -0
  77. package/schemas/acl.json +111 -0
  78. package/schemas/admin/customer.json +32 -0
  79. package/schemas/admin/property.json +54 -0
  80. package/schemas/alarm.json +5 -5
  81. package/schemas/application.json +24 -0
  82. package/schemas/camera.json +41 -0
  83. package/schemas/courtesy.json +5 -6
  84. package/schemas/definitions/common.json +21 -0
  85. package/schemas/{device.json → definitions/device.json} +22 -4
  86. package/schemas/dimmer.json +8 -5
  87. package/schemas/discoveredDevice.json +43 -0
  88. package/schemas/gateway.json +45 -13
  89. package/schemas/identification.json +35 -0
  90. package/schemas/integration.json +94 -0
  91. package/schemas/iotGateway.json +29 -0
  92. package/schemas/lock.json +8 -5
  93. package/schemas/mediaSource.json +151 -0
  94. package/schemas/motionSensor.json +26 -0
  95. package/schemas/payment.json +38 -0
  96. package/schemas/reservation.json +66 -0
  97. package/schemas/room.json +138 -0
  98. package/schemas/scene.json +118 -0
  99. package/schemas/sceneController.json +18 -6
  100. package/schemas/space.json +111 -0
  101. package/schemas/switch.json +8 -5
  102. package/schemas/thermostat.json +19 -10
  103. package/schemas/ticket.json +82 -0
  104. package/schemas/user.json +124 -0
  105. package/schemas/windowCovering.json +8 -5
  106. package/tests/unit/models/space.test.js +31 -0
  107. package/tests/unit/models/thermostat.test.js +146 -0
  108. package/useCases/http.json +902 -0
  109. package/utils/getDeviceTypes.js +7 -0
  110. package/utils/getFormalDeviceType.js +5 -0
  111. package/utils/schema.js +28 -0
@@ -0,0 +1,30 @@
1
+ // Create the Discovered Device Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/discoveredDevice.json");
4
+
5
+ const Kohost = require("./kohost");
6
+
7
+ schemas.add(schema);
8
+ const validator = schemas.compile(schema);
9
+
10
+ class DiscoveredDevice extends Kohost {
11
+ constructor(data) {
12
+ super(data);
13
+ }
14
+ }
15
+
16
+ Object.defineProperty(DiscoveredDevice.prototype, "schema", {
17
+ value: schema,
18
+ });
19
+
20
+ Object.defineProperty(DiscoveredDevice.prototype, "validator", {
21
+ get: function () {
22
+ return validator;
23
+ },
24
+ });
25
+
26
+ Object.defineProperty(DiscoveredDevice, "validProperties", {
27
+ value: Object.keys(schema.properties),
28
+ });
29
+
30
+ module.exports = DiscoveredDevice;
@@ -0,0 +1,37 @@
1
+ // Create the Gateway Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/gateway.json");
4
+ const Kohost = require("./kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ const { customAlphabet } = require("nanoid/async");
10
+ const characters =
11
+ "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
12
+
13
+ class Gateway extends Kohost {
14
+ constructor(data) {
15
+ super(data);
16
+ }
17
+
18
+ static async generateAuthKey(length = 64) {
19
+ return await customAlphabet(characters, length)();
20
+ }
21
+ }
22
+
23
+ Object.defineProperty(Gateway.prototype, "schema", {
24
+ value: schema,
25
+ });
26
+
27
+ Object.defineProperty(Gateway.prototype, "validator", {
28
+ get: function () {
29
+ return validator;
30
+ },
31
+ });
32
+
33
+ Object.defineProperty(Gateway, "validProperties", {
34
+ value: Object.keys(schema.properties),
35
+ });
36
+
37
+ module.exports = Gateway;
@@ -0,0 +1,56 @@
1
+ const IotGateway = require("./iotGateway");
2
+ const Switch = require("./switch");
3
+ const Alarm = require("./alarm");
4
+ const Dimmer = require("./dimmer");
5
+ const Lock = require("./lock");
6
+ const SceneController = require("./sceneController");
7
+ const Thermostat = require("./thermostat");
8
+ const WindowCovering = require("./windowCovering");
9
+ const User = require("./user");
10
+ const ACL = require("./acl");
11
+ const Courtesy = require("./courtesy");
12
+ const Camera = require("./camera");
13
+ const MotionSensor = require("./motionSensor");
14
+ const MediaSource = require("./mediaSource");
15
+ const Room = require("./room");
16
+ const Reservation = require("./reservation");
17
+ const Application = require("./application");
18
+ const Space = require("./space");
19
+ const Ticket = require("./ticket");
20
+ const Scene = require("./scene");
21
+ const Integration = require("./integration");
22
+ const Gateway = require("./gateway");
23
+ const DiscoveredDevice = require("./discoveredDevice");
24
+
25
+ const AdminCustomer = require("./admin/customer");
26
+ const AdminProperty = require("./admin/property");
27
+
28
+ module.exports = {
29
+ Admin: {
30
+ Customer: AdminCustomer,
31
+ Property: AdminProperty,
32
+ },
33
+ Gateway,
34
+ IotGateway,
35
+ Switch,
36
+ Alarm,
37
+ Dimmer,
38
+ Lock,
39
+ Courtesy,
40
+ Camera,
41
+ SceneController,
42
+ MotionSensor,
43
+ Thermostat,
44
+ WindowCovering,
45
+ MediaSource,
46
+ User,
47
+ ACL,
48
+ Room,
49
+ Application,
50
+ Space,
51
+ Ticket,
52
+ Scene,
53
+ Integration,
54
+ DiscoveredDevice,
55
+ Reservation,
56
+ };
@@ -0,0 +1,76 @@
1
+ // Create the Driver Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/integration.json");
4
+ const Kohost = require("./kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+ class Integration extends Kohost {
9
+ constructor(data) {
10
+ super(data);
11
+ }
12
+ getDriverDeviceId(kohostDeviceId, type) {
13
+ const found = this.deviceMap.get(kohostDeviceId);
14
+ if (found) {
15
+ if (type && found.type === type) return found.id;
16
+ else if (!type) return found.id;
17
+ }
18
+ return null;
19
+ }
20
+
21
+ getDeviceId(driverDeviceId, type) {
22
+ const found = this.driverDeviceMap.get(driverDeviceId);
23
+ if (found) {
24
+ if (type && found.type === type) return found.id;
25
+ else if (!type) return found.id;
26
+ }
27
+ return null;
28
+ }
29
+
30
+ getRoomId(driverDeviceId, type) {
31
+ const found = this.driverDeviceMap.get(driverDeviceId);
32
+ if (found) {
33
+ if (type && found.type === type) return found.roomId;
34
+ else if (!type) return found.roomId;
35
+ }
36
+ return null;
37
+ }
38
+
39
+ getDeviceData(driverDeviceId, type) {
40
+ const found = this.driverDeviceMap.get(driverDeviceId);
41
+ if (found) {
42
+ if (type && found.type === type)
43
+ return { id: found.id, roomId: found.roomId };
44
+ else if (!type) return { id: found.id, roomId: found.roomId };
45
+ }
46
+ return null;
47
+ }
48
+
49
+ get deviceMap() {
50
+ return new Map(Object.entries(this.data?.deviceMap || {}));
51
+ }
52
+
53
+ get driverDeviceMap() {
54
+ const map = new Map();
55
+ for (const [id, value] of Object.entries(this.data?.deviceMap || {})) {
56
+ map.set(value.id, { id, type: value.type, roomId: value.roomId });
57
+ }
58
+ return map;
59
+ }
60
+ }
61
+
62
+ Object.defineProperty(Integration.prototype, "schema", {
63
+ value: schema,
64
+ });
65
+
66
+ Object.defineProperty(Integration.prototype, "validator", {
67
+ get: function () {
68
+ return validator;
69
+ },
70
+ });
71
+
72
+ Object.defineProperty(Integration, "validProperties", {
73
+ value: Object.keys(schema.properties),
74
+ });
75
+
76
+ module.exports = Integration;
@@ -0,0 +1,29 @@
1
+ // Create the Gateway Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/iotGateway.json");
4
+ const Kohost = require("./kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class IotGateway extends Kohost {
10
+ constructor(data) {
11
+ super(data);
12
+ }
13
+ }
14
+
15
+ Object.defineProperty(IotGateway.prototype, "schema", {
16
+ value: schema,
17
+ });
18
+
19
+ Object.defineProperty(IotGateway.prototype, "validator", {
20
+ get: function () {
21
+ return validator;
22
+ },
23
+ });
24
+
25
+ Object.defineProperty(IotGateway, "validProperties", {
26
+ value: Object.keys(schema.properties),
27
+ });
28
+
29
+ module.exports = IotGateway;
@@ -0,0 +1,95 @@
1
+ const { ValidationError } = require("../errors");
2
+ const { customAlphabet: generate } = require("nanoid");
3
+
4
+ class Kohost {
5
+ constructor(data) {
6
+ if (!this.schema) {
7
+ throw new Error("Schema is not defined");
8
+ }
9
+
10
+ if (!this.validator) {
11
+ throw new Error("Validator is not defined");
12
+ }
13
+
14
+ const isNew = data?.id ? false : true;
15
+
16
+ this._setId(data);
17
+ this._validate(data);
18
+ this._setProperties(data);
19
+ this._setTimestamps(isNew);
20
+ }
21
+
22
+ static get validProperties() {
23
+ throw new Error("validProperties is not defined");
24
+ }
25
+
26
+ get schemaProperties() {
27
+ return Object.keys(this.validator.schema.properties);
28
+ }
29
+
30
+ _setId(data) {
31
+ if (data._id) data.id = data._id;
32
+ if (!data.id) {
33
+ data.id = this.constructor.generateId();
34
+ }
35
+ delete data._id;
36
+ }
37
+
38
+ _setProperties(data) {
39
+ this.schemaProperties.forEach((key) => {
40
+ if (data[key] !== undefined) this[key] = data[key];
41
+ });
42
+ }
43
+
44
+ _setTimestamps(isNew) {
45
+ const now = new Date();
46
+ if (
47
+ isNew &&
48
+ this.schemaProperties.includes("createdAt") &&
49
+ !this.createdAt
50
+ ) {
51
+ this.createdAt = now;
52
+ }
53
+ }
54
+
55
+ _validate(data) {
56
+ const valid = this.validator(data);
57
+ if (!valid)
58
+ throw new ValidationError(`Invalid ${this.constructor.name}`, {
59
+ cause: this.validator.errors,
60
+ });
61
+ }
62
+
63
+ static generateId() {
64
+ const length = 8;
65
+ const characters =
66
+ "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
67
+ const id = generate(characters, length)();
68
+ return id;
69
+ }
70
+
71
+ static getActionDelta(old, _new) {
72
+ const delta = {};
73
+ for (const action in _new) {
74
+ if (this.actionProperties?.includes(action)) {
75
+ if (old[action] !== _new[action]) {
76
+ delta[action] = 1;
77
+ }
78
+ }
79
+ }
80
+ return delta;
81
+ }
82
+
83
+ toObject() {
84
+ const obj = { ...this };
85
+ // delete keys if they are not valid properties
86
+ Object.keys(obj).forEach((key) => {
87
+ if (!this.constructor.validProperties.includes(key)) {
88
+ delete obj[key];
89
+ }
90
+ });
91
+ return obj;
92
+ }
93
+ }
94
+
95
+ module.exports = Kohost;
package/models/lock.js ADDED
@@ -0,0 +1,33 @@
1
+ // Create the Lock Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/lock.json");
4
+ const Kohost = require("./kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class Lock extends Kohost {
10
+ constructor(data) {
11
+ super(data);
12
+ }
13
+ }
14
+
15
+ Object.defineProperty(Lock.prototype, "schema", {
16
+ value: schema,
17
+ });
18
+
19
+ Object.defineProperty(Lock.prototype, "validator", {
20
+ get: function () {
21
+ return validator;
22
+ },
23
+ });
24
+
25
+ Object.defineProperty(Lock, "validProperties", {
26
+ value: Object.keys(schema.properties),
27
+ });
28
+
29
+ Object.defineProperty(Lock, "actionProperties", {
30
+ value: ["state"],
31
+ });
32
+
33
+ module.exports = Lock;
@@ -0,0 +1,29 @@
1
+ // create the Media Source Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/mediaSource.json");
4
+ const Kohost = require("./kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class MediaSource extends Kohost {
10
+ constructor(data) {
11
+ super(data);
12
+ }
13
+ }
14
+
15
+ Object.defineProperty(MediaSource.prototype, "schema", {
16
+ value: schema,
17
+ });
18
+
19
+ Object.defineProperty(MediaSource.prototype, "validator", {
20
+ get: function () {
21
+ return validator;
22
+ },
23
+ });
24
+
25
+ Object.defineProperty(MediaSource, "validProperties", {
26
+ value: Object.keys(schema.properties),
27
+ });
28
+
29
+ module.exports = MediaSource;
@@ -0,0 +1,29 @@
1
+ // create the Motion Sensor Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/motionSensor.json");
4
+ const Kohost = require("./kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class MotionSensor extends Kohost {
10
+ constructor(data) {
11
+ super(data);
12
+ }
13
+ }
14
+
15
+ Object.defineProperty(MotionSensor.prototype, "schema", {
16
+ value: schema,
17
+ });
18
+
19
+ Object.defineProperty(MotionSensor.prototype, "validator", {
20
+ get: function () {
21
+ return validator;
22
+ },
23
+ });
24
+
25
+ Object.defineProperty(MotionSensor, "validProperties", {
26
+ value: Object.keys(schema.properties),
27
+ });
28
+
29
+ module.exports = MotionSensor;
@@ -0,0 +1,36 @@
1
+ const schemas = require("../utils/schema");
2
+ const schema = require("../schemas/reservation.json");
3
+ const Kohost = require("./kohost");
4
+
5
+ schemas.add(schema);
6
+ const validator = schemas.compile(schema);
7
+
8
+ class Reservation extends Kohost {
9
+ constructor(data) {
10
+ super(data);
11
+ }
12
+
13
+ get peopleCount() {
14
+ return this.adultCount + this.childCount;
15
+ }
16
+
17
+ get hasPayment() {
18
+ return this.paymentId?.length > 0;
19
+ }
20
+ }
21
+
22
+ Object.defineProperty(Reservation.prototype, "schema", {
23
+ value: schema,
24
+ });
25
+
26
+ Object.defineProperty(Reservation.prototype, "validator", {
27
+ get: function () {
28
+ return validator;
29
+ },
30
+ });
31
+
32
+ Object.defineProperty(Reservation, "validProperties", {
33
+ value: Object.keys(schema.properties),
34
+ });
35
+
36
+ module.exports = Reservation;
package/models/room.js ADDED
@@ -0,0 +1,185 @@
1
+ // create the Room model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/room.json");
4
+ const Kohost = require("./kohost");
5
+ const cloneDeep = require("lodash.clonedeep");
6
+
7
+ // device dependencies
8
+ const Switch = require("./switch");
9
+ const Dimmer = require("./dimmer");
10
+ const Thermostat = require("./thermostat");
11
+ const Lock = require("./lock");
12
+ const WindowCovering = require("./windowCovering");
13
+ const Courtesy = require("./courtesy");
14
+ const SceneController = require("./sceneController");
15
+ const Camera = require("./camera");
16
+ const Alarm = require("./alarm");
17
+ const Source = require("./mediaSource");
18
+ const MotionSensor = require("./motionSensor");
19
+
20
+ // other dependencies
21
+ const Scene = require("./scene");
22
+
23
+ schemas.add(schema);
24
+ const validator = schemas.compile(schema);
25
+
26
+ class Room extends Kohost {
27
+ constructor(data) {
28
+ const roomData = mapRoomData(data);
29
+ super(roomData);
30
+ }
31
+
32
+ static getDevicePath(type) {
33
+ const validTypes = [
34
+ "dimmer",
35
+ "switch",
36
+ "thermostat",
37
+ "lock",
38
+ "windowCovering",
39
+ "courtesy",
40
+ "sceneController",
41
+ "camera",
42
+ "source",
43
+ "motionSensor",
44
+ "alarm",
45
+ ];
46
+ if (!validTypes.includes(type))
47
+ throw new Error("Invalid device type:" + type);
48
+ switch (type) {
49
+ case "courtesy":
50
+ return type;
51
+ case "switch":
52
+ return "switches";
53
+ default:
54
+ return `${type}s`;
55
+ }
56
+ }
57
+
58
+ get hasDimmer() {
59
+ return this.dimmers?.length > 0;
60
+ }
61
+
62
+ get hasSwitch() {
63
+ return this.switches?.length > 0;
64
+ }
65
+
66
+ get hasWindowCovering() {
67
+ return this.windowCoverings?.length > 0;
68
+ }
69
+
70
+ get hasThermostat() {
71
+ return this.thermostats?.length > 0;
72
+ }
73
+
74
+ get hasLock() {
75
+ return this.locks?.length > 0;
76
+ }
77
+
78
+ get hasCourtesy() {
79
+ return this.courtesy?.length > 0;
80
+ }
81
+
82
+ get hasSceneController() {
83
+ return this.sceneControllers?.length > 0;
84
+ }
85
+
86
+ get hasCamera() {
87
+ return this.cameras?.length > 0;
88
+ }
89
+
90
+ get hasAlarm() {
91
+ return this.alarms?.length > 0;
92
+ }
93
+
94
+ get hasMedia() {
95
+ return this.sources?.length > 0;
96
+ }
97
+
98
+ get occupied() {
99
+ const now = new Date();
100
+ const lastOccupied = new Date(this.occupiedAt);
101
+ const diff = now - lastOccupied;
102
+ // check if the room has been occupied in the last 60 minutes
103
+ return diff < 60 * 60 * 1000;
104
+ }
105
+ }
106
+
107
+ Object.defineProperty(Room.prototype, "schema", {
108
+ value: schema,
109
+ });
110
+
111
+ Object.defineProperty(Room.prototype, "validator", {
112
+ get: function () {
113
+ return validator;
114
+ },
115
+ });
116
+
117
+ Object.defineProperty(Room, "validProperties", {
118
+ value: Object.keys(schema.properties),
119
+ });
120
+
121
+ function mapRoomData(data) {
122
+ const roomData = cloneDeep(data);
123
+ roomData.dimmers?.map((dimmer) => {
124
+ if (dimmer instanceof Dimmer) return dimmer;
125
+ else return new Dimmer(dimmer);
126
+ });
127
+ roomData.switches?.map((switch_) => {
128
+ if (switch_ instanceof Switch) return switch_;
129
+ else return new Switch(switch_);
130
+ });
131
+
132
+ roomData.windowCoverings?.map((windowCovering) => {
133
+ if (windowCovering instanceof WindowCovering) return windowCovering;
134
+ else return new WindowCovering(windowCovering);
135
+ });
136
+
137
+ roomData.thermostats?.map((thermostat) => {
138
+ if (thermostat instanceof Thermostat) return thermostat;
139
+ else return new Thermostat(thermostat);
140
+ });
141
+
142
+ roomData.locks?.map((lock) => {
143
+ if (lock instanceof Lock) return lock;
144
+ else return new Lock(lock);
145
+ });
146
+
147
+ roomData.courtesy?.map((courtesy) => {
148
+ if (courtesy instanceof Courtesy) return courtesy;
149
+ else return new Courtesy(courtesy);
150
+ });
151
+
152
+ roomData.sources?.map((source) => {
153
+ if (source instanceof Source) return source;
154
+ else return new Source(source);
155
+ });
156
+
157
+ roomData.sceneControllers?.map((sceneController) => {
158
+ if (sceneController instanceof SceneController) return sceneController;
159
+ else return new SceneController(sceneController);
160
+ });
161
+
162
+ roomData.cameras?.map((camera) => {
163
+ if (camera instanceof Camera) return camera;
164
+ else return new Camera(camera);
165
+ });
166
+
167
+ roomData.alarms?.map((alarm) => {
168
+ if (alarm instanceof Alarm) return alarm;
169
+ else return new Alarm(alarm);
170
+ });
171
+
172
+ roomData.motionSensors?.map((motionSensor) => {
173
+ if (motionSensor instanceof MotionSensor) return motionSensor;
174
+ else return new MotionSensor(motionSensor);
175
+ });
176
+
177
+ roomData.scenes?.map((scene) => {
178
+ if (scene instanceof Scene) return scene;
179
+ else return new Scene(scene);
180
+ });
181
+
182
+ return roomData;
183
+ }
184
+
185
+ module.exports = Room;
@@ -0,0 +1,28 @@
1
+ const schemas = require("../utils/schema");
2
+ const schema = require("../schemas/scene.json");
3
+ const Kohost = require("./kohost");
4
+
5
+ schemas.add(schema);
6
+ const validator = schemas.compile(schema);
7
+
8
+ class Scene extends Kohost {
9
+ constructor(data) {
10
+ super(data);
11
+ }
12
+ }
13
+
14
+ Object.defineProperty(Scene.prototype, "schema", {
15
+ value: schema,
16
+ });
17
+
18
+ Object.defineProperty(Scene.prototype, "validator", {
19
+ get: function () {
20
+ return validator;
21
+ },
22
+ });
23
+
24
+ Object.defineProperty(Scene, "validProperties", {
25
+ value: Object.keys(schema.properties),
26
+ });
27
+
28
+ module.exports = Scene;
@@ -0,0 +1,29 @@
1
+ // Create the SceneController Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/sceneController.json");
4
+ const Kohost = require("./kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class SceneController extends Kohost {
10
+ constructor(data) {
11
+ super(data);
12
+ }
13
+ }
14
+
15
+ Object.defineProperty(SceneController.prototype, "schema", {
16
+ value: schema,
17
+ });
18
+
19
+ Object.defineProperty(SceneController.prototype, "validator", {
20
+ get: function () {
21
+ return validator;
22
+ },
23
+ });
24
+
25
+ Object.defineProperty(SceneController, "validProperties", {
26
+ value: Object.keys(schema.properties),
27
+ });
28
+
29
+ module.exports = SceneController;