dt-common-device 1.2.3 → 1.2.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 (53) hide show
  1. package/dist/device/cloud/entities/CloudDevice.d.ts +1 -1
  2. package/dist/device/cloud/entities/CloudDeviceService.d.ts +1 -1
  3. package/dist/device/cloud/entities/index.d.ts +0 -1
  4. package/dist/device/cloud/entities/index.js +0 -1
  5. package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +1 -1
  6. package/dist/device/cloud/interfaces/index.d.ts +1 -1
  7. package/dist/device/cloud/interfaces/index.js +1 -1
  8. package/dist/device/local/events/EventHandler.d.ts +1 -0
  9. package/dist/device/local/events/EventHandler.js +11 -0
  10. package/dist/device/local/interfaces/IConnection.d.ts +12 -2
  11. package/dist/device/local/interfaces/IConnection.js +12 -0
  12. package/dist/device/local/interfaces/ISchedule.d.ts +25 -0
  13. package/dist/device/local/interfaces/ISchedule.js +2 -0
  14. package/dist/device/local/repository/Connection.repository.d.ts +2 -1
  15. package/dist/device/local/repository/Connection.repository.js +15 -0
  16. package/dist/device/local/repository/Hub.repository.d.ts +1 -1
  17. package/dist/device/local/repository/Schedule.repository.d.ts +8 -0
  18. package/dist/device/local/repository/Schedule.repository.js +102 -0
  19. package/dist/device/local/services/Connection.service.d.ts +3 -2
  20. package/dist/device/local/services/Connection.service.js +15 -0
  21. package/dist/device/local/services/Device.service.d.ts +0 -1
  22. package/dist/device/local/services/Device.service.js +46 -13
  23. package/dist/device/local/services/Hub.service.d.ts +1 -1
  24. package/dist/device/local/services/Hub.service.js +18 -0
  25. package/dist/device/local/services/Property.service.js +9 -0
  26. package/dist/device/local/services/Schedule.service.d.ts +8 -0
  27. package/dist/device/local/services/Schedule.service.js +23 -0
  28. package/dist/device/local/services/index.d.ts +1 -0
  29. package/dist/device/local/services/index.js +3 -1
  30. package/dist/index.d.ts +2 -3
  31. package/dist/index.js +3 -4
  32. package/package.json +4 -4
  33. package/src/device/cloud/entities/CloudDevice.ts +1 -1
  34. package/src/device/cloud/entities/CloudDeviceService.ts +1 -1
  35. package/src/device/cloud/entities/index.ts +0 -1
  36. package/src/device/cloud/interfaces/ICloudDeviceService.ts +1 -1
  37. package/src/device/cloud/interfaces/index.ts +1 -1
  38. package/src/device/local/events/EventHandler.ts +16 -0
  39. package/src/device/local/interfaces/IConnection.ts +27 -0
  40. package/src/device/local/interfaces/ISchedule.ts +40 -0
  41. package/src/device/local/repository/Connection.repository.ts +21 -1
  42. package/src/device/local/repository/Hub.repository.ts +1 -1
  43. package/src/device/local/repository/Schedule.repository.ts +56 -0
  44. package/src/device/local/services/Connection.service.ts +23 -2
  45. package/src/device/local/services/Device.service.ts +47 -25
  46. package/src/device/local/services/Hub.service.ts +20 -1
  47. package/src/device/local/services/Property.service.ts +9 -0
  48. package/src/device/local/services/Schedule.service.ts +22 -0
  49. package/src/device/local/services/index.ts +1 -0
  50. package/src/index.ts +2 -3
  51. package/src/device/cloud/entities/CloudConnection.ts +0 -13
  52. package/src/device/cloud/interfaces/ICloudConnection.ts +0 -6
  53. package/src/device/cloud/types.ts +0 -58
package/dist/index.js CHANGED
@@ -15,20 +15,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getConfig = exports.initialize = exports.LocalPropertyService = exports.LocalConnectionService = exports.LocalHubService = exports.LocalDeviceService = exports.CloudDeviceService = exports.CloudConnection = exports.DeviceFactory = exports.CloudDevice = void 0;
18
+ exports.getConfig = exports.initialize = exports.LocalScheduleService = exports.LocalPropertyService = exports.LocalConnectionService = exports.LocalHubService = exports.LocalDeviceService = exports.DeviceFactory = exports.CloudDeviceService = exports.CloudDevice = void 0;
19
19
  // Cloud exports
20
20
  var entities_1 = require("./device/cloud/entities");
21
21
  Object.defineProperty(exports, "CloudDevice", { enumerable: true, get: function () { return entities_1.CloudDevice; } });
22
- Object.defineProperty(exports, "DeviceFactory", { enumerable: true, get: function () { return entities_1.DeviceFactory; } });
23
- Object.defineProperty(exports, "CloudConnection", { enumerable: true, get: function () { return entities_1.CloudConnection; } });
24
22
  Object.defineProperty(exports, "CloudDeviceService", { enumerable: true, get: function () { return entities_1.CloudDeviceService; } });
23
+ Object.defineProperty(exports, "DeviceFactory", { enumerable: true, get: function () { return entities_1.DeviceFactory; } });
25
24
  var services_1 = require("./device/local/services");
26
25
  Object.defineProperty(exports, "LocalDeviceService", { enumerable: true, get: function () { return services_1.LocalDeviceService; } });
27
26
  Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: function () { return services_1.LocalHubService; } });
28
27
  Object.defineProperty(exports, "LocalConnectionService", { enumerable: true, get: function () { return services_1.LocalConnectionService; } });
29
28
  Object.defineProperty(exports, "LocalPropertyService", { enumerable: true, get: function () { return services_1.LocalPropertyService; } });
29
+ Object.defineProperty(exports, "LocalScheduleService", { enumerable: true, get: function () { return services_1.LocalScheduleService; } });
30
30
  __exportStar(require("./device/cloud/interfaces"), exports);
31
- __exportStar(require("./device/cloud/types"), exports);
32
31
  // Local exports
33
32
  __exportStar(require("./device/local/interfaces"), exports);
34
33
  //initialize export
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
7
7
  "build": "tsc",
8
- "patch": "npm version patch && npm run build",
9
- "minor": "npm version minor && npm run build",
10
- "major": "npm version major && npm run build",
8
+ "patch": "npm version patch && npm run build && npm publish",
9
+ "minor": "npm version minor && npm run build && npm publish",
10
+ "major": "npm version major && npm run build && npm publish",
11
11
  "security:audit": "npm audit --audit-level=moderate",
12
12
  "security:fix": "npm audit fix",
13
13
  "security:check": "npm audit && npm outdated",
@@ -1,7 +1,7 @@
1
1
  import { IDevice } from "../../local/interfaces";
2
2
  import { ICloudDevice } from "../interfaces/ICloudDevice";
3
3
  import { ICloudDeviceService } from "../interfaces/ICloudDeviceService";
4
- import { IConnection } from "../types";
4
+ import { IConnection } from "../../local/interfaces/IConnection";
5
5
 
6
6
  export abstract class CloudDevice implements ICloudDevice {
7
7
  deviceId: string;
@@ -1,5 +1,5 @@
1
1
  import { ICloudDeviceService } from "../interfaces/ICloudDeviceService";
2
- import { IConnection } from "../types";
2
+ import { IConnection } from "../../local/interfaces/IConnection";
3
3
 
4
4
  export class CloudDeviceService implements ICloudDeviceService {
5
5
  async getConnection(deviceId: string): Promise<IConnection> {
@@ -1,4 +1,3 @@
1
1
  export * from "./CloudDevice";
2
2
  export * from "./DeviceFactory";
3
- export * from "./CloudConnection";
4
3
  export * from "./CloudDeviceService";
@@ -1,5 +1,5 @@
1
1
  // Interface for CloudDeviceService
2
- import { IConnection } from "../types";
2
+ import { IConnection } from "../../local/interfaces/IConnection";
3
3
 
4
4
  export interface ICloudDeviceService {
5
5
  getConnection(deviceId: string): Promise<IConnection>;
@@ -1,3 +1,3 @@
1
- export * from "./ICloudConnection";
2
1
  export * from "./ICloudDevice";
3
2
  export * from "./ICloudDeviceService";
3
+ export * from "./IDeviceFactory";
@@ -98,4 +98,20 @@ export class EventHandler {
98
98
  };
99
99
  await publishAudit(payload);
100
100
  }
101
+
102
+ async onDeviceMetaChange(deviceId: string, metaData: Record<string, any>) {
103
+ await eventDispatcher.publishEvent(
104
+ DeviceEvents.DEVICE_META_DATA_SET,
105
+ { deviceId, metaData },
106
+ this.source
107
+ );
108
+ const payload = {
109
+ eventType: DeviceEvents.DEVICE_META_DATA_SET,
110
+ properties: {
111
+ deviceId,
112
+ metaData,
113
+ },
114
+ };
115
+ await publishAudit(payload);
116
+ }
101
117
  }
@@ -0,0 +1,27 @@
1
+ export interface IConnection {
2
+ id?: string;
3
+ createdAt?: Date;
4
+ updatedAt?: Date;
5
+ isDeleted?: boolean;
6
+ connectionName: string;
7
+ connectionRefId: string;
8
+ propertyId: string;
9
+ connectionProvider: ConnectionProvider;
10
+ accessToken?: string;
11
+ refreshToken?: string;
12
+ clientId?: string;
13
+ clientSecret: string;
14
+ isActive?: boolean;
15
+ metaData?: any;
16
+ }
17
+
18
+ export enum ConnectionProvider {
19
+ Smartthings = "Smartthings",
20
+ SaltoKS = "SaltoKS",
21
+ TTLock = "TTLock",
22
+ Tuya = "Tuya",
23
+ Schlage = "Schlage",
24
+ YaleWifi = "YaleWifi",
25
+ Sensibo = "Sensibo",
26
+ Devicethread = "Devicethread",
27
+ }
@@ -0,0 +1,40 @@
1
+ export interface ISchedule {
2
+ id?: string;
3
+ name: string;
4
+ deviceId: string;
5
+ scheduleId: string | null; // generated from cloud api, optional
6
+ state: {
7
+ targetTemperature?: number;
8
+ temperatureUnit?: "C" | "F";
9
+ mode?: "cool" | "heat" | "fan" | "dry" | "auto";
10
+ swing?:
11
+ | "stopped"
12
+ | "rangeFull"
13
+ | "fixedTop"
14
+ | "fixedMiddleTop"
15
+ | "fixedMiddle"
16
+ | "fixedMiddleBottom"
17
+ | "fixedBottom";
18
+ fanLevel?: "auto" | "low" | "medium" | "high";
19
+ };
20
+ startTime: string; // ISO date string
21
+ endTime: string; // ISO date string
22
+ recurringDays: (
23
+ | "Monday"
24
+ | "Tuesday"
25
+ | "Wednesday"
26
+ | "Thursday"
27
+ | "Friday"
28
+ | "Saturday"
29
+ | "Sunday"
30
+ )[];
31
+ createTime?: string; // ISO date string, optional
32
+ nextTime?: string; // ISO date string, optional
33
+ nextTimeSecondsFromNow?: number;
34
+ targetTimeLocal: string; // ISO date string
35
+ timezone: string;
36
+ scheduleInheritedFrom: "zone" | "device";
37
+ zoneId: string;
38
+ userId: string;
39
+ status?: "SET" | "UNSET";
40
+ }
@@ -1,5 +1,5 @@
1
1
  import { getPostgresClient } from "../../../db";
2
- import { IConnection } from "../../cloud/types";
2
+ import { IConnection } from "../interfaces/IConnection";
3
3
  import { Service } from "typedi";
4
4
 
5
5
  @Service()
@@ -8,6 +8,26 @@ export class ConnectionRepository {
8
8
  constructor() {
9
9
  this.pool = getPostgresClient();
10
10
  }
11
+
12
+ async createConnection(data: Partial<IConnection>): Promise<IConnection> {
13
+ const result = await this.pool.query(
14
+ "INSERT INTO dt_connections (connectionName, connectionRefId, propertyId, connectionProvider, accessToken, refreshToken, clientId, clientSecret, isActive, metaData) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *",
15
+ [
16
+ data.connectionName,
17
+ data.connectionRefId,
18
+ data.propertyId,
19
+ data.connectionProvider,
20
+ data.accessToken,
21
+ data.refreshToken,
22
+ data.clientId,
23
+ data.clientSecret,
24
+ data.isActive,
25
+ data.metaData,
26
+ ]
27
+ );
28
+ return result.rows[0];
29
+ }
30
+
11
31
  async getConnectionById(connectionId: string): Promise<IConnection> {
12
32
  const result = await this.pool.query(
13
33
  "SELECT * FROM dt_connections WHERE id = $1",
@@ -19,7 +19,7 @@ export class HubRepository {
19
19
  this.postgres = getPostgresClient();
20
20
  }
21
21
 
22
- async addHub(body: any): Promise<IDevice> {
22
+ async addHub(body: Partial<IDevice>): Promise<IDevice> {
23
23
  return await axios.post(`${this.baseUrl}/devices/hubs`, body);
24
24
  }
25
25
 
@@ -0,0 +1,56 @@
1
+ import { Service } from "typedi";
2
+ import { getConfig } from "../../../config/config";
3
+ import axios from "axios";
4
+ import { ISchedule } from "../interfaces/ISchedule";
5
+
6
+ @Service()
7
+ export class ScheduleRepository {
8
+ private readonly baseUrl: string;
9
+ constructor() {
10
+ const { DEVICE_SERVICE } = getConfig();
11
+ if (!DEVICE_SERVICE) {
12
+ throw new Error(
13
+ "DEVICE_SERVICE is not configured. Call initialize() first with DEVICE_SERVICE."
14
+ );
15
+ }
16
+ this.baseUrl = DEVICE_SERVICE;
17
+ }
18
+ async getSchedule(scheduleId: string) {
19
+ try {
20
+ const response = await axios.get(
21
+ `${this.baseUrl}/devices/schedule?id=${scheduleId}`
22
+ );
23
+ return response.data;
24
+ } catch (error: any) {
25
+ console.log(error);
26
+ throw new Error(`Failed to get schedule: ${error.response.data.message}`);
27
+ }
28
+ }
29
+
30
+ async getScheduleByZone(zoneId: string) {
31
+ try {
32
+ const response = await axios.get(
33
+ `${this.baseUrl}/devices/schedules?zoneId=${zoneId}`
34
+ );
35
+ return response.data;
36
+ } catch (error: any) {
37
+ console.log(error);
38
+ throw new Error(`Failed to get schedule: ${error.response.data.message}`);
39
+ }
40
+ }
41
+
42
+ async setSchedule(scheduleId: string, schedule: ISchedule) {
43
+ try {
44
+ const response = await axios.put(
45
+ `${this.baseUrl}/devices/schedules/${scheduleId}`,
46
+ schedule
47
+ );
48
+ return response.data;
49
+ } catch (error: any) {
50
+ console.log(error);
51
+ throw new Error(
52
+ `Failed to update schedule: ${error.response.data.message}`
53
+ );
54
+ }
55
+ }
56
+ }
@@ -1,6 +1,6 @@
1
1
  import { Container } from "typedi";
2
- import { IConnection } from "../../cloud/types";
3
2
  import { ConnectionRepository } from "../repository/Connection.repository";
3
+ import { IConnection } from "../interfaces/IConnection";
4
4
 
5
5
  export class LocalConnectionService {
6
6
  private readonly connectionRepository: ConnectionRepository;
@@ -8,11 +8,32 @@ export class LocalConnectionService {
8
8
  this.connectionRepository = Container.get(ConnectionRepository);
9
9
  }
10
10
 
11
+ async createConnection(data: Partial<IConnection>): Promise<IConnection> {
12
+ if (
13
+ !data.connectionName ||
14
+ !data.connectionRefId ||
15
+ !data.propertyId ||
16
+ !data.connectionProvider
17
+ ) {
18
+ throw new Error("Missing required fields");
19
+ }
20
+ return await this.connectionRepository.createConnection(data);
21
+ }
22
+
11
23
  async getConnection(connectionId: string): Promise<IConnection> {
24
+ if (!connectionId) {
25
+ throw new Error("Connection ID is required");
26
+ }
12
27
  return await this.connectionRepository.getConnectionById(connectionId);
13
28
  }
14
29
 
15
- async updateConnection(connectionId: string, data: any) {
30
+ async updateConnection(
31
+ connectionId: string,
32
+ data: Partial<IConnection>
33
+ ): Promise<IConnection> {
34
+ if (!connectionId) {
35
+ throw new Error("Connection ID is required");
36
+ }
16
37
  return await this.connectionRepository.updateConnection(connectionId, data);
17
38
  }
18
39
  }
@@ -1,27 +1,16 @@
1
- import axios from "axios";
2
- import {
3
- getConfig,
4
- checkAwsEnv,
5
- ensureAuditInitialized,
6
- } from "../../../config/config";
1
+ import { checkAwsEnv, ensureAuditInitialized } from "../../../config/config";
7
2
  import { IDevice } from "../interfaces";
8
- import { eventDispatcher } from "dt-pub-sub";
9
- import { publishAudit } from "dt-audit-library";
10
3
  import { EventHandler } from "../events/EventHandler";
11
4
  import { isEqual } from "lodash";
12
5
  import { AlertService } from "./Alert.service";
13
- import { getPostgresClient } from "../../../db";
14
6
  import { DeviceRepository } from "../repository/Device.repository";
15
7
  import Container from "typedi";
16
8
 
17
9
  export class LocalDeviceService {
18
- private readonly source = "dt-common-device";
19
10
  private readonly eventHandler: EventHandler;
20
11
  private readonly alertService: AlertService;
21
- //private readonly redis;
22
12
  private readonly deviceRepository: DeviceRepository;
23
13
  constructor() {
24
- // this.redis = getRedisClient();
25
14
  checkAwsEnv();
26
15
  ensureAuditInitialized();
27
16
  this.eventHandler = new EventHandler();
@@ -37,6 +26,9 @@ export class LocalDeviceService {
37
26
  deviceId: string,
38
27
  withHubDetails: boolean = false
39
28
  ): Promise<IDevice> {
29
+ if (!deviceId) {
30
+ throw new Error("Device ID is required");
31
+ }
40
32
  return await this.deviceRepository.getDevice(deviceId, withHubDetails);
41
33
  }
42
34
 
@@ -44,6 +36,9 @@ export class LocalDeviceService {
44
36
  deviceIds: string[],
45
37
  withHubDetails: boolean = false
46
38
  ): Promise<IDevice[]> {
39
+ if (!deviceIds.length) {
40
+ throw new Error("At least one device ID is required");
41
+ }
47
42
  return await this.deviceRepository.getDevices(deviceIds, withHubDetails);
48
43
  }
49
44
 
@@ -51,6 +46,9 @@ export class LocalDeviceService {
51
46
  propertyId: string,
52
47
  withHubDetails: boolean = false
53
48
  ): Promise<IDevice[]> {
49
+ if (!propertyId) {
50
+ throw new Error("Property ID is required");
51
+ }
54
52
  return await this.deviceRepository.getPropertyDevices(
55
53
  propertyId,
56
54
  withHubDetails
@@ -58,18 +56,30 @@ export class LocalDeviceService {
58
56
  }
59
57
 
60
58
  async updateDevice(deviceId: string, body: any): Promise<any> {
59
+ if (!deviceId) {
60
+ throw new Error("Device ID is required");
61
+ }
61
62
  return await this.eventHandler.onDeviceUpdate(deviceId, body);
62
63
  }
63
64
 
64
65
  async deleteDevice(deviceId: string): Promise<any> {
66
+ if (!deviceId) {
67
+ throw new Error("Device ID is required");
68
+ }
65
69
  return await this.eventHandler.onDeviceDelete(deviceId);
66
70
  }
67
71
 
68
72
  async getState(deviceId: string) {
73
+ if (!deviceId) {
74
+ throw new Error("Device ID is required");
75
+ }
69
76
  return await this.deviceRepository.getState(deviceId);
70
77
  }
71
78
 
72
79
  async setState(deviceId: string, newState: any) {
80
+ if (!deviceId || !newState) {
81
+ throw new Error("Device ID and new state are required");
82
+ }
73
83
  // If old state and new state are different
74
84
  const oldState = (await this.getState(deviceId))?.data?.state || {};
75
85
  const changedKeys = Object.keys(newState).filter(
@@ -81,10 +91,16 @@ export class LocalDeviceService {
81
91
  }
82
92
 
83
93
  async getStatus(deviceId: string) {
94
+ if (!deviceId) {
95
+ throw new Error("Device ID is required");
96
+ }
84
97
  return await this.deviceRepository.getStatus(deviceId);
85
98
  }
86
99
 
87
100
  async setStatus(deviceId: string, newStatus: any) {
101
+ if (!deviceId || !newStatus) {
102
+ throw new Error("Device ID and new status are required");
103
+ }
88
104
  // If old status and new status are different
89
105
  const oldStatus = await this.getStatus(deviceId);
90
106
  const changedKeys = Object.keys(newStatus).filter(
@@ -110,9 +126,15 @@ export class LocalDeviceService {
110
126
  }
111
127
 
112
128
  async getBatteryLevel(deviceId: string) {
129
+ if (!deviceId) {
130
+ throw new Error("Device ID is required");
131
+ }
113
132
  return await this.deviceRepository.getBatteryLevel(deviceId);
114
133
  }
115
134
  async setBatteryLevel(deviceId: string, newBatteryLevel: any) {
135
+ if (!deviceId || !newBatteryLevel) {
136
+ throw new Error("Device ID and new battery level are required");
137
+ }
116
138
  // If old battery level and new battery level are different
117
139
  const oldBatteryLevel = await this.getBatteryLevel(deviceId);
118
140
  const changedKeys = Object.keys(newBatteryLevel).filter(
@@ -136,29 +158,29 @@ export class LocalDeviceService {
136
158
  }
137
159
  }
138
160
  async getMetaData(deviceId: string) {
161
+ if (!deviceId) {
162
+ throw new Error("Device ID is required");
163
+ }
139
164
  return await this.deviceRepository.getMetaData(deviceId);
140
165
  }
141
166
  async setMetaData(deviceId: string, metaData: Record<string, any>) {
142
- await eventDispatcher.publishEvent(
143
- "device.metaData.set",
144
- { deviceId, metaData },
145
- this.source
146
- );
147
- const payload = {
148
- eventType: "device.metaData.set",
149
- properties: {
150
- deviceId,
151
- metaData,
152
- },
153
- };
154
- await publishAudit(payload);
167
+ if (!deviceId || !metaData) {
168
+ throw new Error("Device ID and meta data are required");
169
+ }
170
+ return await this.eventHandler.onDeviceMetaChange(deviceId, metaData);
155
171
  }
156
172
 
157
173
  async getDevicesByZone(zoneId: string) {
174
+ if (!zoneId) {
175
+ throw new Error("Zone ID is required");
176
+ }
158
177
  return await this.deviceRepository.getDevicesByZone(zoneId);
159
178
  }
160
179
 
161
180
  async getDevicesByAccessGroup(accessGroupId: string) {
181
+ if (!accessGroupId) {
182
+ throw new Error("Access Group ID is required");
183
+ }
162
184
  return await this.deviceRepository.getDevicesByAccessGroup(accessGroupId);
163
185
  }
164
186
  }
@@ -8,31 +8,50 @@ export class LocalHubService {
8
8
  this.hubRepository = Container.get(HubRepository);
9
9
  }
10
10
 
11
- async addHub(body: IDevice): Promise<IDevice> {
11
+ async addHub(body: Partial<IDevice>): Promise<IDevice> {
12
12
  return await this.hubRepository.addHub(body);
13
13
  }
14
14
 
15
15
  async getHubs(hubIds: string[]): Promise<IDevice[]> {
16
+ if (!hubIds.length) {
17
+ throw new Error("At least one hub ID is required");
18
+ }
16
19
  return await this.hubRepository.getHubs(hubIds);
17
20
  }
18
21
 
19
22
  async getHub(hubId: string): Promise<IDevice> {
23
+ if (!hubId) {
24
+ throw new Error("Hub ID is required");
25
+ }
20
26
  return await this.hubRepository.getHub(hubId);
21
27
  }
22
28
 
23
29
  async updateHub(hubId: string, body: Partial<IDevice>): Promise<IDevice> {
30
+ if (!hubId) {
31
+ throw new Error("Hub ID is required");
32
+ }
24
33
  return await this.hubRepository.updateHub(hubId, body);
25
34
  }
26
35
 
27
36
  async getStatus(hubId: string): Promise<any> {
37
+ if (!hubId) {
38
+ throw new Error("Hub ID is required");
39
+ }
28
40
  return await this.hubRepository.getStatus(hubId);
29
41
  }
30
42
 
31
43
  async deleteHub(hubId: string): Promise<any> {
44
+ if (!hubId) {
45
+ throw new Error("Hub ID is required");
46
+ }
32
47
  return await this.hubRepository.deleteHub(hubId);
33
48
  }
34
49
 
50
+
35
51
  async deleteAllHubs(hubIds: string[]): Promise<any> {
52
+ if (!hubIds.length) {
53
+ throw new Error("At least one hub ID is required");
54
+ }
36
55
  return await this.hubRepository.deleteAllHubs(hubIds);
37
56
  }
38
57
  }
@@ -7,14 +7,23 @@ export class LocalPropertyService {
7
7
  }
8
8
 
9
9
  async getPropertyPreferences(propertyId: string) {
10
+ if (!propertyId) {
11
+ throw new Error("Property ID is required");
12
+ }
10
13
  return await this.propertyRepository.getPropertyPreferences(propertyId);
11
14
  }
12
15
 
13
16
  async getProperty(propertyId: string) {
17
+ if (!propertyId) {
18
+ throw new Error("Property ID is required");
19
+ }
14
20
  return await this.propertyRepository.getProperty(propertyId);
15
21
  }
16
22
 
17
23
  async getPropertyTimeZone(propertyId: string) {
24
+ if (!propertyId) {
25
+ throw new Error("Property ID is required");
26
+ }
18
27
  const property = await this.propertyRepository.getProperty(propertyId);
19
28
  if (!property) {
20
29
  throw new Error("Property not found");
@@ -0,0 +1,22 @@
1
+ import Container from "typedi";
2
+ import { ScheduleRepository } from "../repository/Schedule.repository";
3
+ import { ISchedule } from "../interfaces/ISchedule";
4
+
5
+ export class LocalScheduleService {
6
+ private readonly scheduleRepository: ScheduleRepository;
7
+ constructor() {
8
+ this.scheduleRepository = Container.get(ScheduleRepository);
9
+ }
10
+
11
+ async getSchedule(scheduleId: string) {
12
+ return await this.scheduleRepository.getSchedule(scheduleId);
13
+ }
14
+
15
+ async setSchedule(scheduleId: string, schedule: ISchedule) {
16
+ return await this.scheduleRepository.setSchedule(scheduleId, schedule);
17
+ }
18
+
19
+ async getScheduleByZone(zoneId: string) {
20
+ return await this.scheduleRepository.getScheduleByZone(zoneId);
21
+ }
22
+ }
@@ -2,3 +2,4 @@ export { LocalDeviceService } from "./Device.service";
2
2
  export { LocalHubService } from "./Hub.service";
3
3
  export { LocalConnectionService } from "./Connection.service";
4
4
  export { LocalPropertyService } from "./Property.service";
5
+ export { LocalScheduleService } from "./Schedule.service";
package/src/index.ts CHANGED
@@ -3,19 +3,18 @@
3
3
  // Cloud exports
4
4
  export {
5
5
  CloudDevice,
6
- DeviceFactory,
7
- CloudConnection,
8
6
  CloudDeviceService,
7
+ DeviceFactory,
9
8
  } from "./device/cloud/entities";
10
9
  export {
11
10
  LocalDeviceService,
12
11
  LocalHubService,
13
12
  LocalConnectionService,
14
13
  LocalPropertyService,
14
+ LocalScheduleService,
15
15
  } from "./device/local/services";
16
16
 
17
17
  export * from "./device/cloud/interfaces";
18
- export * from "./device/cloud/types";
19
18
 
20
19
  // Local exports
21
20
  export * from "./device/local/interfaces";
@@ -1,13 +0,0 @@
1
- // Device Cloud Service - Class Implementation
2
- import { ICloudConnection } from "../interfaces";
3
- import { IDeviceAccountResponse, IConnection } from "../types";
4
-
5
- export abstract class CloudConnection implements ICloudConnection {
6
- abstract createConnection(
7
- data: IConnection,
8
- userId: string
9
- ): Promise<IConnection>;
10
- abstract getDeviceAccount(
11
- connection: IConnection
12
- ): Promise<IDeviceAccountResponse>;
13
- }
@@ -1,6 +0,0 @@
1
- import { IConnection, IDeviceAccountResponse } from "../types";
2
-
3
- export interface ICloudConnection {
4
- createConnection(data: IConnection, userId: string): Promise<IConnection>;
5
- getDeviceAccount(connection: IConnection): Promise<IDeviceAccountResponse>;
6
- }