homebridge-fire-detector 1.0.1 → 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 +8 -4
  3. package/package.json +1 -1
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
@@ -13,6 +13,12 @@ class FireDetector {
13
13
 
14
14
  this.services = [];
15
15
 
16
+ // Nếu không có 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
+
16
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}`}`);
@@ -20,7 +26,7 @@ class FireDetector {
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)
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-fire-detector",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A Homebridge plugin to create virtual fire detection sensors and switches.",
5
5
  "main": "index.js",
6
6
  "author": "DINH THAI AIGLOBAL",