homebridge-multiple-switch 1.1.1 → 1.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/config.schema.json +77 -6
- package/index.js +56 -50
- package/package.json +2 -2
package/config.schema.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"pluginAlias": "MultipleSwitchAccessory",
|
|
3
3
|
"pluginType": "accessory",
|
|
4
|
+
"singular": false,
|
|
4
5
|
"headerDisplay": "Multiple Switch Accessory",
|
|
5
6
|
"schema": {
|
|
6
7
|
"type": "object",
|
|
@@ -15,9 +16,24 @@
|
|
|
15
16
|
"type": "string",
|
|
16
17
|
"default": "independent",
|
|
17
18
|
"oneOf": [
|
|
18
|
-
{
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
{
|
|
20
|
+
"title": "Independent",
|
|
21
|
+
"enum": [
|
|
22
|
+
"independent"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"title": "Master",
|
|
27
|
+
"enum": [
|
|
28
|
+
"master"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"title": "Single",
|
|
33
|
+
"enum": [
|
|
34
|
+
"single"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
21
37
|
]
|
|
22
38
|
},
|
|
23
39
|
"switches": {
|
|
@@ -29,13 +45,68 @@
|
|
|
29
45
|
"name": {
|
|
30
46
|
"title": "Switch Name",
|
|
31
47
|
"type": "string"
|
|
48
|
+
},
|
|
49
|
+
"type": {
|
|
50
|
+
"title": "Switch Type",
|
|
51
|
+
"type": "string",
|
|
52
|
+
"default": "outlet",
|
|
53
|
+
"oneOf": [
|
|
54
|
+
{
|
|
55
|
+
"title": "Switch",
|
|
56
|
+
"enum": [
|
|
57
|
+
"switch"
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"title": "Outlet",
|
|
62
|
+
"enum": [
|
|
63
|
+
"outlet"
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"title": "Lightbulb",
|
|
68
|
+
"enum": [
|
|
69
|
+
"lightbulb"
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"title": "Fan",
|
|
74
|
+
"enum": [
|
|
75
|
+
"fan"
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
"defaultState": {
|
|
81
|
+
"title": "Default State",
|
|
82
|
+
"type": "boolean",
|
|
83
|
+
"default": false
|
|
84
|
+
},
|
|
85
|
+
"delayOff": {
|
|
86
|
+
"title": "Auto Turn Off (ms)",
|
|
87
|
+
"type": "number",
|
|
88
|
+
"default": 0,
|
|
89
|
+
"minimum": 0
|
|
32
90
|
}
|
|
33
91
|
},
|
|
34
|
-
"required": [
|
|
92
|
+
"required": [
|
|
93
|
+
"name",
|
|
94
|
+
"type"
|
|
95
|
+
]
|
|
35
96
|
},
|
|
36
|
-
"default": [
|
|
97
|
+
"default": [
|
|
98
|
+
{
|
|
99
|
+
"name": "Switch 1",
|
|
100
|
+
"type": "outlet",
|
|
101
|
+
"defaultState": false,
|
|
102
|
+
"delayOff": 0
|
|
103
|
+
}
|
|
104
|
+
]
|
|
37
105
|
}
|
|
38
106
|
},
|
|
39
|
-
"required": [
|
|
107
|
+
"required": [
|
|
108
|
+
"name",
|
|
109
|
+
"switches"
|
|
110
|
+
]
|
|
40
111
|
}
|
|
41
112
|
}
|
package/index.js
CHANGED
|
@@ -1,72 +1,78 @@
|
|
|
1
|
-
let Accessory, Service, Characteristic
|
|
1
|
+
let Accessory, Service, Characteristic;
|
|
2
2
|
|
|
3
|
-
module.exports = (
|
|
4
|
-
Accessory =
|
|
5
|
-
Service =
|
|
6
|
-
Characteristic =
|
|
7
|
-
UUIDGen = api.hap.uuid;
|
|
3
|
+
module.exports = (homebridge) => {
|
|
4
|
+
Accessory = homebridge.platformAccessory || homebridge.hap.Accessory;
|
|
5
|
+
Service = homebridge.hap.Service;
|
|
6
|
+
Characteristic = homebridge.hap.Characteristic;
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
homebridge.registerAccessory(
|
|
9
|
+
'homebridge-multiple-switch',
|
|
10
|
+
'MultipleSwitchAccessory',
|
|
11
|
+
MultipleSwitchAccessory
|
|
12
|
+
);
|
|
10
13
|
};
|
|
11
14
|
|
|
12
15
|
class MultipleSwitchAccessory {
|
|
13
|
-
constructor(log, config
|
|
16
|
+
constructor(log, config) {
|
|
14
17
|
this.log = log;
|
|
15
18
|
this.config = config;
|
|
16
|
-
this.name = config.name;
|
|
19
|
+
this.name = config.name || 'Multiple Switch';
|
|
17
20
|
this.switches = config.switches || [];
|
|
18
|
-
this.mode = config.switchBehavior || "independent";
|
|
19
21
|
this.services = [];
|
|
20
22
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
const infoService = new Service.AccessoryInformation()
|
|
24
|
+
.setCharacteristic(Characteristic.Manufacturer, 'Custom')
|
|
25
|
+
.setCharacteristic(Characteristic.Model, 'MultipleSwitch')
|
|
26
|
+
.setCharacteristic(Characteristic.SerialNumber, 'v1.0.0');
|
|
24
27
|
|
|
25
|
-
this.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
this.services.push(infoService);
|
|
29
|
+
|
|
30
|
+
const serviceTypes = {
|
|
31
|
+
switch: Service.Switch,
|
|
32
|
+
outlet: Service.Outlet,
|
|
33
|
+
lightbulb: Service.Lightbulb,
|
|
34
|
+
fan: Service.Fan
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
this.switches.forEach((conf, index) => {
|
|
38
|
+
const switchName = conf.name || `Switch ${index + 1}`;
|
|
39
|
+
const type = (conf.type || 'outlet').toLowerCase();
|
|
40
|
+
const ServiceClass = serviceTypes[type];
|
|
41
|
+
|
|
42
|
+
if (!ServiceClass) {
|
|
43
|
+
this.log.warn(`"${switchName}" üçün tanınmayan növ: "${type}". Default olaraq Outlet istifadə olunur.`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
34
46
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
47
|
+
conf.state = conf.defaultState === true;
|
|
48
|
+
|
|
49
|
+
const service = new ServiceClass(switchName, `subtype-${index}`);
|
|
50
|
+
|
|
51
|
+
service
|
|
38
52
|
.getCharacteristic(Characteristic.On)
|
|
39
|
-
.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
.on('get', (callback) => {
|
|
54
|
+
callback(null, conf.state);
|
|
55
|
+
})
|
|
56
|
+
.on('set', (value, callback) => {
|
|
57
|
+
conf.state = value;
|
|
58
|
+
this.log(`"${switchName}" vəziyyəti dəyişdi: ${value}`);
|
|
45
59
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
60
|
+
if (value && conf.delayOff && conf.delayOff > 0) {
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
conf.state = false;
|
|
63
|
+
service.getCharacteristic(Characteristic.On).updateValue(false);
|
|
64
|
+
this.log(`"${switchName}" auto turn off tətbiq olundu`);
|
|
65
|
+
}, conf.delayOff); // saniyəni ms-ə çeviririk
|
|
66
|
+
}
|
|
54
67
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.updateStates();
|
|
58
|
-
}
|
|
68
|
+
callback();
|
|
69
|
+
});
|
|
59
70
|
|
|
60
|
-
|
|
61
|
-
this.switches.forEach((_, i) => {
|
|
62
|
-
this.services
|
|
63
|
-
.find((s) => s.subtype === "switch_" + i)
|
|
64
|
-
?.getCharacteristic(Characteristic.On)
|
|
65
|
-
.updateValue(this.switchStates[i]);
|
|
71
|
+
this.services.push(service);
|
|
66
72
|
});
|
|
67
73
|
}
|
|
68
74
|
|
|
69
75
|
getServices() {
|
|
70
|
-
return
|
|
76
|
+
return this.services;
|
|
71
77
|
}
|
|
72
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-multiple-switch",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Multiple switch accessory for Homebridge",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Azad Aydınlı",
|
|
@@ -16,4 +16,4 @@
|
|
|
16
16
|
"node": ">=14.17.0",
|
|
17
17
|
"homebridge": ">=1.3.0"
|
|
18
18
|
}
|
|
19
|
-
}
|
|
19
|
+
}
|