homebridge-fire-detector 1.0.0 → 1.0.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 (3) hide show
  1. package/README.md +19 -0
  2. package/index.js +11 -7
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -7,3 +7,22 @@ This plugin creates virtual fire detection sensors and switches in Homebridge.
7
7
  1. Install the plugin:
8
8
  ```bash
9
9
  npm install -g homebridge-fire-detector
10
+
11
+ 2. Thêm cấu hình mẫu
12
+ Đảm bảo cấu hình trong config.json đầy đủ và chính xác. Cấu hình mẫu:
13
+
14
+ json
15
+ Sao chép mã
16
+ {
17
+ "accessories": [
18
+ {
19
+ "accessory": "FireDetector",
20
+ "name": "Fire Detector",
21
+ "sensors": [
22
+ { "name": "Living Room" },
23
+ { "name": "Kitchen" }
24
+ ]
25
+ }
26
+ ]
27
+ }
28
+ Nếu không có cấu hình sensors, plugin sẽ tạo 1 cảm biến mặc định.
package/index.js CHANGED
@@ -9,24 +9,30 @@ class FireDetector {
9
9
  this.log = log;
10
10
  this.api = api;
11
11
  this.name = config.name || 'Fire Detector';
12
- this.sensors = config.sensors || []; // Danh sách các cảm biến từ cấu hình
12
+ this.sensors = config.sensors || []; // Danh sách cảm biến từ cấu hình
13
13
 
14
14
  this.services = [];
15
15
 
16
- // Tạo mỗi công tắc cảm biến tương ứng
16
+ // Nếu không cảm biến nào được cấu hình, tạo 1 cảm biến mặc định
17
+ if (this.sensors.length === 0) {
18
+ this.log('No sensors configured. Adding a default sensor.');
19
+ this.sensors = [{ name: 'Default Sensor' }];
20
+ }
21
+
22
+ // Tạo công tắc và cảm biến cho từng cảm biến cấu hình
17
23
  this.sensors.forEach((sensor, index) => {
18
24
  const switchService = new Service.Switch(`Switch - ${sensor.name || `Sensor ${index + 1}`}`);
19
25
  const sensorService = new Service.MotionSensor(sensor.name || `Sensor ${index + 1}`);
20
26
 
21
27
  let isFireDetected = false;
22
28
 
23
- // Xử lý khi bật/tắt công tắc
29
+ // Xử lý bật/tắt công tắc
24
30
  switchService
25
31
  .getCharacteristic(Characteristic.On)
26
32
  .onGet(() => isFireDetected)
27
33
  .onSet((value) => {
28
34
  isFireDetected = value;
29
- this.log(`Switch for ${sensor.name || `Sensor ${index + 1}`} set to: ${value}`);
35
+ this.log(`${sensor.name || `Sensor ${index + 1}`} set to: ${value}`);
30
36
  sensorService
31
37
  .getCharacteristic(Characteristic.MotionDetected)
32
38
  .updateValue(isFireDetected);
@@ -36,9 +42,7 @@ class FireDetector {
36
42
  this.services.push(switchService, sensorService);
37
43
  });
38
44
 
39
- if (this.services.length === 0) {
40
- this.log('No sensors configured. Please add sensors in the configuration.');
41
- }
45
+ this.log(`Initialized ${this.sensors.length} fire sensors.`);
42
46
  }
43
47
 
44
48
  getServices() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-fire-detector",
3
- "version": "1.0.0",
4
- "description": "A Homebridge plugin to create virtual fire detection sensors.",
3
+ "version": "1.0.2",
4
+ "description": "A Homebridge plugin to create virtual fire detection sensors and switches.",
5
5
  "main": "index.js",
6
6
  "author": "DINH THAI AIGLOBAL",
7
7
  "license": "MIT",