v2c-any 0.1.2 → 0.1.3

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.
package/dist/index.js CHANGED
@@ -34,16 +34,20 @@ async function main() {
34
34
  logger.info('Shutting down...');
35
35
  if (service)
36
36
  await service.stop();
37
+ logger.info('Shutdown complete');
38
+ }
39
+ catch (err) {
40
+ logger.error(err, 'Error during shutdown');
37
41
  }
38
42
  finally {
39
43
  process.exit(0);
40
44
  }
41
45
  };
42
46
  logger.info('Application started successfully');
43
- process.on('SIGINT', () => {
47
+ process.once('SIGINT', () => {
44
48
  shutdown().catch((err) => logger.error(err, 'Error during shutdown'));
45
49
  });
46
- process.on('SIGTERM', () => {
50
+ process.once('SIGTERM', () => {
47
51
  shutdown().catch((err) => logger.error(err, 'Error during shutdown'));
48
52
  });
49
53
  }
@@ -26,6 +26,7 @@ export class MqttBridgeService {
26
26
  * @returns A promise that resolves when the subscription is active
27
27
  */
28
28
  async start() {
29
+ logger.info('Starting MQTT bridge service');
29
30
  this.client = await createMqttClient(this.properties.url);
30
31
  this.client.on('message', (topic, message) => {
31
32
  if (topic === this.properties.topic) {
@@ -40,16 +41,20 @@ export class MqttBridgeService {
40
41
  });
41
42
  }
42
43
  });
44
+ logger.info({ topic: this.properties.topic }, 'Subscribing to MQTT topic');
43
45
  await this.client.subscribeAsync(this.properties.topic);
46
+ logger.info('MQTT bridge service started');
44
47
  }
45
48
  /**
46
49
  * Stops the bridge: disconnects the MQTT client and clears resources.
47
50
  * @returns A promise that resolves when the client has disconnected
48
51
  */
49
52
  async stop() {
53
+ logger.info('Stopping MQTT bridge service');
50
54
  if (this.client) {
51
55
  await this.client.endAsync();
52
56
  this.client = null;
53
57
  }
58
+ logger.info('MQTT bridge service stopped');
54
59
  }
55
60
  }
@@ -60,6 +60,7 @@ export class MqttService {
60
60
  throw new Error('MQTT client already started');
61
61
  }
62
62
  this.client = await createMqttClient(this.properties.url);
63
+ logger.info('MQTT client started');
63
64
  }
64
65
  /**
65
66
  * Stops the MQTT client connection.
@@ -67,6 +68,7 @@ export class MqttService {
67
68
  * @throws {Error} If the client is not started
68
69
  */
69
70
  async stop() {
71
+ logger.info('Stopping MQTT mode');
70
72
  const client = this.client;
71
73
  this.client = null;
72
74
  if (!client) {
@@ -10,12 +10,6 @@ import { logger } from './logger.js';
10
10
  */
11
11
  export async function createMqttClient(url) {
12
12
  const client = await mqtt.connectAsync(url);
13
- client.on('connect', () => {
14
- logger.info({ url }, 'Connected to MQTT broker');
15
- });
16
- client.on('error', (err) => {
17
- logger.error(err, 'MQTT client error');
18
- });
19
13
  client.on('reconnect', () => logger.info('Reconnecting...'));
20
14
  return client;
21
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "v2c-any",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "V2C device adapter and MQTT publisher (Shelly EM1 compatible)",
6
6
  "main": "dist/index.js",