@kohost/api-client 3.0.0-beta.9 → 3.0.0-beta.90

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 (277) hide show
  1. package/README.md +71 -0
  2. package/dist/cjs/AMQPClient/index.js +296 -0
  3. package/dist/cjs/{Client.js → Client/index.js} +1907 -598
  4. package/dist/cjs/Commands/CheckInReservationCommand.js +19 -0
  5. package/dist/cjs/Commands/CheckOutReservationCommand.js +20 -0
  6. package/dist/cjs/Commands/Command.js +34 -0
  7. package/dist/cjs/Commands/CreateImageUploadEndpointCommand.js +17 -0
  8. package/dist/cjs/Commands/CreateShortLinkCommand.js +20 -0
  9. package/dist/cjs/Commands/DiscoverCategoriesCommand.js +20 -0
  10. package/dist/cjs/Commands/DiscoverReservationSpaceCategoryAvailabilitiesCommand.js +20 -0
  11. package/dist/cjs/Commands/DiscoverReservationsCommand.js +20 -0
  12. package/dist/cjs/Commands/DiscoverRoomsCommand.js +37 -0
  13. package/dist/cjs/Commands/DiscoverUsersCommand.js +19 -0
  14. package/dist/cjs/Commands/GetMobileKeyCommand.js +24 -0
  15. package/dist/cjs/Commands/GetProductsCommand.js +17 -0
  16. package/dist/cjs/Commands/OCRDocumentCommand.js +15 -0
  17. package/dist/cjs/Commands/SellProductsCommand.js +17 -0
  18. package/dist/cjs/Commands/SendEmailCommand.js +24 -0
  19. package/dist/cjs/Commands/SendSMSCommand.js +21 -0
  20. package/dist/cjs/Commands/SetAlarmCommand.js +17 -0
  21. package/dist/cjs/Commands/SetCourtesyCommand.js +17 -0
  22. package/dist/cjs/Commands/SetDimmerCommand.js +17 -0
  23. package/dist/cjs/Commands/SetLockCommand.js +17 -0
  24. package/dist/cjs/Commands/SetMediaCommand.js +17 -0
  25. package/dist/cjs/Commands/SetSceneCommand.js +17 -0
  26. package/dist/cjs/Commands/SetSwitchCommand.js +17 -0
  27. package/dist/cjs/Commands/SetThermostatCommand.js +17 -0
  28. package/dist/cjs/Commands/SetWindowCoveringCommand.js +17 -0
  29. package/dist/cjs/Commands/UpdateReservationCommand.js +19 -0
  30. package/dist/cjs/Commands/UpdateUserCommand.js +41 -0
  31. package/dist/cjs/Commands/UploadImageCommand.js +17 -0
  32. package/dist/cjs/Commands/index.js +57 -0
  33. package/dist/cjs/Errors/AppError.js +8 -0
  34. package/dist/cjs/Errors/AuthenticationError.js +9 -0
  35. package/dist/cjs/Errors/AuthorizationError.js +9 -0
  36. package/dist/cjs/Errors/ConflictError.js +9 -0
  37. package/dist/cjs/Errors/DeviceCommError.js +9 -0
  38. package/dist/cjs/Errors/LoginError.js +9 -0
  39. package/dist/cjs/Errors/NotFoundError.js +9 -0
  40. package/dist/cjs/Errors/RequestError.js +9 -0
  41. package/dist/cjs/Errors/SystemCommError.js +9 -0
  42. package/dist/cjs/Errors/TokenExpiredError.js +9 -0
  43. package/dist/cjs/Errors/UnprocessableRequestError.js +9 -0
  44. package/dist/cjs/Errors/ValidationError.js +9 -0
  45. package/dist/cjs/Errors/index.js +16 -0
  46. package/dist/cjs/Events/ApplicationInUseEvent.js +21 -0
  47. package/dist/cjs/Events/ApplicationOutOfUseEvent.js +21 -0
  48. package/dist/cjs/Events/EmailEvent.js +18 -0
  49. package/dist/cjs/Events/Event.js +55 -0
  50. package/dist/cjs/Events/SMSEvent.js +18 -0
  51. package/dist/cjs/Events/SMSSentEvent.js +17 -0
  52. package/dist/cjs/Events/SceneSetEvent.js +17 -0
  53. package/dist/cjs/Events/ShortLinkCreatedEvent.js +17 -0
  54. package/dist/cjs/Events/SystemAlarmUpdatedEvent.js +17 -0
  55. package/dist/cjs/Events/SystemCameraUpdatedEvent.js +17 -0
  56. package/dist/cjs/Events/SystemCategoryUpdatedEvent.js +17 -0
  57. package/dist/cjs/Events/SystemCourtesyUpdatedEvent.js +17 -0
  58. package/dist/cjs/Events/SystemCredentialUpdatedEvent.js +17 -0
  59. package/dist/cjs/Events/SystemDimmerUpdatedEvent.js +17 -0
  60. package/dist/cjs/Events/SystemEntityDeletedEvent.js +17 -0
  61. package/dist/cjs/Events/SystemGatewayUpdatedEvent.js +17 -0
  62. package/dist/cjs/Events/SystemLockUpdatedEvent.js +17 -0
  63. package/dist/cjs/Events/SystemMediaSourceUpdatedEvent.js +17 -0
  64. package/dist/cjs/Events/SystemMotionSensorUpdatedEvent.js +17 -0
  65. package/dist/cjs/Events/SystemOrganizationUpdatedEvent.js +17 -0
  66. package/dist/cjs/Events/SystemProductUpdatedEvent.js +17 -0
  67. package/dist/cjs/Events/SystemPropertyUpdatedEvent.js +17 -0
  68. package/dist/cjs/Events/SystemReservationUpdatedEvent.js +17 -0
  69. package/dist/cjs/Events/SystemSceneControllerUpdatedEvent.js +17 -0
  70. package/dist/cjs/Events/SystemSpaceUpdatedEvent.js +17 -0
  71. package/dist/cjs/Events/SystemSwitchUpdatedEvent.js +17 -0
  72. package/dist/cjs/Events/SystemThermostatUpdatedEvent.js +17 -0
  73. package/dist/cjs/Events/SystemUserUpdatedEvent.js +17 -0
  74. package/dist/cjs/Events/SystemWindowCoveringUpdatedEvent.js +17 -0
  75. package/dist/cjs/Events/index.js +65 -0
  76. package/dist/cjs/Models/Alarm.js +35 -0
  77. package/dist/cjs/Models/Announcement.js +34 -0
  78. package/dist/cjs/Models/Camera.js +35 -0
  79. package/dist/cjs/Models/Category.js +36 -0
  80. package/dist/cjs/Models/Courtesy.js +39 -0
  81. package/dist/cjs/Models/Credential.js +35 -0
  82. package/dist/cjs/Models/Dimmer.js +61 -0
  83. package/dist/cjs/Models/DiscoveredDevice.js +36 -0
  84. package/dist/cjs/Models/EmailMessage.js +35 -0
  85. package/dist/cjs/Models/EnergyReport.js +35 -0
  86. package/dist/cjs/Models/EnergyReportShard.js +35 -0
  87. package/dist/cjs/Models/Gateway.js +35 -0
  88. package/dist/cjs/Models/Identification.js +38 -0
  89. package/dist/cjs/Models/Kohost.js +96 -0
  90. package/dist/cjs/Models/Lock.js +39 -0
  91. package/dist/cjs/Models/MediaFile.js +48 -0
  92. package/dist/cjs/Models/MediaSource.js +35 -0
  93. package/dist/cjs/Models/MotionSensor.js +35 -0
  94. package/dist/cjs/Models/Order.js +97 -0
  95. package/dist/cjs/Models/Organization.js +34 -0
  96. package/dist/cjs/Models/Product.js +35 -0
  97. package/dist/cjs/Models/Property.js +34 -0
  98. package/dist/cjs/Models/Reservation.js +114 -0
  99. package/dist/cjs/Models/Room.js +217 -0
  100. package/dist/cjs/Models/Scene.js +169 -0
  101. package/dist/cjs/Models/ShortLink.js +35 -0
  102. package/dist/cjs/Models/SmsMessage.js +35 -0
  103. package/dist/cjs/Models/Space.js +97 -0
  104. package/dist/cjs/Models/Switch.js +39 -0
  105. package/dist/cjs/Models/SystemUser.js +55 -0
  106. package/dist/cjs/Models/Thermostat.js +86 -0
  107. package/dist/cjs/Models/Ticket.js +55 -0
  108. package/dist/cjs/Models/User.js +115 -0
  109. package/dist/cjs/Models/WindowCovering.js +55 -0
  110. package/dist/cjs/Models/index.js +72 -0
  111. package/dist/cjs/SocketIoClient/index.js +74 -0
  112. package/dist/cjs/defs/deviceTypes.js +15 -0
  113. package/dist/cjs/defs/formalDeviceTypes.js +6 -0
  114. package/dist/cjs/defs/index.js +11 -0
  115. package/dist/cjs/{index.cjs.js → index.js} +7 -1
  116. package/dist/cjs/schemas/AlarmSchema.d.ts +158 -0
  117. package/dist/cjs/schemas/AnnouncementSchema.d.ts +59 -0
  118. package/dist/cjs/schemas/CameraSchema.d.ts +149 -0
  119. package/dist/cjs/schemas/CategorySchema.d.ts +82 -0
  120. package/dist/cjs/schemas/CourtesySchema.d.ts +148 -0
  121. package/dist/cjs/schemas/CredentialSchema.d.ts +53 -0
  122. package/dist/cjs/schemas/DefinitionsSchema.d.ts +10 -0
  123. package/dist/cjs/schemas/DimmerSchema.d.ts +147 -0
  124. package/dist/cjs/schemas/DiscoveredDeviceSchema.d.ts +39 -0
  125. package/dist/cjs/schemas/EmailMessageSchema.d.ts +49 -0
  126. package/dist/cjs/schemas/EnergyReportSchema.d.ts +57 -0
  127. package/dist/cjs/schemas/EnergyReportShardSchema.d.ts +61 -0
  128. package/dist/cjs/schemas/GatewaySchema.d.ts +145 -0
  129. package/dist/cjs/schemas/IdentificationSchema.d.ts +45 -0
  130. package/dist/cjs/schemas/LockSchema.d.ts +152 -0
  131. package/dist/cjs/schemas/MediaFileSchema.d.ts +43 -0
  132. package/dist/cjs/schemas/MediaSourceSchema.d.ts +244 -0
  133. package/dist/cjs/schemas/MotionSensorSchema.d.ts +143 -0
  134. package/dist/cjs/schemas/OrderSchema.d.ts +91 -0
  135. package/dist/cjs/schemas/OrganizationSchema.d.ts +34 -0
  136. package/dist/cjs/schemas/PaymentSchema.d.ts +33 -0
  137. package/dist/cjs/schemas/ProductSchema.d.ts +66 -0
  138. package/dist/cjs/schemas/PropertySchema.d.ts +144 -0
  139. package/dist/cjs/schemas/ReservationSchema.d.ts +119 -0
  140. package/dist/cjs/schemas/RoomSchema.d.ts +1103 -0
  141. package/dist/cjs/schemas/SceneSchema.d.ts +57 -0
  142. package/dist/cjs/schemas/ShortLinkSchema.d.ts +20 -0
  143. package/dist/cjs/schemas/SmsMessageSchema.d.ts +40 -0
  144. package/dist/cjs/schemas/SpaceSchema.d.ts +73 -0
  145. package/dist/cjs/schemas/SwitchSchema.d.ts +148 -0
  146. package/dist/cjs/schemas/SystemUserSchema.d.ts +194 -0
  147. package/dist/cjs/schemas/ThermostatSchema.d.ts +178 -0
  148. package/dist/cjs/schemas/TicketSchema.d.ts +89 -0
  149. package/dist/cjs/schemas/UserSchema.d.ts +287 -0
  150. package/dist/cjs/schemas/WindowCoveringSchema.d.ts +147 -0
  151. package/dist/cjs/schemas/alarm.json +81 -0
  152. package/dist/cjs/schemas/announcement.json +36 -0
  153. package/dist/cjs/schemas/camera.json +50 -0
  154. package/dist/cjs/schemas/category.json +42 -0
  155. package/dist/cjs/schemas/courtesy.json +48 -0
  156. package/dist/cjs/schemas/credential.json +44 -0
  157. package/dist/cjs/schemas/definitions.json +223 -0
  158. package/dist/cjs/schemas/dimmer.json +42 -0
  159. package/dist/cjs/schemas/discoveredDevice.json +31 -0
  160. package/dist/cjs/schemas/emailMessage.json +71 -0
  161. package/dist/cjs/schemas/energyReport.json +86 -0
  162. package/dist/cjs/schemas/energyReportShard.json +75 -0
  163. package/dist/cjs/schemas/gateway.json +34 -0
  164. package/dist/cjs/schemas/identification.json +61 -0
  165. package/dist/cjs/schemas/lock.json +50 -0
  166. package/dist/cjs/schemas/mediaFile.json +70 -0
  167. package/dist/cjs/schemas/mediaSource.json +187 -0
  168. package/dist/cjs/schemas/motionSensor.json +32 -0
  169. package/dist/cjs/schemas/order.json +182 -0
  170. package/dist/cjs/schemas/organization.json +40 -0
  171. package/dist/cjs/schemas/payment.json +47 -0
  172. package/dist/cjs/schemas/product.json +41 -0
  173. package/dist/cjs/schemas/property.json +347 -0
  174. package/dist/cjs/schemas/reservation.json +137 -0
  175. package/dist/cjs/schemas/room.json +98 -0
  176. package/dist/cjs/schemas/scene.json +121 -0
  177. package/dist/cjs/schemas/shortLink.json +30 -0
  178. package/dist/cjs/schemas/smsMessage.json +61 -0
  179. package/dist/cjs/schemas/space.json +129 -0
  180. package/dist/cjs/schemas/switch.json +44 -0
  181. package/dist/cjs/schemas/systemUser.json +98 -0
  182. package/dist/cjs/schemas/thermostat.json +150 -0
  183. package/dist/cjs/schemas/ticket.json +176 -0
  184. package/dist/cjs/schemas/user.json +170 -0
  185. package/dist/cjs/schemas/windowCovering.json +42 -0
  186. package/dist/cjs/utils/errorFactory.js +8 -0
  187. package/dist/cjs/utils/eventFactory.js +10 -0
  188. package/dist/cjs/utils/getDeviceTypes.js +7 -0
  189. package/dist/cjs/utils/getFormalDeviceType.js +5 -0
  190. package/dist/cjs/utils/index.js +11 -0
  191. package/dist/cjs/utils/schema.js +25 -0
  192. package/dist/esm/Client.js +2013 -637
  193. package/dist/esm/Client.js.map +4 -4
  194. package/dist/esm/Commands.js +499 -120
  195. package/dist/esm/Commands.js.map +3 -3
  196. package/dist/esm/Errors.js +73 -22
  197. package/dist/esm/Errors.js.map +3 -3
  198. package/dist/esm/Events.js +414 -73
  199. package/dist/esm/Events.js.map +3 -3
  200. package/dist/esm/Models.js +3297 -3915
  201. package/dist/esm/Models.js.map +4 -4
  202. package/dist/esm/SocketIoClient.js +4846 -0
  203. package/dist/esm/SocketIoClient.js.map +7 -0
  204. package/dist/esm/defs.js +168 -112
  205. package/dist/esm/defs.js.map +4 -4
  206. package/dist/esm/index.js +17 -10
  207. package/dist/esm/utils.js +451 -73
  208. package/dist/esm/utils.js.map +3 -3
  209. package/dist/useCases/AdminUpdateCustomer.js +1 -1
  210. package/dist/useCases/AssignSpaceToReservation.js +32 -0
  211. package/dist/useCases/{AdminCreateProperty.js → BatchNotifyCheckIn.js} +2 -2
  212. package/dist/useCases/{AdminCreateCustomer.js → BatchNotifyCheckOut.js} +2 -2
  213. package/dist/useCases/BatchNotifyMissedCheckOut.js +32 -0
  214. package/dist/useCases/{AdminUpdateProperty.js → CheckOutReservation.js} +3 -3
  215. package/dist/useCases/{AdminListCustomers.js → CreateAnnouncement.js} +3 -3
  216. package/dist/useCases/CreateCateory.js +32 -0
  217. package/dist/useCases/CreateImageUploadEndpoint.js +32 -0
  218. package/dist/useCases/CreateMediaSource.js +32 -0
  219. package/dist/useCases/CreateOrganization.js +32 -0
  220. package/dist/useCases/{AdminLoginUser.js → CreateProperty.js} +2 -2
  221. package/dist/useCases/DeleteAnnouncement.js +32 -0
  222. package/dist/useCases/DeleteCategory.js +32 -0
  223. package/dist/useCases/DeleteMediaFile.js +32 -0
  224. package/dist/useCases/DeleteMediaSource.js +32 -0
  225. package/dist/useCases/{AdminCreateAdminUser.js → DescribeAnnouncement.js} +4 -4
  226. package/dist/useCases/{ListIntegrations.js → DescribeCategory.js} +3 -3
  227. package/dist/useCases/{DeleteSource.js → DescribeLockCredential.js} +3 -3
  228. package/dist/useCases/{AdminListAdminUsers.js → DescribeMediaSource.js} +3 -3
  229. package/dist/useCases/DescribeMyAccessCredentials.js +32 -0
  230. package/dist/useCases/{AdminDescribeCustomer.js → DescribeOrganization.js} +2 -2
  231. package/dist/useCases/{DescribeIntegration.js → DescribeProduct.js} +2 -2
  232. package/dist/useCases/DescribeProperty.js +32 -0
  233. package/dist/useCases/DescribeReservationEarlyCheckInProducts.js +32 -0
  234. package/dist/useCases/DescribeReservationLateCheckOutProducts.js +32 -0
  235. package/dist/useCases/{AdminDescribeProperty.js → DescribeReservationRoomUpgrades.js} +2 -2
  236. package/dist/useCases/{AdminRefreshToken.js → ListAnnouncements.js} +3 -3
  237. package/dist/useCases/ListCategories.js +32 -0
  238. package/dist/useCases/ListMediaSources.js +32 -0
  239. package/dist/useCases/{CreateSource.js → ListMyOrders.js} +4 -4
  240. package/dist/useCases/{AdminListProperties.js → ListMyTickets.js} +2 -2
  241. package/dist/useCases/ListOrders.js +32 -0
  242. package/dist/useCases/{DeleteIntegration.js → ListOrganizations.js} +3 -3
  243. package/dist/useCases/ListProperties.js +32 -0
  244. package/dist/useCases/ListScenes.js +32 -0
  245. package/dist/useCases/ListTeam.js +32 -0
  246. package/dist/useCases/ListUserOrders.js +32 -0
  247. package/dist/useCases/ListUserSpaces.js +32 -0
  248. package/dist/useCases/LogoutUser.js +32 -0
  249. package/dist/useCases/PurchaseReservationEarlyCheckInProducts.js +32 -0
  250. package/dist/useCases/PurchaseReservationLateCheckOutProducts.js +32 -0
  251. package/dist/useCases/{CreateIntegrationDeviceMapEntry.js → PurchaseReservationRoomUpgrades.js} +2 -2
  252. package/dist/useCases/RequestLoginLink.js +1 -1
  253. package/dist/useCases/{CreateIntegration.js → RequestMyKeyToken.js} +2 -2
  254. package/dist/useCases/RequestPWAToken.js +32 -0
  255. package/dist/useCases/SendCheckInSMS.js +32 -0
  256. package/dist/useCases/SendCheckOutSMS.js +32 -0
  257. package/dist/useCases/SendRoomControlSMS.js +32 -0
  258. package/dist/useCases/{SetSource.js → SetDimmer.js} +2 -2
  259. package/dist/useCases/{DescribeSource.js → SetMediaSource.js} +3 -3
  260. package/dist/useCases/{UpdateSource.js → SetRoomScene.js} +3 -3
  261. package/dist/useCases/SetSpaceScene.js +32 -0
  262. package/dist/useCases/TipUser.js +32 -0
  263. package/dist/useCases/UpdateAnnouncement.js +32 -0
  264. package/dist/useCases/UpdateCategory.js +32 -0
  265. package/dist/useCases/{UpdateIntegration.js → UpdateMediaSource.js} +3 -3
  266. package/dist/useCases/UpdateProperty.js +32 -0
  267. package/dist/useCases/UpdateReservationExpectedArrivalTime.js +32 -0
  268. package/dist/useCases/{ListSources.js → UploadImage.js} +4 -4
  269. package/package.json +37 -14
  270. package/dist/cjs/Commands.js +0 -643
  271. package/dist/cjs/Errors.js +0 -176
  272. package/dist/cjs/Events.js +0 -387
  273. package/dist/cjs/Models.js +0 -3612
  274. package/dist/cjs/defs.js +0 -178
  275. package/dist/cjs/utils.js +0 -250
  276. package/dist/useCases/AdminRequestLoginLink.js +0 -32
  277. package/dist/useCases/DescribeReservationCheckinStatus.js +0 -32
@@ -0,0 +1,217 @@
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
+
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 MediaSource = 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
+ /**
27
+ * @typedef {import("../schemas/RoomSchema").Room} RoomType
28
+ * Create a Room instance.
29
+ * @constructor
30
+ * @param {RoomType} room - The room object of type Room.
31
+ */
32
+ constructor(room) {
33
+ const roomData = mapRoomData(room);
34
+ super(roomData);
35
+ }
36
+
37
+ static getDevicePath(type) {
38
+ const validTypes = deviceSchema.definitions.type.enum;
39
+ if (!validTypes.includes(type))
40
+ throw new Error("Invalid device type:" + type);
41
+ switch (type) {
42
+ case "tv":
43
+ case "dvr":
44
+ case "appleTv":
45
+ case "discPlayer":
46
+ case "mediaPlayer":
47
+ case "uncontrolledDevice":
48
+ case "mediaSource":
49
+ return "mediaSources";
50
+ case "courtesy":
51
+ return type;
52
+ case "switch":
53
+ return "switches";
54
+ default:
55
+ return `${type}s`;
56
+ }
57
+ }
58
+
59
+ static getDeviceTypeFromPath(path) {
60
+ const validPaths = [
61
+ "dimmers",
62
+ "switches",
63
+ "thermostats",
64
+ "locks",
65
+ "windowCoverings",
66
+ "courtesy",
67
+ "cameras",
68
+ "mediaSources",
69
+ "motionSensors",
70
+ "alarms",
71
+ ];
72
+ if (!validPaths.includes(path))
73
+ throw new Error("Invalid device path:" + path);
74
+ switch (path) {
75
+ case "courtesy":
76
+ return path;
77
+ case "switches":
78
+ return "switch";
79
+ default:
80
+ return path.slice(0, -1);
81
+ }
82
+ }
83
+
84
+ get hasDimmer() {
85
+ return this.dimmers?.length > 0;
86
+ }
87
+
88
+ get hasSwitch() {
89
+ return this.switches?.length > 0;
90
+ }
91
+
92
+ get hasWindowCovering() {
93
+ return this.windowCoverings?.length > 0;
94
+ }
95
+
96
+ get hasShade() {
97
+ return this.hasWindowCovering;
98
+ }
99
+
100
+ get hasThermostat() {
101
+ return this.thermostats?.length > 0;
102
+ }
103
+
104
+ get hasClimate() {
105
+ return this.hasThermostat;
106
+ }
107
+
108
+ get hasLock() {
109
+ return this.locks?.length > 0;
110
+ }
111
+
112
+ get hasCourtesy() {
113
+ return this.courtesy?.length > 0;
114
+ }
115
+
116
+ get hasCamera() {
117
+ return this.cameras?.length > 0;
118
+ }
119
+
120
+ get hasAlarm() {
121
+ return this.alarms?.length > 0;
122
+ }
123
+
124
+ get hasMedia() {
125
+ return this.mediaSources?.length > 0;
126
+ }
127
+
128
+ get hasLight() {
129
+ const hasSubTypeLight = this.switches?.some((sw) => {
130
+ return sw.subType === "light" || sw.subType === "fan";
131
+ });
132
+ return this.hasDimmer || hasSubTypeLight;
133
+ }
134
+
135
+ get occupied() {
136
+ const now = new Date();
137
+ const lastOccupied = new Date(this.occupiedAt);
138
+ const diff = now - lastOccupied;
139
+ // check if the room has been occupied in the last 60 minutes
140
+ return diff < 60 * 60 * 1000;
141
+ }
142
+ }
143
+
144
+ Object.defineProperty(Room.prototype, "schema", {
145
+ value: schema,
146
+ });
147
+
148
+ Object.defineProperty(Room.prototype, "validator", {
149
+ get: function () {
150
+ return validator;
151
+ },
152
+ });
153
+
154
+ Object.defineProperty(Room, "validProperties", {
155
+ value: Object.keys(schema.properties),
156
+ });
157
+
158
+ function mapRoomData(data) {
159
+ const roomData = structuredClone(data);
160
+ roomData.dimmers?.map((dimmer) => {
161
+ if (dimmer instanceof Dimmer) return dimmer;
162
+ else return new Dimmer(dimmer);
163
+ });
164
+ roomData.switches?.map((switch_) => {
165
+ if (switch_ instanceof Switch) return switch_;
166
+ else return new Switch(switch_);
167
+ });
168
+
169
+ roomData.windowCoverings?.map((windowCovering) => {
170
+ if (windowCovering instanceof WindowCovering) return windowCovering;
171
+ else return new WindowCovering(windowCovering);
172
+ });
173
+
174
+ roomData.thermostats?.map((thermostat) => {
175
+ if (thermostat instanceof Thermostat) return thermostat;
176
+ else return new Thermostat(thermostat);
177
+ });
178
+
179
+ roomData.locks?.map((lock) => {
180
+ if (lock instanceof Lock) return lock;
181
+ else return new Lock(lock);
182
+ });
183
+
184
+ roomData.courtesy?.map((courtesy) => {
185
+ if (courtesy instanceof Courtesy) return courtesy;
186
+ else return new Courtesy(courtesy);
187
+ });
188
+
189
+ roomData.mediaSources?.map((source) => {
190
+ if (source instanceof MediaSource) return source;
191
+ else return new MediaSource(source);
192
+ });
193
+
194
+ roomData.cameras?.map((camera) => {
195
+ if (camera instanceof Camera) return camera;
196
+ else return new Camera(camera);
197
+ });
198
+
199
+ roomData.alarms?.map((alarm) => {
200
+ if (alarm instanceof Alarm) return alarm;
201
+ else return new Alarm(alarm);
202
+ });
203
+
204
+ roomData.motionSensors?.map((motionSensor) => {
205
+ if (motionSensor instanceof MotionSensor) return motionSensor;
206
+ else return new MotionSensor(motionSensor);
207
+ });
208
+
209
+ roomData.scenes?.map((scene) => {
210
+ if (scene instanceof Scene) return scene;
211
+ else return new Scene(scene);
212
+ });
213
+
214
+ return roomData;
215
+ }
216
+
217
+ module.exports = Room;
@@ -0,0 +1,169 @@
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
+ /**
10
+ * @typedef {import("../schemas/SceneSchema").Scene} SceneType
11
+ * Create a Scene instance.
12
+ * @constructor
13
+ * @param {SceneType} scene - The scene object of type Scene.
14
+ */
15
+ constructor(scene) {
16
+ super(scene);
17
+ }
18
+
19
+ static getRoomSceneDeviceData(room, scene, restore) {
20
+ const deviceData = [];
21
+
22
+ const sceneDevices = scene?.devices || {};
23
+ const sceneId = scene.id;
24
+
25
+ for (const deviceType in sceneDevices) {
26
+ const sceneData = sceneDevices[deviceType];
27
+
28
+ const roomDevices = room[deviceType];
29
+
30
+ if (sceneId === "1" && restore && deviceType !== "thermostats") continue;
31
+
32
+ for (const data of sceneData) {
33
+ const { id, ...deviceProps } = data;
34
+ if (id === "*") {
35
+ for (const device of roomDevices) {
36
+ const deviceCmd = {
37
+ id: device.id,
38
+ systemId: device.systemId,
39
+ type: device.type,
40
+ driver: device.driver,
41
+ commandData: {},
42
+ };
43
+ for (const prop in deviceProps) {
44
+ if (prop === "setpointDelta") {
45
+ const delta = deviceProps[prop];
46
+ const currentMode = device.hvacMode;
47
+ const setpoints = device.setpoints;
48
+ const minAutoDelta = device.minAutoDelta;
49
+ const currentSetpoint = setpoints[currentMode];
50
+
51
+ if (currentMode === "heat") {
52
+ let setpointValue = Math.max(
53
+ currentSetpoint.min,
54
+ currentSetpoint.value - delta
55
+ );
56
+
57
+ if (restore) {
58
+ setpointValue = Math.min(
59
+ currentSetpoint.max,
60
+ currentSetpoint.value + delta
61
+ );
62
+ }
63
+
64
+ deviceCmd.commandData.setpoints = {
65
+ heat: {
66
+ value: setpointValue,
67
+ },
68
+ };
69
+ }
70
+ if (currentMode === "cool") {
71
+ let setpointValue = Math.min(
72
+ currentSetpoint.max,
73
+ currentSetpoint.value + delta
74
+ );
75
+
76
+ if (restore) {
77
+ setpointValue = Math.max(
78
+ currentSetpoint.min,
79
+ currentSetpoint.value - delta
80
+ );
81
+ }
82
+ deviceCmd.commandData.setpoints = {
83
+ cool: {
84
+ value: setpointValue,
85
+ },
86
+ };
87
+ }
88
+
89
+ if (currentMode === "auto") {
90
+ if (!currentSetpoint && setpoints.cool && setpoints.heat) {
91
+ let heatSetpoint = Math.max(
92
+ setpoints.heat.min,
93
+ setpoints.heat.value - delta
94
+ );
95
+
96
+ let coolSetpoint = Math.min(
97
+ setpoints.cool.max,
98
+ setpoints.cool.value + delta
99
+ );
100
+
101
+ if (restore) {
102
+ heatSetpoint = Math.min(
103
+ setpoints.heat.max,
104
+ setpoints.heat.value + delta
105
+ );
106
+
107
+ coolSetpoint = Math.max(
108
+ setpoints.cool.min,
109
+ setpoints.cool.value - delta
110
+ );
111
+ }
112
+
113
+ // make sure the delta is not less than the minAutoDelta
114
+ if (Math.abs(heatSetpoint - coolSetpoint) < minAutoDelta) {
115
+ continue;
116
+ }
117
+
118
+ deviceCmd.commandData.setpoints = {
119
+ heat: {
120
+ value: heatSetpoint,
121
+ },
122
+ cool: {
123
+ value: coolSetpoint,
124
+ },
125
+ };
126
+ }
127
+ }
128
+
129
+ if (currentMode === "off") {
130
+ // move to next loop
131
+ continue;
132
+ }
133
+ } else {
134
+ deviceCmd.commandData[prop] = deviceProps[prop];
135
+ }
136
+ }
137
+
138
+ // move to next loop if no keys in command data
139
+ if (Object.keys(deviceCmd.commandData).length === 0) {
140
+ continue;
141
+ }
142
+
143
+ deviceData.push(deviceCmd);
144
+ }
145
+ }
146
+ /**
147
+ * TODO: handle individual device ids
148
+ */
149
+ }
150
+ }
151
+ return deviceData;
152
+ }
153
+ }
154
+
155
+ Object.defineProperty(Scene.prototype, "schema", {
156
+ value: schema,
157
+ });
158
+
159
+ Object.defineProperty(Scene.prototype, "validator", {
160
+ get: function () {
161
+ return validator;
162
+ },
163
+ });
164
+
165
+ Object.defineProperty(Scene, "validProperties", {
166
+ value: Object.keys(schema.properties),
167
+ });
168
+
169
+ 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;
@@ -0,0 +1,97 @@
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
+
7
+ const Room = require("./Room");
8
+
9
+ schemas.add(schema);
10
+ const validator = schemas.compile(schema);
11
+
12
+ class Space extends Kohost {
13
+ /**
14
+ * @typedef {import("../schemas/SpaceSchema").Space} SpaceType
15
+ * Create a Space instance.
16
+ * @constructor
17
+ * @param {SpaceType} space - The space object of type Space.
18
+ */
19
+ constructor(space) {
20
+ const spaceData = mapSpaceData(space);
21
+ super(spaceData);
22
+ }
23
+
24
+ get floor() {
25
+ const floors = new Set();
26
+
27
+ this.room.forEach((room) => {
28
+ if (room.floor) floors.add(room.floor);
29
+ });
30
+
31
+ return floors.size == 1 ? [...floors][0] : undefined;
32
+ }
33
+
34
+ get hasDimmer() {
35
+ return this.rooms.some((room) => room.hasDimmer);
36
+ }
37
+
38
+ get hasSwitch() {
39
+ return this.rooms.some((room) => room.hasSwitch);
40
+ }
41
+
42
+ get hasWindowCovering() {
43
+ return this.rooms.some((room) => room.hasWindowCovering);
44
+ }
45
+
46
+ get hasThermostat() {
47
+ return this.rooms.some((room) => room.hasThermostat);
48
+ }
49
+
50
+ get hasLock() {
51
+ return this.rooms.some((room) => room.hasLock);
52
+ }
53
+
54
+ get hasCourtesy() {
55
+ return this.rooms.some((room) => room.hasCourtesy);
56
+ }
57
+
58
+ get hasCamera() {
59
+ return this.rooms.some((room) => room.hasCamera);
60
+ }
61
+
62
+ get hasAlarm() {
63
+ return this.rooms.some((room) => room.hasAlarm);
64
+ }
65
+
66
+ get hasMedia() {
67
+ return this.rooms.some((room) => room.hasMedia);
68
+ }
69
+ }
70
+
71
+ Object.defineProperty(Space.prototype, "schema", {
72
+ value: schema,
73
+ });
74
+
75
+ Object.defineProperty(Space.prototype, "validator", {
76
+ get: function () {
77
+ return validator;
78
+ },
79
+ });
80
+
81
+ Object.defineProperty(Space, "validProperties", {
82
+ value: Object.keys(schema.properties),
83
+ });
84
+
85
+ function mapSpaceData(data) {
86
+ const spaceData = structuredClone(data);
87
+ if (spaceData.rooms?.length) {
88
+ spaceData.rooms.map((room) => {
89
+ if (typeof room === "string") return room;
90
+ if (room instanceof Room) return room;
91
+ return new Room(room);
92
+ });
93
+ }
94
+ return spaceData;
95
+ }
96
+
97
+ module.exports = Space;
@@ -0,0 +1,39 @@
1
+ // create the Switch model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/switch.json");
4
+ const Kohost = require("./Kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class Switch extends Kohost {
10
+ /**
11
+ * @typedef {import("../schemas/SwitchSchema").Switch} SwitchType
12
+ * Create a Switch instance.
13
+ * @constructor
14
+ * @param {SwitchType} _switch - The _switch object of type Switch.
15
+ */
16
+ constructor(_switch) {
17
+ super(_switch);
18
+ }
19
+ }
20
+
21
+ Object.defineProperty(Switch.prototype, "schema", {
22
+ value: schema,
23
+ });
24
+
25
+ Object.defineProperty(Switch.prototype, "validator", {
26
+ get: function () {
27
+ return validator;
28
+ },
29
+ });
30
+
31
+ Object.defineProperty(Switch, "validProperties", {
32
+ value: Object.keys(schema.properties),
33
+ });
34
+
35
+ Object.defineProperty(Switch, "actionProperties", {
36
+ value: ["state"],
37
+ });
38
+
39
+ module.exports = Switch;
@@ -0,0 +1,55 @@
1
+ // Create the User Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/systemUser.json");
4
+ const Kohost = require("./Kohost");
5
+
6
+ schemas.add(schema);
7
+
8
+ const validator = schemas.compile(schema);
9
+
10
+ class SystemUser extends Kohost {
11
+ /**
12
+ * @typedef {import("../schemas/SystemUserSchema").SystemUser} SystemUserType
13
+ * Create a SystemUser instance.
14
+ * @constructor
15
+ * @param {SystemUserType} user - The user object of type SystemUser.
16
+ */
17
+
18
+ constructor(user) {
19
+ super(user);
20
+ }
21
+
22
+ static validatePhone(phoneNumber) {
23
+ const regex = /^\+?[1-9]\d{1,14}$/;
24
+ return regex.test(phoneNumber);
25
+ }
26
+
27
+ static validateEmail(email) {
28
+ //eslint-disable-next-line no-useless-escape
29
+ const regex =
30
+ /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
31
+ return regex.test(email);
32
+ }
33
+ }
34
+
35
+ Object.defineProperty(SystemUser.prototype, "schema", {
36
+ value: schema,
37
+ });
38
+
39
+ Object.defineProperty(SystemUser.prototype, "validator", {
40
+ get: function () {
41
+ return validator;
42
+ },
43
+ });
44
+
45
+ Object.defineProperty(SystemUser, "validProperties", {
46
+ value: Object.keys(schema.properties),
47
+ });
48
+
49
+ Object.defineProperty(SystemUser.prototype, "fullName", {
50
+ get: function () {
51
+ return `${this.firstName} ${this.lastName}`;
52
+ },
53
+ });
54
+
55
+ module.exports = SystemUser;