@phystack/device-phyos 6.15.1 → 6.15.2

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 (2) hide show
  1. package/dist/index.js +42 -40
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -71,7 +71,7 @@ function getSystemdJournalGid() {
71
71
  try {
72
72
  const groupFile = fs_1.default.readFileSync('/etc/group', 'utf8');
73
73
  const groups = groupFile.split('\n');
74
- const journalGroup = groups.find(line => line.startsWith('systemd-journal:'));
74
+ const journalGroup = groups.find((line) => line.startsWith('systemd-journal:'));
75
75
  if (!journalGroup) {
76
76
  throw new Error('systemd-journal group not found');
77
77
  }
@@ -187,12 +187,12 @@ class DevicePhyos {
187
187
  await this.initializeTimeSync();
188
188
  this.logger.info(`Starting device phyos service 🟢-⚪-⚪-⚪-⚪`, {
189
189
  GRID_ENV: this.GRID_ENV,
190
- PHYOS_VERSION: this.PHYOS_VERSION
190
+ PHYOS_VERSION: this.PHYOS_VERSION,
191
191
  });
192
192
  }
193
193
  async initializeEnvironment() {
194
194
  try {
195
- this.GRID_ENV = await fs_1.default.promises.readFile(phyosEnvPath, 'utf8').then(data => data.trim() || 'LOCAL');
195
+ this.GRID_ENV = await fs_1.default.promises.readFile(phyosEnvPath, 'utf8').then((data) => data.trim() || 'LOCAL');
196
196
  this.logger.info('initializeEnvironment(): Setting grid environment', {
197
197
  GRID_ENV: this.GRID_ENV,
198
198
  });
@@ -202,9 +202,9 @@ class DevicePhyos {
202
202
  this.GRID_ENV = 'PROD';
203
203
  }
204
204
  try {
205
- this.PHYOS_VERSION = await fs_1.default.promises.readFile(phyosVersionPath, 'utf8').then(data => data.trim());
205
+ this.PHYOS_VERSION = await fs_1.default.promises.readFile(phyosVersionPath, 'utf8').then((data) => data.trim());
206
206
  this.logger.info('initializeEnvironment(): Setting PhyOS version', {
207
- PHYOS_VERSION: this.PHYOS_VERSION
207
+ PHYOS_VERSION: this.PHYOS_VERSION,
208
208
  });
209
209
  }
210
210
  catch (error) {
@@ -256,10 +256,14 @@ class DevicePhyos {
256
256
  this.logger.info('connectPhyHub(): Device authenticated, resubscribing twins...');
257
257
  await edge_hub_1.EdgeHubServer.getInstance().resubscribeAllTwins();
258
258
  try {
259
- const cachedTwinsInfo = await this.twinManager.getCachedTwins();
260
- if (cachedTwinsInfo && typeof cachedTwinsInfo === 'object' && 'Device' in cachedTwinsInfo && Array.isArray(cachedTwinsInfo.Device) && cachedTwinsInfo.Device.length > 0) {
259
+ const cachedTwinsInfo = (await this.twinManager.getCachedTwins());
260
+ if (cachedTwinsInfo &&
261
+ typeof cachedTwinsInfo === 'object' &&
262
+ 'Device' in cachedTwinsInfo &&
263
+ Array.isArray(cachedTwinsInfo.Device) &&
264
+ cachedTwinsInfo.Device.length > 0) {
261
265
  const deviceTwinId = cachedTwinsInfo.Device[0];
262
- const deviceTwin = await this.twinManager.getCachedTwins(deviceTwinId);
266
+ const deviceTwin = (await this.twinManager.getCachedTwins(deviceTwinId));
263
267
  if (deviceTwin && deviceTwin.type === 'Device' && 'properties' in deviceTwin && deviceTwin.properties) {
264
268
  const deviceProps = deviceTwin.properties;
265
269
  const jobs = deviceProps.reported?.jobs || [];
@@ -275,6 +279,32 @@ class DevicePhyos {
275
279
  });
276
280
  await hubDevice.connect();
277
281
  this.logger.info('connectPhyHub(): Connected to PhyHub');
282
+ hubDevice.setTwinUpdateHandler(async (twin) => {
283
+ this.logger.info('connectPhyHub() on setTwinUpdateHandler(): Twin update received, updating instance...');
284
+ await this.twinManager.cacheHubTwin(twin);
285
+ if (twin.type === 'Device' && twin.properties?.desired?.timezone) {
286
+ try {
287
+ const region = JSON.parse(fs_1.default.readFileSync(regionFilePath, 'utf8'));
288
+ const proxyConfig = {
289
+ region,
290
+ port: 443,
291
+ username: twin.deviceId,
292
+ password: 'device',
293
+ timezone: twin.properties.desired.timezone,
294
+ };
295
+ this.logger.info('connectPhyHub(): Updating environment with:', proxyConfig);
296
+ await (0, environment_1.setTZinEnvFile)(twin.properties.desired.timezone);
297
+ }
298
+ catch (error) {
299
+ this.logger.error('connectPhyHub(): Failed to update environment with new timezone:', error);
300
+ }
301
+ }
302
+ await (0, instances_1.updateInstances)(this.twinManager, [(await this.twinManager.getCachedTwins(twin.id))]);
303
+ });
304
+ hubDevice.setTwinRemoveHandler(async (twin) => {
305
+ this.logger.info('connectPhyHub() on setTwinRemoveHandler(): Twin remove event received, removing instance twin...', twin);
306
+ await (0, instances_1.removeInstances)(this.twinManager, [twin]);
307
+ });
278
308
  hubDevice.connectDevice(async (response) => {
279
309
  const { twins } = response;
280
310
  console.log('connectPhyHub(): response', response);
@@ -307,7 +337,7 @@ class DevicePhyos {
307
337
  port: 443,
308
338
  username: deviceId,
309
339
  password: 'device',
310
- timezone: deviceTwin?.properties?.desired?.timezone || 'Etc/UTC'
340
+ timezone: deviceTwin?.properties?.desired?.timezone || 'Etc/UTC',
311
341
  };
312
342
  this.logger.info('connectPhyHub(): Environment contains unprovisioned username, configuring with device credentials:', proxyConfig);
313
343
  await (0, environment_1.setEnvironmentConfiguration)(proxyConfig);
@@ -328,44 +358,16 @@ class DevicePhyos {
328
358
  this.logger.info('connectPhyHub(): Caching twins from server response...');
329
359
  await Promise.all(twins.map((twin) => this.twinManager.cacheHubTwin(twin)));
330
360
  this.logger.info(`connectPhyHub(): Cached ${twins.length} twins from hub`);
331
- const twinsByType = await this.twinManager.getCachedTwins();
361
+ const twinsByType = (await this.twinManager.getCachedTwins());
332
362
  const allTwinIds = Object.values(twinsByType).flat();
333
363
  this.logger.info(`connectPhyHub(): Found ${allTwinIds.length} total twins after caching`);
334
- const allTwins = await Promise.all(allTwinIds.map(id => this.twinManager.getCachedTwins(id)));
364
+ const allTwins = await Promise.all(allTwinIds.map((id) => this.twinManager.getCachedTwins(id)));
335
365
  console.log(`connectPhyHub(): allTwins ${allTwins.length}`);
336
366
  await (0, instances_1.initInstances)(this.twinManager, allTwins);
337
367
  await (0, methods_1.initMethods)(hubDevice);
338
368
  }
339
369
  });
340
370
  await this.initializeCachedInstances(this.twinManager);
341
- hubDevice.setTwinUpdateHandler(async (twin) => {
342
- this.logger.info('connectPhyHub() on setTwinUpdateHandler(): Twin update received, updating instance...');
343
- await this.twinManager.cacheHubTwin(twin);
344
- if (twin.type === 'Device' && twin.properties?.desired?.timezone) {
345
- try {
346
- const region = JSON.parse(fs_1.default.readFileSync(regionFilePath, 'utf8'));
347
- const proxyConfig = {
348
- region,
349
- port: 443,
350
- username: twin.deviceId,
351
- password: 'device',
352
- timezone: twin.properties.desired.timezone
353
- };
354
- this.logger.info('connectPhyHub(): Updating environment with:', proxyConfig);
355
- await (0, environment_1.setTZinEnvFile)(twin.properties.desired.timezone);
356
- }
357
- catch (error) {
358
- this.logger.error('connectPhyHub(): Failed to update environment with new timezone:', error);
359
- }
360
- }
361
- await (0, instances_1.updateInstances)(this.twinManager, [
362
- (await this.twinManager.getCachedTwins(twin.id)),
363
- ]);
364
- });
365
- hubDevice.setTwinRemoveHandler(async (twin) => {
366
- this.logger.info('connectPhyHub() on setTwinRemoveHandler(): Twin remove event received, removing instance twin...', twin);
367
- await (0, instances_1.removeInstances)(this.twinManager, [twin]);
368
- });
369
371
  hubDevice.on('setCACertificate', async (payload, callback) => {
370
372
  try {
371
373
  const config = payload.data;
@@ -444,7 +446,7 @@ class DevicePhyos {
444
446
  this.scheduler = new scheduler_service_1.Scheduler();
445
447
  this.logger.info('start(): Created new scheduler instance');
446
448
  }
447
- (0, edge_hub_1.startEdgeHub)().catch(error => {
449
+ (0, edge_hub_1.startEdgeHub)().catch((error) => {
448
450
  this.logger.error('start(): Error starting edgeHub messaging', error);
449
451
  });
450
452
  this.phyHubInterval = setInterval(() => this.getPhyHub(), 30000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phystack/device-phyos",
3
- "version": "6.15.1",
3
+ "version": "6.15.2",
4
4
  "description": "PhyOS device agent",
5
5
  "main": "dist/index.js",
6
6
  "license": "UNLICENSED",
@@ -25,9 +25,9 @@
25
25
  "format": "prettier --write \"src/**/*.{ts,js,json,md}\""
26
26
  },
27
27
  "optionalDependencies": {
28
- "@phystack/phydevice-darwin-arm64": "6.15.1",
29
- "@phystack/phydevice-darwin-x64": "6.15.1",
30
- "@phystack/phydevice-linux-arm64": "6.15.1",
31
- "@phystack/phydevice-linux-x64": "6.15.1"
28
+ "@phystack/phydevice-darwin-arm64": "6.15.2",
29
+ "@phystack/phydevice-darwin-x64": "6.15.2",
30
+ "@phystack/phydevice-linux-arm64": "6.15.2",
31
+ "@phystack/phydevice-linux-x64": "6.15.2"
32
32
  }
33
33
  }