@kohost/api-client 1.0.0-beta.2 → 1.0.0-beta.4

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 (255) hide show
  1. package/dist/Client.js +19632 -0
  2. package/dist/commands.js +568 -0
  3. package/dist/defs.js +196 -0
  4. package/dist/errors.js +174 -0
  5. package/dist/events.js +375 -0
  6. package/dist/models.js +3584 -0
  7. package/dist/useCases/AddDefaultScenesToRooms.js +39 -0
  8. package/dist/useCases/AddScenesToRoom.js +39 -0
  9. package/dist/useCases/AdminCreateProperty.js +39 -0
  10. package/dist/useCases/AdminDescribeProperty.js +39 -0
  11. package/dist/useCases/AdminListCustomers.js +39 -0
  12. package/dist/useCases/AdminListProperties.js +39 -0
  13. package/dist/useCases/AdminUpdateProperty.js +39 -0
  14. package/dist/useCases/BatchNotifyPreArrival.js +39 -0
  15. package/dist/useCases/CheckInReservation.js +39 -0
  16. package/dist/useCases/CheckVerificationCode.js +39 -0
  17. package/dist/useCases/CreateAlarm.js +39 -0
  18. package/dist/useCases/CreateCamera.js +39 -0
  19. package/dist/useCases/CreateCourtesy.js +39 -0
  20. package/dist/useCases/CreateDefaultScenes.js +39 -0
  21. package/dist/useCases/CreateDimmer.js +39 -0
  22. package/dist/useCases/CreateDiscoveredDevice.js +39 -0
  23. package/dist/useCases/CreateDiscoveredDeviceAssociation.js +39 -0
  24. package/dist/useCases/CreateIntegration.js +39 -0
  25. package/dist/useCases/CreateIntegrationDeviceMapEntry.js +39 -0
  26. package/dist/useCases/CreateLock.js +39 -0
  27. package/dist/useCases/CreateReservation.js +39 -0
  28. package/dist/useCases/CreateRoom.js +39 -0
  29. package/dist/useCases/CreateRoomInSpace.js +39 -0
  30. package/dist/useCases/CreateSource.js +39 -0
  31. package/dist/useCases/CreateSpace.js +39 -0
  32. package/dist/useCases/CreateSwitch.js +39 -0
  33. package/dist/useCases/CreateThermostat.js +39 -0
  34. package/dist/useCases/CreateTicket.js +39 -0
  35. package/dist/useCases/CreateTicketMessage.js +39 -0
  36. package/dist/useCases/CreateUser.js +39 -0
  37. package/dist/useCases/CreateWindowCovering.js +39 -0
  38. package/dist/useCases/DeleteAlarm.js +39 -0
  39. package/dist/useCases/DeleteCamera.js +39 -0
  40. package/dist/useCases/DeleteCourtesy.js +39 -0
  41. package/dist/useCases/DeleteDimmer.js +39 -0
  42. package/dist/useCases/DeleteDiscoveredDevice.js +39 -0
  43. package/dist/useCases/DeleteIntegration.js +39 -0
  44. package/dist/useCases/DeleteLock.js +39 -0
  45. package/dist/useCases/DeleteReservation.js +39 -0
  46. package/dist/useCases/DeleteRoom.js +39 -0
  47. package/dist/useCases/DeleteSource.js +39 -0
  48. package/dist/useCases/DeleteSpace.js +39 -0
  49. package/dist/useCases/DeleteSwitch.js +39 -0
  50. package/dist/useCases/DeleteThermostat.js +39 -0
  51. package/dist/useCases/DeleteTicket.js +39 -0
  52. package/dist/useCases/DeleteUser.js +39 -0
  53. package/dist/useCases/DeleteWindowCovering.js +39 -0
  54. package/dist/useCases/DescribeAlarm.js +39 -0
  55. package/dist/useCases/DescribeCamera.js +39 -0
  56. package/dist/useCases/DescribeCourtesy.js +39 -0
  57. package/dist/useCases/DescribeDimmer.js +39 -0
  58. package/dist/useCases/DescribeDiscoveredDevice.js +39 -0
  59. package/dist/useCases/DescribeIntegration.js +39 -0
  60. package/dist/useCases/DescribeLock.js +39 -0
  61. package/dist/useCases/DescribeMyProperty.js +39 -0
  62. package/dist/useCases/DescribeReservation.js +39 -0
  63. package/dist/useCases/DescribeReservationCheckinStatus.js +39 -0
  64. package/dist/useCases/DescribeRoom.js +39 -0
  65. package/dist/useCases/DescribeSelf.js +39 -0
  66. package/dist/useCases/DescribeSource.js +39 -0
  67. package/dist/useCases/DescribeSpace.js +39 -0
  68. package/dist/useCases/DescribeSwitch.js +39 -0
  69. package/dist/useCases/DescribeThermostat.js +39 -0
  70. package/dist/useCases/DescribeTicket.js +39 -0
  71. package/dist/useCases/DescribeUser.js +39 -0
  72. package/dist/useCases/DescribeWindowCovering.js +39 -0
  73. package/dist/useCases/DiscoverReservations.js +39 -0
  74. package/dist/useCases/EmailUserAccountSetup.js +39 -0
  75. package/dist/useCases/ListAlarms.js +39 -0
  76. package/dist/useCases/ListCameras.js +39 -0
  77. package/dist/useCases/ListCourtesy.js +39 -0
  78. package/dist/useCases/ListDimmers.js +39 -0
  79. package/dist/useCases/ListDiscoveredDevices.js +39 -0
  80. package/dist/useCases/ListIntegrations.js +39 -0
  81. package/dist/useCases/ListLocks.js +39 -0
  82. package/dist/useCases/ListMyReservations.js +39 -0
  83. package/dist/useCases/ListMySpaces.js +39 -0
  84. package/dist/useCases/ListReservations.js +39 -0
  85. package/dist/useCases/ListRooms.js +39 -0
  86. package/dist/useCases/ListRoomsInSpace.js +39 -0
  87. package/dist/useCases/ListSources.js +39 -0
  88. package/dist/useCases/ListSpaces.js +39 -0
  89. package/dist/useCases/ListSwitches.js +39 -0
  90. package/dist/useCases/ListThermostats.js +39 -0
  91. package/dist/useCases/ListTickets.js +39 -0
  92. package/dist/useCases/ListUserReservations.js +39 -0
  93. package/dist/useCases/ListUsers.js +39 -0
  94. package/dist/useCases/ListWindowCoverings.js +39 -0
  95. package/dist/useCases/LoginGateway.js +39 -0
  96. package/dist/useCases/LoginUser.js +39 -0
  97. package/dist/useCases/MatchUserIdentification.js +39 -0
  98. package/dist/useCases/OCRDocument.js +39 -0
  99. package/dist/useCases/RefreshToken.js +39 -0
  100. package/dist/useCases/RequestLoginLink.js +39 -0
  101. package/dist/useCases/SendPreArrivalEmail.js +39 -0
  102. package/dist/useCases/SendPreArrivalSMS.js +39 -0
  103. package/dist/useCases/SendVerificationCode.js +39 -0
  104. package/dist/useCases/SetCamera.js +39 -0
  105. package/dist/useCases/SetCourtesy.js +39 -0
  106. package/dist/useCases/SetLock.js +39 -0
  107. package/dist/useCases/SetSource.js +39 -0
  108. package/dist/useCases/SetSwitch.js +39 -0
  109. package/dist/useCases/SetThermostat.js +39 -0
  110. package/dist/useCases/SetWindowCovering.js +39 -0
  111. package/dist/useCases/UpdateAlarm.js +39 -0
  112. package/dist/useCases/UpdateCamera.js +39 -0
  113. package/dist/useCases/UpdateCourtesy.js +39 -0
  114. package/dist/useCases/UpdateDimmer.js +39 -0
  115. package/dist/useCases/UpdateDiscoveredDevice.js +39 -0
  116. package/dist/useCases/UpdateIntegration.js +39 -0
  117. package/dist/useCases/UpdateLock.js +39 -0
  118. package/dist/useCases/UpdateMessageReadStatus.js +39 -0
  119. package/dist/useCases/UpdateReservation.js +39 -0
  120. package/dist/useCases/UpdateRoom.js +39 -0
  121. package/dist/useCases/UpdateSelf.js +39 -0
  122. package/dist/useCases/UpdateSource.js +39 -0
  123. package/dist/useCases/UpdateSpace.js +39 -0
  124. package/dist/useCases/UpdateSwitch.js +39 -0
  125. package/dist/useCases/UpdateThermostat.js +39 -0
  126. package/dist/useCases/UpdateTicket.js +39 -0
  127. package/dist/useCases/UpdateTicketStatus.js +39 -0
  128. package/dist/useCases/UpdateUser.js +39 -0
  129. package/dist/useCases/UpdateWindowCovering.js +39 -0
  130. package/dist/useCases/UpsertDiscoveredDevice.js +39 -0
  131. package/dist/utils.js +53 -0
  132. package/package.json +8 -2
  133. package/.eslintrc.js +0 -10
  134. package/bitbucket-pipelines.yml +0 -65
  135. package/commands/CheckInReservationCommand.js +0 -23
  136. package/commands/Command.js +0 -38
  137. package/commands/DiscoverReservationsCommand.js +0 -24
  138. package/commands/DiscoverRoomsCommand.js +0 -21
  139. package/commands/DiscoverUsersCommand.js +0 -21
  140. package/commands/OCRDocumentCommand.js +0 -20
  141. package/commands/SendEmailCommand.js +0 -24
  142. package/commands/SendSMSCommand.js +0 -21
  143. package/commands/SetAlarmCommand.js +0 -21
  144. package/commands/SetCourtesyCommand.js +0 -21
  145. package/commands/SetDimmerCommand.js +0 -21
  146. package/commands/SetLockCommand.js +0 -21
  147. package/commands/SetSceneControllerCommand.js +0 -21
  148. package/commands/SetSwitchCommand.js +0 -21
  149. package/commands/SetThermostatCommand.js +0 -21
  150. package/commands/SetWindowCoveringCommand.js +0 -21
  151. package/commands/index.js +0 -31
  152. package/defs/deviceTypes.js +0 -15
  153. package/defs/formalDeviceTypes.js +0 -6
  154. package/defs/http.js +0 -7
  155. package/defs/index.js +0 -11
  156. package/errors/AppError.js +0 -8
  157. package/errors/AuthenticationError.js +0 -9
  158. package/errors/AuthorizationError.js +0 -9
  159. package/errors/DeviceCommError.js +0 -9
  160. package/errors/LoginError.js +0 -9
  161. package/errors/NotFoundError.js +0 -9
  162. package/errors/RequestError.js +0 -9
  163. package/errors/SystemCommError.js +0 -9
  164. package/errors/TokenExpiredError.js +0 -9
  165. package/errors/UnprocessableRequestError.js +0 -9
  166. package/errors/ValidationError.js +0 -9
  167. package/errors/index.js +0 -15
  168. package/events/EmailSentEvent.js +0 -17
  169. package/events/Event.js +0 -52
  170. package/events/SMSSentEvent.js +0 -17
  171. package/events/ShortLinkCreatedEvent.js +0 -17
  172. package/events/SystemCameraUpdatedEvent.js +0 -17
  173. package/events/SystemCourtesyUpdatedEvent.js +0 -17
  174. package/events/SystemDimmerUpdatedEvent.js +0 -17
  175. package/events/SystemLockUpdatedEvent.js +0 -17
  176. package/events/SystemReservationUpdatedEvent.js +0 -17
  177. package/events/SystemSceneControllerUpdatedEvent.js +0 -17
  178. package/events/SystemSourceUpdatedEvent.js +0 -17
  179. package/events/SystemSpaceUpdatedEvent.js +0 -17
  180. package/events/SystemSwitchUpdatedEvent.js +0 -17
  181. package/events/SystemThermostatUpdatedEvent.js +0 -17
  182. package/events/SystemUserUpdatedEvent.js +0 -17
  183. package/events/SystemWindowCoveringUpdatedEvent.js +0 -17
  184. package/events/index.js +0 -35
  185. package/http/handleResponseError.js +0 -33
  186. package/http/handleResponseSuccess.js +0 -15
  187. package/http/index.js +0 -169
  188. package/index.js +0 -23
  189. package/models/acl.js +0 -29
  190. package/models/admin/customer.js +0 -28
  191. package/models/admin/property.js +0 -28
  192. package/models/alarm.js +0 -29
  193. package/models/application.js +0 -28
  194. package/models/camera.js +0 -29
  195. package/models/courtesy.js +0 -33
  196. package/models/credential.js +0 -29
  197. package/models/dimmer.js +0 -49
  198. package/models/discoveredDevice.js +0 -30
  199. package/models/gateway.js +0 -29
  200. package/models/identification.js +0 -32
  201. package/models/index.js +0 -56
  202. package/models/integration.js +0 -76
  203. package/models/kohost.js +0 -96
  204. package/models/lock.js +0 -33
  205. package/models/mediaSource.js +0 -29
  206. package/models/motionSensor.js +0 -29
  207. package/models/product.js +0 -30
  208. package/models/reservation.js +0 -83
  209. package/models/room.js +0 -174
  210. package/models/scene.js +0 -28
  211. package/models/shortLink.js +0 -29
  212. package/models/space.js +0 -99
  213. package/models/switch.js +0 -33
  214. package/models/thermostat.js +0 -80
  215. package/models/ticket.js +0 -91
  216. package/models/user.js +0 -56
  217. package/models/windowCovering.js +0 -49
  218. package/prepare.js +0 -4
  219. package/schemas/acl.json +0 -111
  220. package/schemas/admin/customer.json +0 -32
  221. package/schemas/admin/property.json +0 -180
  222. package/schemas/alarm.json +0 -93
  223. package/schemas/application.json +0 -24
  224. package/schemas/camera.json +0 -41
  225. package/schemas/courtesy.json +0 -37
  226. package/schemas/credential.json +0 -28
  227. package/schemas/definitions/common.json +0 -74
  228. package/schemas/definitions/device.json +0 -76
  229. package/schemas/dimmer.json +0 -34
  230. package/schemas/discoveredDevice.json +0 -43
  231. package/schemas/gateway.json +0 -30
  232. package/schemas/identification.json +0 -49
  233. package/schemas/integration.json +0 -94
  234. package/schemas/lock.json +0 -36
  235. package/schemas/mediaSource.json +0 -151
  236. package/schemas/motionSensor.json +0 -26
  237. package/schemas/payment.json +0 -40
  238. package/schemas/product.json +0 -36
  239. package/schemas/reservation.json +0 -71
  240. package/schemas/room.json +0 -131
  241. package/schemas/scene.json +0 -118
  242. package/schemas/shortLink.json +0 -30
  243. package/schemas/space.json +0 -111
  244. package/schemas/switch.json +0 -33
  245. package/schemas/thermostat.json +0 -139
  246. package/schemas/ticket.json +0 -82
  247. package/schemas/user.json +0 -176
  248. package/schemas/windowCovering.json +0 -34
  249. package/tests/unit/models/space.test.js +0 -31
  250. package/tests/unit/models/thermostat.test.js +0 -146
  251. package/tests/unit/models/user.test.js +0 -28
  252. package/useCases/http.json +0 -1206
  253. package/utils/getDeviceTypes.js +0 -7
  254. package/utils/getFormalDeviceType.js +0 -5
  255. package/utils/schema.js +0 -28
@@ -1,76 +0,0 @@
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;
package/models/kohost.js DELETED
@@ -1,96 +0,0 @@
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
-
64
- static generateId() {
65
- const length = 8;
66
- const characters =
67
- "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
68
- const id = generate(characters, length)();
69
- return id;
70
- }
71
-
72
- static getActionDelta(old, _new) {
73
- const delta = {};
74
- for (const action in _new) {
75
- if (this.actionProperties?.includes(action)) {
76
- if (old[action] !== _new[action]) {
77
- delta[action] = 1;
78
- }
79
- }
80
- }
81
- return delta;
82
- }
83
-
84
- toObject() {
85
- const obj = { ...this };
86
- // delete keys if they are not valid properties
87
- Object.keys(obj).forEach((key) => {
88
- if (!this.constructor.validProperties.includes(key)) {
89
- delete obj[key];
90
- }
91
- });
92
- return obj;
93
- }
94
- }
95
-
96
- module.exports = Kohost;
package/models/lock.js DELETED
@@ -1,33 +0,0 @@
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;
@@ -1,29 +0,0 @@
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;
@@ -1,29 +0,0 @@
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;
package/models/product.js DELETED
@@ -1,30 +0,0 @@
1
- // Create the Product Model
2
- const schemas = require("../utils/schema");
3
- const schema = require("../schemas/product.json");
4
- const Kohost = require("./kohost");
5
-
6
- schemas.add(schema);
7
- const validator = schemas.compile(schema);
8
-
9
- class Product extends Kohost {
10
- constructor(data) {
11
- super(data);
12
- }
13
- }
14
-
15
- Object.defineProperty(Product.prototype, "schema", {
16
- value: schema,
17
- });
18
-
19
- Object.defineProperty(Product.prototype, "validator", {
20
- get: function () {
21
- return validator;
22
- },
23
- });
24
-
25
- Object.defineProperty(Product, "validProperties", {
26
- value: Object.keys(schema.properties),
27
- });
28
-
29
-
30
- module.exports = Product;
@@ -1,83 +0,0 @@
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
- range(tz) {
22
- const start = new Date(this.checkInDateTime);
23
- const end = new Date(this.checkOutDateTime);
24
-
25
- // output Dec 19-23 if same month and year
26
- if (
27
- start.getMonth() === end.getMonth() &&
28
- start.getFullYear() === end.getFullYear()
29
- ) {
30
- return `${start.toLocaleString("default", {
31
- month: "short",
32
- timeZone: tz,
33
- })} ${start.toLocaleString("default", {
34
- timeZone: tz,
35
- day: "numeric",
36
- })}-${end.toLocaleString("default", {
37
- timeZone: tz,
38
- day: "numeric",
39
- })}`;
40
- }
41
-
42
- // output Dec 19 - Jan 2 if different month and year
43
- return `${start.toLocaleString("default", {
44
- month: "short",
45
- timeZone: tz,
46
- })} ${start.getDate()} - ${end.toLocaleString("default", {
47
- month: "short",
48
- timeZone: tz,
49
- })} ${end.getDate()}`;
50
- }
51
-
52
- checkInTime(tz) {
53
- return new Date(this.checkInDateTime).toLocaleString("default", {
54
- hour: "numeric",
55
- minute: "numeric",
56
- timeZone: tz,
57
- });
58
- }
59
-
60
- checkOutTime(tz) {
61
- return new Date(this.checkOutDateTime).toLocaleString("default", {
62
- hour: "numeric",
63
- minute: "numeric",
64
- timeZone: tz,
65
- });
66
- }
67
- }
68
-
69
- Object.defineProperty(Reservation.prototype, "schema", {
70
- value: schema,
71
- });
72
-
73
- Object.defineProperty(Reservation.prototype, "validator", {
74
- get: function () {
75
- return validator;
76
- },
77
- });
78
-
79
- Object.defineProperty(Reservation, "validProperties", {
80
- value: Object.keys(schema.properties),
81
- });
82
-
83
- module.exports = Reservation;
package/models/room.js DELETED
@@ -1,174 +0,0 @@
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 Camera = require("./camera");
15
- const Alarm = require("./alarm");
16
- const Source = require("./mediaSource");
17
- const MotionSensor = require("./motionSensor");
18
-
19
- // other dependencies
20
- const Scene = require("./scene");
21
-
22
- schemas.add(schema);
23
- const validator = schemas.compile(schema);
24
-
25
- class Room extends Kohost {
26
- constructor(data) {
27
- const roomData = mapRoomData(data);
28
- super(roomData);
29
- }
30
-
31
- static getDevicePath(type) {
32
- const validTypes = [
33
- "dimmer",
34
- "switch",
35
- "thermostat",
36
- "lock",
37
- "windowCovering",
38
- "courtesy",
39
- "camera",
40
- "source",
41
- "motionSensor",
42
- "alarm",
43
- ];
44
- if (!validTypes.includes(type))
45
- throw new Error("Invalid device type:" + type);
46
- switch (type) {
47
- case "courtesy":
48
- return type;
49
- case "switch":
50
- return "switches";
51
- default:
52
- return `${type}s`;
53
- }
54
- }
55
-
56
- get hasDimmer() {
57
- return this.dimmers?.length > 0;
58
- }
59
-
60
- get hasSwitch() {
61
- return this.switches?.length > 0;
62
- }
63
-
64
- get hasWindowCovering() {
65
- return this.windowCoverings?.length > 0;
66
- }
67
-
68
- get hasThermostat() {
69
- return this.thermostats?.length > 0;
70
- }
71
-
72
- get hasLock() {
73
- return this.locks?.length > 0;
74
- }
75
-
76
- get hasCourtesy() {
77
- return this.courtesy?.length > 0;
78
- }
79
-
80
- get hasCamera() {
81
- return this.cameras?.length > 0;
82
- }
83
-
84
- get hasAlarm() {
85
- return this.alarms?.length > 0;
86
- }
87
-
88
- get hasMedia() {
89
- return this.sources?.length > 0;
90
- }
91
-
92
- get occupied() {
93
- const now = new Date();
94
- const lastOccupied = new Date(this.occupiedAt);
95
- const diff = now - lastOccupied;
96
- // check if the room has been occupied in the last 60 minutes
97
- return diff < 60 * 60 * 1000;
98
- }
99
- }
100
-
101
- Object.defineProperty(Room.prototype, "schema", {
102
- value: schema,
103
- });
104
-
105
- Object.defineProperty(Room.prototype, "validator", {
106
- get: function () {
107
- return validator;
108
- },
109
- });
110
-
111
- Object.defineProperty(Room, "validProperties", {
112
- value: Object.keys(schema.properties),
113
- });
114
-
115
- function mapRoomData(data) {
116
- const roomData = cloneDeep(data);
117
- roomData.dimmers?.map((dimmer) => {
118
- if (dimmer instanceof Dimmer) return dimmer;
119
- else return new Dimmer(dimmer);
120
- });
121
- roomData.switches?.map((switch_) => {
122
- if (switch_ instanceof Switch) return switch_;
123
- else return new Switch(switch_);
124
- });
125
-
126
- roomData.windowCoverings?.map((windowCovering) => {
127
- if (windowCovering instanceof WindowCovering) return windowCovering;
128
- else return new WindowCovering(windowCovering);
129
- });
130
-
131
- roomData.thermostats?.map((thermostat) => {
132
- if (thermostat instanceof Thermostat) return thermostat;
133
- else return new Thermostat(thermostat);
134
- });
135
-
136
- roomData.locks?.map((lock) => {
137
- if (lock instanceof Lock) return lock;
138
- else return new Lock(lock);
139
- });
140
-
141
- roomData.courtesy?.map((courtesy) => {
142
- if (courtesy instanceof Courtesy) return courtesy;
143
- else return new Courtesy(courtesy);
144
- });
145
-
146
- roomData.sources?.map((source) => {
147
- if (source instanceof Source) return source;
148
- else return new Source(source);
149
- });
150
-
151
- roomData.cameras?.map((camera) => {
152
- if (camera instanceof Camera) return camera;
153
- else return new Camera(camera);
154
- });
155
-
156
- roomData.alarms?.map((alarm) => {
157
- if (alarm instanceof Alarm) return alarm;
158
- else return new Alarm(alarm);
159
- });
160
-
161
- roomData.motionSensors?.map((motionSensor) => {
162
- if (motionSensor instanceof MotionSensor) return motionSensor;
163
- else return new MotionSensor(motionSensor);
164
- });
165
-
166
- roomData.scenes?.map((scene) => {
167
- if (scene instanceof Scene) return scene;
168
- else return new Scene(scene);
169
- });
170
-
171
- return roomData;
172
- }
173
-
174
- module.exports = Room;
package/models/scene.js DELETED
@@ -1,28 +0,0 @@
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;
@@ -1,29 +0,0 @@
1
- // Create the Lock Model
2
- const schemas = require("../utils/schema");
3
- const schema = require("../schemas/shortLink.json");
4
- const Kohost = require("./kohost");
5
-
6
- schemas.add(schema);
7
- const validator = schemas.compile(schema);
8
-
9
- class ShortLink extends Kohost {
10
- constructor(data) {
11
- super(data);
12
- }
13
- }
14
-
15
- Object.defineProperty(ShortLink.prototype, "schema", {
16
- value: schema,
17
- });
18
-
19
- Object.defineProperty(ShortLink.prototype, "validator", {
20
- get: function () {
21
- return validator;
22
- },
23
- });
24
-
25
- Object.defineProperty(ShortLink, "validProperties", {
26
- value: Object.keys(schema.properties),
27
- });
28
-
29
- module.exports = ShortLink;
package/models/space.js DELETED
@@ -1,99 +0,0 @@
1
- // Create the Space Model
2
- // A group of rooms -> rooms could become a space later...
3
- const schemas = require("../utils/schema");
4
- const schema = require("../schemas/space.json");
5
- const Kohost = require("./kohost");
6
- const cloneDeep = require("lodash.clonedeep");
7
-
8
- const Room = require("./room");
9
-
10
- schemas.add(schema);
11
- const validator = schemas.compile(schema);
12
-
13
- class Space extends Kohost {
14
- constructor(data) {
15
- const spaceData = mapSpaceData(data);
16
- super(spaceData);
17
- }
18
-
19
- get floor() {
20
- const floors = new Set();
21
-
22
- this.room.forEach((room) => {
23
- if (room.floor) floors.add(room.floor);
24
- });
25
-
26
- return floors.size == 1 ? [...floors][0] : undefined;
27
- }
28
-
29
- get hasDimmer() {
30
- return this.rooms.some((room) => room.hasDimmer);
31
- }
32
-
33
- get hasSwitch() {
34
- return this.rooms.some((room) => room.hasSwitch);
35
- }
36
-
37
- get hasWindowCovering() {
38
- return this.rooms.some((room) => room.hasWindowCovering);
39
- }
40
-
41
- get hasThermostat() {
42
- return this.rooms.some((room) => room.hasThermostat);
43
- }
44
-
45
- get hasLock() {
46
- return this.rooms.some((room) => room.hasLock);
47
- }
48
-
49
- get hasCourtesy() {
50
- return this.rooms.some((room) => room.hasCourtesy);
51
- }
52
-
53
- get hasSceneController() {
54
- return this.rooms.some((room) => room.hasSceneController);
55
- }
56
-
57
- get hasCamera() {
58
- return this.rooms.some((room) => room.hasCamera);
59
- }
60
-
61
- get hasAlarm() {
62
- return this.rooms.some((room) => room.hasAlarm);
63
- }
64
-
65
- get hasMedia() {
66
- return this.rooms.some((room) => room.hasMedia);
67
- }
68
- get occupied() {
69
- return this.rooms.some((room) => room.occupied);
70
- }
71
- }
72
-
73
- Object.defineProperty(Space.prototype, "schema", {
74
- value: schema,
75
- });
76
-
77
- Object.defineProperty(Space.prototype, "validator", {
78
- get: function () {
79
- return validator;
80
- },
81
- });
82
-
83
- Object.defineProperty(Space, "validProperties", {
84
- value: Object.keys(schema.properties),
85
- });
86
-
87
- function mapSpaceData(data) {
88
- const spaceData = cloneDeep(data);
89
- if (spaceData.rooms?.length) {
90
- spaceData.rooms.map((room) => {
91
- if (typeof room === "string") return room;
92
- if (room instanceof Room) return room;
93
- return new Room(room);
94
- });
95
- }
96
- return spaceData;
97
- }
98
-
99
- module.exports = Space;