@kohost/api-client 3.0.0-beta.5 → 3.0.0-beta.51

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 (211) hide show
  1. package/README.md +71 -0
  2. package/dist/cjs/AMQPClient/index.js +290 -0
  3. package/dist/cjs/{Client.js → Client/index.js} +1938 -986
  4. package/dist/cjs/Commands/CheckInReservationCommand.js +19 -0
  5. package/dist/cjs/Commands/Command.js +34 -0
  6. package/dist/cjs/Commands/CreateImageUploadEndpointCommand.js +17 -0
  7. package/dist/cjs/Commands/CreateShortLinkCommand.js +20 -0
  8. package/dist/cjs/Commands/DiscoverReservationRoomTypeUpsellOptionsCommand.js +20 -0
  9. package/dist/cjs/Commands/DiscoverReservationsCommand.js +20 -0
  10. package/dist/cjs/Commands/DiscoverRoomTypesCommand.js +19 -0
  11. package/dist/cjs/Commands/DiscoverRoomsCommand.js +35 -0
  12. package/dist/cjs/Commands/DiscoverUsersCommand.js +19 -0
  13. package/dist/cjs/Commands/GetMobileKeyCommand.js +24 -0
  14. package/dist/cjs/Commands/GetProductsCommand.js +17 -0
  15. package/dist/cjs/Commands/OCRDocumentCommand.js +15 -0
  16. package/dist/cjs/Commands/SellProductsCommand.js +17 -0
  17. package/dist/cjs/Commands/SendEmailCommand.js +24 -0
  18. package/dist/cjs/Commands/SendSMSCommand.js +21 -0
  19. package/dist/cjs/Commands/SetAlarmCommand.js +17 -0
  20. package/dist/cjs/Commands/SetCourtesyCommand.js +17 -0
  21. package/dist/cjs/Commands/SetDimmerCommand.js +17 -0
  22. package/dist/cjs/Commands/SetLockCommand.js +17 -0
  23. package/dist/cjs/Commands/SetMediaCommand.js +17 -0
  24. package/dist/cjs/Commands/SetSceneCommand.js +17 -0
  25. package/dist/cjs/Commands/SetSwitchCommand.js +17 -0
  26. package/dist/cjs/Commands/SetThermostatCommand.js +17 -0
  27. package/dist/cjs/Commands/SetWindowCoveringCommand.js +17 -0
  28. package/dist/cjs/Commands/UpdateReservationCommand.js +19 -0
  29. package/dist/cjs/Commands/UpdateUserCommand.js +41 -0
  30. package/dist/cjs/Commands/UploadImageCommand.js +17 -0
  31. package/dist/cjs/Commands/index.js +55 -0
  32. package/dist/cjs/Errors/AppError.js +8 -0
  33. package/dist/cjs/Errors/AuthenticationError.js +9 -0
  34. package/dist/cjs/Errors/AuthorizationError.js +9 -0
  35. package/dist/cjs/Errors/DeviceCommError.js +9 -0
  36. package/dist/cjs/Errors/LoginError.js +9 -0
  37. package/dist/cjs/Errors/NotFoundError.js +9 -0
  38. package/dist/cjs/Errors/RequestError.js +9 -0
  39. package/dist/cjs/Errors/SystemCommError.js +9 -0
  40. package/dist/cjs/Errors/TokenExpiredError.js +9 -0
  41. package/dist/cjs/Errors/UnprocessableRequestError.js +9 -0
  42. package/dist/cjs/Errors/ValidationError.js +9 -0
  43. package/dist/cjs/Errors/index.js +15 -0
  44. package/dist/cjs/Events/ApplicationInUseEvent.js +17 -0
  45. package/dist/cjs/Events/ApplicationOutOfUseEvent.js +17 -0
  46. package/dist/cjs/Events/EmailEvent.js +18 -0
  47. package/dist/cjs/Events/Event.js +55 -0
  48. package/dist/cjs/Events/SMSEvent.js +18 -0
  49. package/dist/cjs/Events/SMSSentEvent.js +17 -0
  50. package/dist/cjs/Events/ShortLinkCreatedEvent.js +17 -0
  51. package/dist/cjs/Events/SystemAlarmUpdatedEvent.js +17 -0
  52. package/dist/cjs/Events/SystemCameraUpdatedEvent.js +17 -0
  53. package/dist/cjs/Events/SystemCourtesyUpdatedEvent.js +17 -0
  54. package/dist/cjs/Events/SystemDimmerUpdatedEvent.js +17 -0
  55. package/dist/cjs/Events/SystemGatewayUpdatedEvent.js +17 -0
  56. package/dist/cjs/Events/SystemLockUpdatedEvent.js +17 -0
  57. package/dist/cjs/Events/SystemMediaSourceUpdatedEvent.js +17 -0
  58. package/dist/cjs/Events/SystemMotionSensorUpdatedEvent.js +17 -0
  59. package/dist/cjs/Events/SystemProductUpdatedEvent.js +17 -0
  60. package/dist/cjs/Events/SystemReservationUpdatedEvent.js +17 -0
  61. package/dist/cjs/Events/SystemSceneControllerUpdatedEvent.js +17 -0
  62. package/dist/cjs/Events/SystemSpaceTypeUpdatedEvent.js +17 -0
  63. package/dist/cjs/Events/SystemSpaceUpdatedEvent.js +17 -0
  64. package/dist/cjs/Events/SystemSwitchUpdatedEvent.js +17 -0
  65. package/dist/cjs/Events/SystemThermostatUpdatedEvent.js +17 -0
  66. package/dist/cjs/Events/SystemUserUpdatedEvent.js +17 -0
  67. package/dist/cjs/Events/SystemWindowCoveringUpdatedEvent.js +17 -0
  68. package/dist/cjs/Events/index.js +51 -0
  69. package/dist/cjs/Models/Alarm.js +35 -0
  70. package/dist/cjs/Models/Camera.js +35 -0
  71. package/dist/cjs/Models/Courtesy.js +39 -0
  72. package/dist/cjs/Models/Credential.js +35 -0
  73. package/dist/cjs/Models/Dimmer.js +61 -0
  74. package/dist/cjs/Models/DiscoveredDevice.js +36 -0
  75. package/dist/cjs/Models/EmailMessage.js +35 -0
  76. package/dist/cjs/Models/EnergyReport.js +35 -0
  77. package/dist/cjs/Models/EnergyReportShard.js +35 -0
  78. package/dist/cjs/Models/Gateway.js +35 -0
  79. package/dist/cjs/Models/Identification.js +38 -0
  80. package/dist/cjs/Models/Kohost.js +96 -0
  81. package/dist/cjs/Models/Lock.js +39 -0
  82. package/dist/cjs/Models/MediaFile.js +47 -0
  83. package/dist/cjs/Models/MediaSource.js +35 -0
  84. package/dist/cjs/Models/MotionSensor.js +35 -0
  85. package/dist/cjs/Models/Organization.js +34 -0
  86. package/dist/cjs/Models/Product.js +35 -0
  87. package/dist/cjs/Models/Property.js +34 -0
  88. package/dist/cjs/Models/Reservation.js +104 -0
  89. package/dist/cjs/Models/Room.js +218 -0
  90. package/dist/cjs/Models/Scene.js +189 -0
  91. package/dist/cjs/Models/ShortLink.js +35 -0
  92. package/dist/cjs/Models/SmsMessage.js +35 -0
  93. package/dist/cjs/Models/Space.js +97 -0
  94. package/dist/cjs/Models/SpaceType.js +36 -0
  95. package/dist/cjs/Models/Switch.js +39 -0
  96. package/dist/cjs/Models/SystemUser.js +55 -0
  97. package/dist/cjs/Models/Thermostat.js +86 -0
  98. package/dist/cjs/Models/Ticket.js +111 -0
  99. package/dist/cjs/Models/User.js +79 -0
  100. package/dist/cjs/Models/WindowCovering.js +55 -0
  101. package/dist/cjs/Models/index.js +68 -0
  102. package/dist/cjs/SocketIoClient/index.js +74 -0
  103. package/dist/cjs/defs/deviceTypes.js +15 -0
  104. package/dist/cjs/defs/formalDeviceTypes.js +6 -0
  105. package/dist/cjs/defs/index.js +11 -0
  106. package/dist/cjs/{index.cjs.js → index.js} +7 -1
  107. package/dist/cjs/schemas/alarm.json +103 -0
  108. package/dist/cjs/schemas/camera.json +50 -0
  109. package/dist/cjs/schemas/courtesy.json +46 -0
  110. package/dist/cjs/schemas/credential.json +31 -0
  111. package/dist/cjs/schemas/definitions.json +191 -0
  112. package/dist/cjs/schemas/dimmer.json +43 -0
  113. package/dist/cjs/schemas/discoveredDevice.json +31 -0
  114. package/dist/cjs/schemas/emailMessage.json +71 -0
  115. package/dist/cjs/schemas/energyReport.json +86 -0
  116. package/dist/cjs/schemas/energyReportShard.json +75 -0
  117. package/dist/cjs/schemas/gateway.json +35 -0
  118. package/dist/cjs/schemas/identification.json +61 -0
  119. package/dist/cjs/schemas/lock.json +45 -0
  120. package/dist/cjs/schemas/mediaFile.json +67 -0
  121. package/dist/cjs/schemas/mediaSource.json +184 -0
  122. package/dist/cjs/schemas/motionSensor.json +32 -0
  123. package/dist/cjs/schemas/organization.json +36 -0
  124. package/dist/cjs/schemas/payment.json +47 -0
  125. package/dist/cjs/schemas/product.json +40 -0
  126. package/dist/cjs/schemas/property.json +246 -0
  127. package/dist/cjs/schemas/reservation.json +118 -0
  128. package/dist/cjs/schemas/room.json +98 -0
  129. package/dist/cjs/schemas/scene.json +121 -0
  130. package/dist/cjs/schemas/shortLink.json +30 -0
  131. package/dist/cjs/schemas/smsMessage.json +61 -0
  132. package/dist/cjs/schemas/space.json +120 -0
  133. package/dist/cjs/schemas/spaceType.json +30 -0
  134. package/dist/cjs/schemas/switch.json +42 -0
  135. package/dist/cjs/schemas/systemUser.json +95 -0
  136. package/dist/cjs/schemas/thermostat.json +153 -0
  137. package/dist/cjs/schemas/ticket.json +96 -0
  138. package/dist/cjs/schemas/user.json +152 -0
  139. package/dist/cjs/schemas/windowCovering.json +43 -0
  140. package/dist/cjs/utils/errorFactory.js +8 -0
  141. package/dist/cjs/utils/eventFactory.js +10 -0
  142. package/dist/cjs/utils/getDeviceTypes.js +7 -0
  143. package/dist/cjs/utils/getFormalDeviceType.js +5 -0
  144. package/dist/cjs/utils/index.js +11 -0
  145. package/dist/cjs/utils/schema.js +25 -0
  146. package/dist/esm/Client.js +2293 -1205
  147. package/dist/esm/Client.js.map +4 -4
  148. package/dist/esm/Commands.js +478 -73
  149. package/dist/esm/Commands.js.map +3 -3
  150. package/dist/esm/Errors.js +35 -0
  151. package/dist/esm/Errors.js.map +1 -1
  152. package/dist/esm/Events.js +290 -63
  153. package/dist/esm/Events.js.map +3 -3
  154. package/dist/esm/Models.js +3074 -880
  155. package/dist/esm/Models.js.map +4 -4
  156. package/dist/esm/SocketIoClient.js +4748 -0
  157. package/dist/esm/SocketIoClient.js.map +7 -0
  158. package/dist/esm/defs.js +407 -279
  159. package/dist/esm/defs.js.map +4 -4
  160. package/dist/esm/index.js +17 -10
  161. package/dist/esm/utils.js +742 -85
  162. package/dist/esm/utils.js.map +3 -3
  163. package/dist/useCases/{AdminUpdateProperty.js → AdminUpdateCustomer.js} +2 -2
  164. package/dist/useCases/AssignSpaceToReservation.js +32 -0
  165. package/dist/useCases/BatchNotifyCheckIn.js +32 -0
  166. package/dist/useCases/CreateImageUploadEndpoint.js +32 -0
  167. package/dist/useCases/{CreateSource.js → CreateMediaSource.js} +2 -2
  168. package/dist/useCases/{AdminListCustomers.js → CreateOrganization.js} +3 -3
  169. package/dist/useCases/{LoginGateway.js → CreateProperty.js} +2 -2
  170. package/dist/useCases/{AdminCreateProperty.js → CreateSpaceType.js} +2 -2
  171. package/dist/useCases/DeleteMediaFile.js +32 -0
  172. package/dist/useCases/{DeleteSource.js → DeleteMediaSource.js} +2 -2
  173. package/dist/useCases/DeleteSpaceType.js +32 -0
  174. package/dist/useCases/DescribeLockCredential.js +32 -0
  175. package/dist/useCases/{DescribeIntegration.js → DescribeMediaSource.js} +3 -3
  176. package/dist/useCases/DescribeMyAccessCredentials.js +32 -0
  177. package/dist/useCases/{AdminDescribeProperty.js → DescribeOrganization.js} +2 -2
  178. package/dist/useCases/DescribeProduct.js +32 -0
  179. package/dist/useCases/{ListIntegrations.js → DescribeProperty.js} +3 -3
  180. package/dist/useCases/DescribeReservationEarlyCheckInProducts.js +32 -0
  181. package/dist/useCases/DescribeReservationRoomUpgrades.js +32 -0
  182. package/dist/useCases/{DeleteIntegration.js → DescribeSpaceType.js} +2 -2
  183. package/dist/useCases/ListMediaSources.js +32 -0
  184. package/dist/useCases/{AdminListProperties.js → ListMyTickets.js} +2 -2
  185. package/dist/useCases/{UpdateIntegration.js → ListOrganizations.js} +4 -4
  186. package/dist/useCases/ListProperties.js +32 -0
  187. package/dist/useCases/ListScenes.js +32 -0
  188. package/dist/useCases/ListSpaceTypes.js +32 -0
  189. package/dist/useCases/ListTeam.js +32 -0
  190. package/dist/useCases/ListUserSpaces.js +32 -0
  191. package/dist/useCases/LogoutUser.js +32 -0
  192. package/dist/useCases/PurchaseReservationEarlyCheckInProducts.js +32 -0
  193. package/dist/useCases/{CreateIntegrationDeviceMapEntry.js → PurchaseReservationRoomUpgrades.js} +2 -2
  194. package/dist/useCases/RequestLoginLink.js +1 -1
  195. package/dist/useCases/{CreateIntegration.js → RequestMyKeyToken.js} +2 -2
  196. package/dist/useCases/SendCheckInSMS.js +32 -0
  197. package/dist/useCases/{SetSource.js → SetDimmer.js} +2 -2
  198. package/dist/useCases/{DescribeSource.js → SetMediaSource.js} +3 -3
  199. package/dist/useCases/{UpdateSource.js → SetRoomScene.js} +3 -3
  200. package/dist/useCases/SetSpaceScene.js +32 -0
  201. package/dist/useCases/UpdateMediaSource.js +32 -0
  202. package/dist/useCases/UpdateProperty.js +32 -0
  203. package/dist/useCases/UpdateSpaceType.js +32 -0
  204. package/dist/useCases/{ListSources.js → UploadImage.js} +4 -4
  205. package/package.json +36 -10
  206. package/dist/cjs/Commands.js +0 -568
  207. package/dist/cjs/Errors.js +0 -174
  208. package/dist/cjs/Events.js +0 -375
  209. package/dist/cjs/Models.js +0 -3582
  210. package/dist/cjs/defs.js +0 -175
  211. package/dist/cjs/utils.js +0 -246
@@ -0,0 +1,35 @@
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
+ /**
11
+ * @typedef {import("../schemas/ProductSchema").Product} ProductType
12
+ * Create a Product instance.
13
+ * @constructor
14
+ * @param {ProductType} product - The product object of type Product.
15
+ */
16
+ constructor(product) {
17
+ super(product);
18
+ }
19
+ }
20
+
21
+ Object.defineProperty(Product.prototype, "schema", {
22
+ value: schema,
23
+ });
24
+
25
+ Object.defineProperty(Product.prototype, "validator", {
26
+ get: function () {
27
+ return validator;
28
+ },
29
+ });
30
+
31
+ Object.defineProperty(Product, "validProperties", {
32
+ value: Object.keys(schema.properties),
33
+ });
34
+
35
+ module.exports = Product;
@@ -0,0 +1,34 @@
1
+ const schemas = require("../utils/schema");
2
+ const schema = require("../schemas/property.json");
3
+ const Kohost = require("./Kohost");
4
+
5
+ schemas.add(schema);
6
+ const validator = schemas.compile(schema);
7
+
8
+ class Property extends Kohost {
9
+ /**
10
+ * @typedef {import("../schemas/PropertySchema").Property} PropertyType
11
+ * Create a Property instance.
12
+ * @constructor
13
+ * @param {PropertyType} property - The property object of type Property.
14
+ */
15
+ constructor(property) {
16
+ super(property);
17
+ }
18
+ }
19
+
20
+ Object.defineProperty(Property.prototype, "schema", {
21
+ value: schema,
22
+ });
23
+
24
+ Object.defineProperty(Property.prototype, "validator", {
25
+ get: function () {
26
+ return validator;
27
+ },
28
+ });
29
+
30
+ Object.defineProperty(Property, "validProperties", {
31
+ value: Object.keys(schema.properties),
32
+ });
33
+
34
+ module.exports = Property;
@@ -0,0 +1,104 @@
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
+ /**
10
+ * @typedef {import("../schemas/ReservationSchema").Reservation} ReservationType
11
+ * Create a Reservation instance.
12
+ * @constructor
13
+ * @param {ReservationType} reservation - The reservation object of type Reservation.
14
+ */
15
+ constructor(reservation) {
16
+ super(reservation);
17
+ }
18
+
19
+ get peopleCount() {
20
+ return this.adultCount + this.childCount;
21
+ }
22
+
23
+ get hasPayment() {
24
+ return this.paymentId?.length > 0;
25
+ }
26
+
27
+ range(tz) {
28
+ const start = new Date(this.checkInDateTime);
29
+ const end = new Date(this.checkOutDateTime);
30
+
31
+ // output Dec 19 if same day in timezone
32
+
33
+ if (
34
+ start.getDate() === end.getDate() &&
35
+ start.getMonth() === end.getMonth() &&
36
+ start.getFullYear() === end.getFullYear()
37
+ ) {
38
+ return `${start.toLocaleString("default", {
39
+ month: "short",
40
+ timeZone: tz,
41
+ })} ${start.toLocaleString("default", {
42
+ timeZone: tz,
43
+ day: "numeric",
44
+ })}`;
45
+ }
46
+ // output Dec 19-23 if same month and year
47
+ if (
48
+ start.getMonth() === end.getMonth() &&
49
+ start.getFullYear() === end.getFullYear()
50
+ ) {
51
+ return `${start.toLocaleString("default", {
52
+ month: "short",
53
+ timeZone: tz,
54
+ })} ${start.toLocaleString("default", {
55
+ timeZone: tz,
56
+ day: "numeric",
57
+ })}-${end.toLocaleString("default", {
58
+ timeZone: tz,
59
+ day: "numeric",
60
+ })}`;
61
+ }
62
+
63
+ // output Dec 19 - Jan 2 if different month and year
64
+ return `${start.toLocaleString("default", {
65
+ month: "short",
66
+ timeZone: tz,
67
+ })} ${start.getDate()} - ${end.toLocaleString("default", {
68
+ month: "short",
69
+ timeZone: tz,
70
+ })} ${end.getDate()}`;
71
+ }
72
+
73
+ checkInTime(tz) {
74
+ return new Date(this.checkInDateTime).toLocaleString("default", {
75
+ hour: "numeric",
76
+ minute: "numeric",
77
+ timeZone: tz,
78
+ });
79
+ }
80
+
81
+ checkOutTime(tz) {
82
+ return new Date(this.checkOutDateTime).toLocaleString("default", {
83
+ hour: "numeric",
84
+ minute: "numeric",
85
+ timeZone: tz,
86
+ });
87
+ }
88
+ }
89
+
90
+ Object.defineReservation(Reservation.prototype, "schema", {
91
+ value: schema,
92
+ });
93
+
94
+ Object.defineReservation(Reservation.prototype, "validator", {
95
+ get: function () {
96
+ return validator;
97
+ },
98
+ });
99
+
100
+ Object.defineReservation(Reservation, "validProperties", {
101
+ value: Object.keys(schema.properties),
102
+ });
103
+
104
+ module.exports = Reservation;
@@ -0,0 +1,218 @@
1
+ // create the Room model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/room.json");
4
+ const deviceSchema = require("../schemas/definitions.json");
5
+ const Kohost = require("./Kohost");
6
+ const cloneDeep = require("lodash.clonedeep");
7
+
8
+ // device dependencies
9
+ const Switch = require("./Switch");
10
+ const Dimmer = require("./Dimmer");
11
+ const Thermostat = require("./Thermostat");
12
+ const Lock = require("./Lock");
13
+ const WindowCovering = require("./WindowCovering");
14
+ const Courtesy = require("./Courtesy");
15
+ const Camera = require("./Camera");
16
+ const Alarm = require("./Alarm");
17
+ const MediaSource = 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
+ /**
28
+ * @typedef {import("../schemas/RoomSchema").Room} RoomType
29
+ * Create a Room instance.
30
+ * @constructor
31
+ * @param {RoomType} room - The room object of type Room.
32
+ */
33
+ constructor(room) {
34
+ const roomData = mapRoomData(room);
35
+ super(roomData);
36
+ }
37
+
38
+ static getDevicePath(type) {
39
+ const validTypes = deviceSchema.definitions.type.enum;
40
+ if (!validTypes.includes(type))
41
+ throw new Error("Invalid device type:" + type);
42
+ switch (type) {
43
+ case "tv":
44
+ case "dvr":
45
+ case "appleTv":
46
+ case "discPlayer":
47
+ case "mediaPlayer":
48
+ case "uncontrolledDevice":
49
+ case "mediaSource":
50
+ return "mediaSources";
51
+ case "courtesy":
52
+ return type;
53
+ case "switch":
54
+ return "switches";
55
+ default:
56
+ return `${type}s`;
57
+ }
58
+ }
59
+
60
+ static getDeviceTypeFromPath(path) {
61
+ const validPaths = [
62
+ "dimmers",
63
+ "switches",
64
+ "thermostats",
65
+ "locks",
66
+ "windowCoverings",
67
+ "courtesy",
68
+ "cameras",
69
+ "mediaSources",
70
+ "motionSensors",
71
+ "alarms",
72
+ ];
73
+ if (!validPaths.includes(path))
74
+ throw new Error("Invalid device path:" + path);
75
+ switch (path) {
76
+ case "courtesy":
77
+ return path;
78
+ case "switches":
79
+ return "switch";
80
+ default:
81
+ return path.slice(0, -1);
82
+ }
83
+ }
84
+
85
+ get hasDimmer() {
86
+ return this.dimmers?.length > 0;
87
+ }
88
+
89
+ get hasSwitch() {
90
+ return this.switches?.length > 0;
91
+ }
92
+
93
+ get hasWindowCovering() {
94
+ return this.windowCoverings?.length > 0;
95
+ }
96
+
97
+ get hasShade() {
98
+ return this.hasWindowCovering;
99
+ }
100
+
101
+ get hasThermostat() {
102
+ return this.thermostats?.length > 0;
103
+ }
104
+
105
+ get hasClimate() {
106
+ return this.hasThermostat;
107
+ }
108
+
109
+ get hasLock() {
110
+ return this.locks?.length > 0;
111
+ }
112
+
113
+ get hasCourtesy() {
114
+ return this.courtesy?.length > 0;
115
+ }
116
+
117
+ get hasCamera() {
118
+ return this.cameras?.length > 0;
119
+ }
120
+
121
+ get hasAlarm() {
122
+ return this.alarms?.length > 0;
123
+ }
124
+
125
+ get hasMedia() {
126
+ return this.mediaSources?.length > 0;
127
+ }
128
+
129
+ get hasLight() {
130
+ const hasSubTypeLight = this.switches?.some((sw) => {
131
+ return sw.subType === "light" || sw.subType === "fan";
132
+ });
133
+ return this.hasDimmer || hasSubTypeLight;
134
+ }
135
+
136
+ get occupied() {
137
+ const now = new Date();
138
+ const lastOccupied = new Date(this.occupiedAt);
139
+ const diff = now - lastOccupied;
140
+ // check if the room has been occupied in the last 60 minutes
141
+ return diff < 60 * 60 * 1000;
142
+ }
143
+ }
144
+
145
+ Object.defineProperty(Room.prototype, "schema", {
146
+ value: schema,
147
+ });
148
+
149
+ Object.defineProperty(Room.prototype, "validator", {
150
+ get: function () {
151
+ return validator;
152
+ },
153
+ });
154
+
155
+ Object.defineProperty(Room, "validProperties", {
156
+ value: Object.keys(schema.properties),
157
+ });
158
+
159
+ function mapRoomData(data) {
160
+ const roomData = cloneDeep(data);
161
+ roomData.dimmers?.map((dimmer) => {
162
+ if (dimmer instanceof Dimmer) return dimmer;
163
+ else return new Dimmer(dimmer);
164
+ });
165
+ roomData.switches?.map((switch_) => {
166
+ if (switch_ instanceof Switch) return switch_;
167
+ else return new Switch(switch_);
168
+ });
169
+
170
+ roomData.windowCoverings?.map((windowCovering) => {
171
+ if (windowCovering instanceof WindowCovering) return windowCovering;
172
+ else return new WindowCovering(windowCovering);
173
+ });
174
+
175
+ roomData.thermostats?.map((thermostat) => {
176
+ if (thermostat instanceof Thermostat) return thermostat;
177
+ else return new Thermostat(thermostat);
178
+ });
179
+
180
+ roomData.locks?.map((lock) => {
181
+ if (lock instanceof Lock) return lock;
182
+ else return new Lock(lock);
183
+ });
184
+
185
+ roomData.courtesy?.map((courtesy) => {
186
+ if (courtesy instanceof Courtesy) return courtesy;
187
+ else return new Courtesy(courtesy);
188
+ });
189
+
190
+ roomData.mediaSources?.map((source) => {
191
+ if (source instanceof MediaSource) return source;
192
+ else return new MediaSource(source);
193
+ });
194
+
195
+ roomData.cameras?.map((camera) => {
196
+ if (camera instanceof Camera) return camera;
197
+ else return new Camera(camera);
198
+ });
199
+
200
+ roomData.alarms?.map((alarm) => {
201
+ if (alarm instanceof Alarm) return alarm;
202
+ else return new Alarm(alarm);
203
+ });
204
+
205
+ roomData.motionSensors?.map((motionSensor) => {
206
+ if (motionSensor instanceof MotionSensor) return motionSensor;
207
+ else return new MotionSensor(motionSensor);
208
+ });
209
+
210
+ roomData.scenes?.map((scene) => {
211
+ if (scene instanceof Scene) return scene;
212
+ else return new Scene(scene);
213
+ });
214
+
215
+ return roomData;
216
+ }
217
+
218
+ module.exports = Room;
@@ -0,0 +1,189 @@
1
+ const schemas = require("../utils/schema");
2
+ const schema = require("../schemas/scene.json");
3
+ const Kohost = require("./Kohost");
4
+ const SetSceneCommand = require("../Commands/SetSceneCommand");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class Scene extends Kohost {
10
+ /**
11
+ * @typedef {import("../schemas/SceneSchema").Scene} SceneType
12
+ * Create a Scene instance.
13
+ * @constructor
14
+ * @param {SceneType} scene - The scene object of type Scene.
15
+ */
16
+ constructor(scene) {
17
+ super(scene);
18
+ }
19
+
20
+ static createSceneCommandPayload(room, scene, restore) {
21
+ const commandsByDriver = [];
22
+
23
+ const sceneDevices = scene?.devices || {};
24
+ const sceneId = scene.id;
25
+
26
+ for (const deviceType in sceneDevices) {
27
+ const sceneData = sceneDevices[deviceType];
28
+
29
+ const roomDevices = room[deviceType];
30
+
31
+ if (sceneId === "1" && restore && deviceType !== "thermostats") continue;
32
+
33
+ for (const data of sceneData) {
34
+ const { id, ...deviceProps } = data;
35
+ if (id === "*") {
36
+ for (const device of roomDevices) {
37
+ const driver = device.driver;
38
+ const deviceCmd = {
39
+ id: device.systemData?.id,
40
+ };
41
+ for (const prop in deviceProps) {
42
+ if (prop === "setpointDelta") {
43
+ const delta = deviceProps[prop];
44
+ const currentMode = device.hvacMode;
45
+ const setpoints = device.setpoints;
46
+ const minAutoDelta = device.minAutoDelta;
47
+ const currentSetpoint = setpoints[currentMode];
48
+
49
+ if (currentMode === "heat") {
50
+ let setpointValue = Math.min(
51
+ currentSetpoint.min,
52
+ currentSetpoint.value - delta
53
+ );
54
+
55
+ if (restore) {
56
+ setpointValue = Math.min(
57
+ currentSetpoint.max,
58
+ currentSetpoint.value + delta
59
+ );
60
+ }
61
+
62
+ deviceCmd.setpoints = {
63
+ heat: {
64
+ value: setpointValue,
65
+ },
66
+ };
67
+ }
68
+ if (currentMode === "cool") {
69
+ let setpointValue = Math.max(
70
+ currentSetpoint.max,
71
+ currentSetpoint.value + delta
72
+ );
73
+
74
+ if (restore) {
75
+ setpointValue = Math.max(
76
+ currentSetpoint.min,
77
+ currentSetpoint.value - delta
78
+ );
79
+ }
80
+ deviceCmd.setpoints = {
81
+ cool: {
82
+ value: setpointValue,
83
+ },
84
+ };
85
+ }
86
+
87
+ if (currentMode === "auto") {
88
+ if (!currentSetpoint && setpoints.cool && setpoints.heat) {
89
+ let heatSetpoint = Math.min(
90
+ setpoints.heat.min,
91
+ setpoints.heat.value - delta
92
+ );
93
+
94
+ let coolSetpoint = Math.max(
95
+ setpoints.cool.max,
96
+ setpoints.cool.value + delta
97
+ );
98
+
99
+ if (restore) {
100
+ heatSetpoint = Math.min(
101
+ setpoints.heat.max,
102
+ setpoints.heat.value + delta
103
+ );
104
+
105
+ coolSetpoint = Math.max(
106
+ setpoints.cool.min,
107
+ setpoints.cool.value - delta
108
+ );
109
+ }
110
+
111
+ // make sure the delta is not less than the minAutoDelta
112
+ if (Math.abs(heatSetpoint - coolSetpoint) < minAutoDelta) {
113
+ continue;
114
+ }
115
+
116
+ deviceCmd.setpoints = {
117
+ heat: {
118
+ value: heatSetpoint,
119
+ },
120
+ cool: {
121
+ value: coolSetpoint,
122
+ },
123
+ };
124
+ }
125
+ }
126
+
127
+ if (currentMode === "off") {
128
+ // move to next loop
129
+ continue;
130
+ }
131
+ } else {
132
+ deviceCmd[prop] = deviceProps[prop];
133
+ }
134
+ }
135
+
136
+ // move to next loop if the only key in deviceCmd is id
137
+ if (Object.keys(deviceCmd).length === 1) {
138
+ continue;
139
+ }
140
+
141
+ const driverIndex = commandsByDriver.findIndex(
142
+ (c) => c.driver === driver
143
+ );
144
+ if (driverIndex >= 0) {
145
+ commandsByDriver[driverIndex].command.devices.push(deviceCmd);
146
+ } else {
147
+ commandsByDriver.push({
148
+ driver,
149
+ command: {
150
+ id: sceneId,
151
+ devices: [deviceCmd],
152
+ },
153
+ });
154
+ }
155
+ }
156
+ }
157
+ /**
158
+ * TODO: handle individual device ids
159
+ */
160
+ }
161
+ }
162
+
163
+ const commands = commandsByDriver.map((c) => {
164
+ const command = new SetSceneCommand(c.command);
165
+ return {
166
+ driver: c.driver,
167
+ command,
168
+ };
169
+ });
170
+
171
+ return commands;
172
+ }
173
+ }
174
+
175
+ Object.defineProperty(Scene.prototype, "schema", {
176
+ value: schema,
177
+ });
178
+
179
+ Object.defineProperty(Scene.prototype, "validator", {
180
+ get: function () {
181
+ return validator;
182
+ },
183
+ });
184
+
185
+ Object.defineProperty(Scene, "validProperties", {
186
+ value: Object.keys(schema.properties),
187
+ });
188
+
189
+ module.exports = Scene;
@@ -0,0 +1,35 @@
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
+ /**
11
+ * @typedef {import("../schemas/ShortLinkSchema").ShortLink} ShortLinkType
12
+ * Create a ShortLink instance.
13
+ * @constructor
14
+ * @param {ShortLinkType} shortlink - The shortlink object of type ShortLink.
15
+ */
16
+ constructor(shortlink) {
17
+ super(shortlink);
18
+ }
19
+ }
20
+
21
+ Object.defineProperty(ShortLink.prototype, "schema", {
22
+ value: schema,
23
+ });
24
+
25
+ Object.defineProperty(ShortLink.prototype, "validator", {
26
+ get: function () {
27
+ return validator;
28
+ },
29
+ });
30
+
31
+ Object.defineProperty(ShortLink, "validProperties", {
32
+ value: Object.keys(schema.properties),
33
+ });
34
+
35
+ module.exports = ShortLink;
@@ -0,0 +1,35 @@
1
+ // Create the SMS Message Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/smsMessage.json");
4
+ const Kohost = require("./Kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class SMSMessage extends Kohost {
10
+ /**
11
+ * @typedef {import("../schemas/SmsMessageSchema").SmsMessage} SmsMessageType
12
+ * Create a SmsMessage instance.
13
+ * @constructor
14
+ * @param {SmsMessageType} message - The message object of type SmsMessage.
15
+ */
16
+ constructor(message) {
17
+ super(message);
18
+ }
19
+ }
20
+
21
+ Object.defineProperty(SMSMessage.prototype, "schema", {
22
+ value: schema,
23
+ });
24
+
25
+ Object.defineProperty(SMSMessage.prototype, "validator", {
26
+ get: function () {
27
+ return validator;
28
+ },
29
+ });
30
+
31
+ Object.defineProperty(SMSMessage, "validProperties", {
32
+ value: Object.keys(schema.properties),
33
+ });
34
+
35
+ module.exports = SMSMessage;