homebridge-fire-detector 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +9 -0
- package/config.schema.json +27 -0
- package/index.js +47 -0
- package/package.json +14 -0
package/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"pluginAlias": "FireDetector",
|
3
|
+
"pluginType": "accessory",
|
4
|
+
"schema": {
|
5
|
+
"type": "object",
|
6
|
+
"properties": {
|
7
|
+
"name": {
|
8
|
+
"type": "string",
|
9
|
+
"title": "Accessory Name",
|
10
|
+
"default": "Fire Detector"
|
11
|
+
},
|
12
|
+
"sensors": {
|
13
|
+
"type": "array",
|
14
|
+
"title": "Fire Sensors",
|
15
|
+
"items": {
|
16
|
+
"type": "object",
|
17
|
+
"properties": {
|
18
|
+
"name": {
|
19
|
+
"type": "string",
|
20
|
+
"title": "Sensor Name"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
package/index.js
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
const { Service, Characteristic } = require('homebridge');
|
2
|
+
|
3
|
+
module.exports = (api) => {
|
4
|
+
api.registerAccessory('FireDetector', FireDetector);
|
5
|
+
};
|
6
|
+
|
7
|
+
class FireDetector {
|
8
|
+
constructor(log, config, api) {
|
9
|
+
this.log = log;
|
10
|
+
this.api = api;
|
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
|
13
|
+
|
14
|
+
this.services = [];
|
15
|
+
|
16
|
+
// Tạo mỗi công tắc và cảm biến tương ứng
|
17
|
+
this.sensors.forEach((sensor, index) => {
|
18
|
+
const switchService = new Service.Switch(`Switch - ${sensor.name || `Sensor ${index + 1}`}`);
|
19
|
+
const sensorService = new Service.MotionSensor(sensor.name || `Sensor ${index + 1}`);
|
20
|
+
|
21
|
+
let isFireDetected = false;
|
22
|
+
|
23
|
+
// Xử lý khi bật/tắt công tắc
|
24
|
+
switchService
|
25
|
+
.getCharacteristic(Characteristic.On)
|
26
|
+
.onGet(() => isFireDetected)
|
27
|
+
.onSet((value) => {
|
28
|
+
isFireDetected = value;
|
29
|
+
this.log(`Switch for ${sensor.name || `Sensor ${index + 1}`} set to: ${value}`);
|
30
|
+
sensorService
|
31
|
+
.getCharacteristic(Characteristic.MotionDetected)
|
32
|
+
.updateValue(isFireDetected);
|
33
|
+
});
|
34
|
+
|
35
|
+
// Lưu dịch vụ vào danh sách
|
36
|
+
this.services.push(switchService, sensorService);
|
37
|
+
});
|
38
|
+
|
39
|
+
if (this.services.length === 0) {
|
40
|
+
this.log('No sensors configured. Please add sensors in the configuration.');
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
getServices() {
|
45
|
+
return this.services;
|
46
|
+
}
|
47
|
+
}
|
package/package.json
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"name": "homebridge-fire-detector",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "A Homebridge plugin to create virtual fire detection sensors.",
|
5
|
+
"main": "index.js",
|
6
|
+
"author": "DINH THAI AIGLOBAL",
|
7
|
+
"license": "MIT",
|
8
|
+
"keywords": ["homebridge-plugin", "fire-detector", "virtual-switch"],
|
9
|
+
"dependencies": {},
|
10
|
+
"engines": {
|
11
|
+
"homebridge": ">=1.3.0",
|
12
|
+
"node": ">=14.18.0"
|
13
|
+
}
|
14
|
+
}
|