homebridge-multiple-switch 1.1.4 → 1.1.5
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/.github/workflows/ci.yml +41 -0
- package/.github/workflows/release.yml +28 -0
- package/config.schema.json +14 -56
- package/index.js +98 -67
- package/package.json +4 -4
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [master]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- name: 📥 Repo-nu klonla
|
|
15
|
+
uses: actions/checkout@v3
|
|
16
|
+
|
|
17
|
+
- name: ⚙️ Node.js qur
|
|
18
|
+
uses: actions/setup-node@v3
|
|
19
|
+
with:
|
|
20
|
+
node-version: '18'
|
|
21
|
+
cache: 'npm'
|
|
22
|
+
|
|
23
|
+
- name: 📦 Asılılıqları qur
|
|
24
|
+
run: npm install
|
|
25
|
+
|
|
26
|
+
- name: ✅ Kod yoxlaması (lint varsa)
|
|
27
|
+
run: |
|
|
28
|
+
if [ -f .eslintrc.js ] || [ -f .eslintrc.json ]; then
|
|
29
|
+
npm run lint
|
|
30
|
+
else
|
|
31
|
+
echo "Lint skripti tapılmadı, keçilir..."
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
- name: 🧪 Testləri icra et (əgər varsa)
|
|
35
|
+
run: |
|
|
36
|
+
if [ -f package.json ] && grep -q '\"test\"' package.json; then
|
|
37
|
+
npm test
|
|
38
|
+
else
|
|
39
|
+
echo "Test skripti yoxdur, keçilir..."
|
|
40
|
+
fi
|
|
41
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: 📦 Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*.*.*'
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
steps:
|
|
13
|
+
- name: 📥 Repo-nu klonla
|
|
14
|
+
uses: actions/checkout@v3
|
|
15
|
+
|
|
16
|
+
- name: ⚙️ Node.js qur
|
|
17
|
+
uses: actions/setup-node@v3
|
|
18
|
+
with:
|
|
19
|
+
node-version: '18'
|
|
20
|
+
registry-url: 'https://registry.npmjs.org/'
|
|
21
|
+
|
|
22
|
+
- name: 📦 Asılılıqları qur
|
|
23
|
+
run: npm install
|
|
24
|
+
|
|
25
|
+
- name: 🚀 NPM-ə yüklə
|
|
26
|
+
run: npm publish
|
|
27
|
+
env:
|
|
28
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/config.schema.json
CHANGED
|
@@ -1,39 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
-
"pluginAlias": "
|
|
3
|
-
"pluginType": "
|
|
4
|
-
"
|
|
5
|
-
"headerDisplay": "Multiple Switch Accessory",
|
|
2
|
+
"pluginAlias": "MultipleSwitchPlatform",
|
|
3
|
+
"pluginType": "platform",
|
|
4
|
+
"headerDisplay": "Multiple Switch Platform",
|
|
6
5
|
"schema": {
|
|
7
6
|
"type": "object",
|
|
8
7
|
"properties": {
|
|
9
8
|
"name": {
|
|
10
|
-
"title": "
|
|
9
|
+
"title": "Platform Name",
|
|
11
10
|
"type": "string",
|
|
12
|
-
"default": "Multiple Switch"
|
|
11
|
+
"default": "Multiple Switch Platform"
|
|
13
12
|
},
|
|
14
13
|
"switchBehavior": {
|
|
15
14
|
"title": "Switch Behavior Mode",
|
|
16
15
|
"type": "string",
|
|
17
16
|
"default": "independent",
|
|
18
17
|
"oneOf": [
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"independent"
|
|
23
|
-
]
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"title": "Master",
|
|
27
|
-
"enum": [
|
|
28
|
-
"master"
|
|
29
|
-
]
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"title": "Single",
|
|
33
|
-
"enum": [
|
|
34
|
-
"single"
|
|
35
|
-
]
|
|
36
|
-
}
|
|
18
|
+
{ "title": "Independent", "enum": ["independent"] },
|
|
19
|
+
{ "title": "Master", "enum": ["master"] },
|
|
20
|
+
{ "title": "Single", "enum": ["single"] }
|
|
37
21
|
]
|
|
38
22
|
},
|
|
39
23
|
"switches": {
|
|
@@ -51,30 +35,10 @@
|
|
|
51
35
|
"type": "string",
|
|
52
36
|
"default": "outlet",
|
|
53
37
|
"oneOf": [
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
}
|
|
38
|
+
{ "title": "Switch", "enum": ["switch"] },
|
|
39
|
+
{ "title": "Outlet", "enum": ["outlet"] },
|
|
40
|
+
{ "title": "Lightbulb", "enum": ["lightbulb"] },
|
|
41
|
+
{ "title": "Fan", "enum": ["fan"] }
|
|
78
42
|
]
|
|
79
43
|
},
|
|
80
44
|
"defaultState": {
|
|
@@ -89,10 +53,7 @@
|
|
|
89
53
|
"minimum": 0
|
|
90
54
|
}
|
|
91
55
|
},
|
|
92
|
-
"required": [
|
|
93
|
-
"name",
|
|
94
|
-
"type"
|
|
95
|
-
]
|
|
56
|
+
"required": ["name", "type"]
|
|
96
57
|
},
|
|
97
58
|
"default": [
|
|
98
59
|
{
|
|
@@ -104,9 +65,6 @@
|
|
|
104
65
|
]
|
|
105
66
|
}
|
|
106
67
|
},
|
|
107
|
-
"required": [
|
|
108
|
-
"name",
|
|
109
|
-
"switches"
|
|
110
|
-
]
|
|
68
|
+
"required": ["name", "switches"]
|
|
111
69
|
}
|
|
112
70
|
}
|
package/index.js
CHANGED
|
@@ -1,78 +1,109 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
MultipleSwitchAccessory
|
|
12
|
-
);
|
|
1
|
+
// homebridge-multiple-switch: index.js (Platform plugin, bir Accessory, çox Service)
|
|
2
|
+
|
|
3
|
+
let Service, Characteristic, UUIDGen;
|
|
4
|
+
|
|
5
|
+
module.exports = (api) => {
|
|
6
|
+
Service = api.hap.Service;
|
|
7
|
+
Characteristic = api.hap.Characteristic;
|
|
8
|
+
UUIDGen = api.hap.uuid;
|
|
9
|
+
|
|
10
|
+
api.registerPlatform('MultipleSwitchPlatform', MultipleSwitchPlatform);
|
|
13
11
|
};
|
|
14
12
|
|
|
15
|
-
class
|
|
16
|
-
constructor(log, config) {
|
|
13
|
+
class MultipleSwitchPlatform {
|
|
14
|
+
constructor(log, config, api) {
|
|
17
15
|
this.log = log;
|
|
18
16
|
this.config = config;
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
17
|
+
this.api = api;
|
|
18
|
+
this.accessories = [];
|
|
19
|
+
|
|
20
|
+
this.api.on('didFinishLaunching', () => {
|
|
21
|
+
this.log('🔌 MultipleSwitchPlatform başladıldı.');
|
|
22
|
+
this.setupAccessories();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
setupAccessories() {
|
|
27
|
+
const switches = this.config.switches || [];
|
|
28
|
+
const behavior = this.config.switchBehavior || 'independent';
|
|
29
|
+
const name = this.config.name || 'Multiple Switch Panel';
|
|
30
|
+
|
|
31
|
+
const uuid = UUIDGen.generate(name);
|
|
32
|
+
const accessory = new this.api.platformAccessory(name, uuid);
|
|
33
|
+
|
|
34
|
+
accessory.context.switchStates = {};
|
|
35
|
+
accessory.context.switchServices = {};
|
|
36
|
+
accessory.context.switchBehavior = behavior;
|
|
37
|
+
|
|
38
|
+
switches.forEach((sw, index) => {
|
|
39
|
+
const id = `switch_${index}`;
|
|
40
|
+
const service = this.createSwitchService(accessory, sw, id);
|
|
41
|
+
|
|
42
|
+
accessory.addService(service);
|
|
43
|
+
accessory.context.switchStates[id] = sw.defaultState || false;
|
|
44
|
+
accessory.context.switchServices[id] = service;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
this.api.registerPlatformAccessories(
|
|
48
|
+
'homebridge-multiple-switch',
|
|
49
|
+
'MultipleSwitchPlatform',
|
|
50
|
+
[accessory]
|
|
51
|
+
);
|
|
52
|
+
this.accessories.push(accessory);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
createSwitchService(accessory, sw, id) {
|
|
56
|
+
const ServiceType = this.getServiceClass(sw.type);
|
|
57
|
+
const service = new ServiceType(sw.name, id);
|
|
58
|
+
|
|
59
|
+
service.getCharacteristic(Characteristic.On)
|
|
60
|
+
.onGet(() => {
|
|
61
|
+
return accessory.context.switchStates[id];
|
|
62
|
+
})
|
|
63
|
+
.onSet((value) => {
|
|
64
|
+
const behavior = accessory.context.switchBehavior;
|
|
65
|
+
accessory.context.switchStates[id] = value;
|
|
66
|
+
this.log(`[${sw.name}] → ${value ? 'ON' : 'OFF'}`);
|
|
67
|
+
|
|
68
|
+
if (behavior === 'single' && value) {
|
|
69
|
+
Object.keys(accessory.context.switchStates).forEach(key => {
|
|
70
|
+
if (key !== id) {
|
|
71
|
+
accessory.context.switchStates[key] = false;
|
|
72
|
+
accessory.context.switchServices[key].updateCharacteristic(Characteristic.On, false);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (behavior === 'master') {
|
|
78
|
+
Object.keys(accessory.context.switchStates).forEach(key => {
|
|
79
|
+
accessory.context.switchStates[key] = value;
|
|
80
|
+
accessory.context.switchServices[key].updateCharacteristic(Characteristic.On, value);
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
if (value && sw.delayOff > 0) {
|
|
61
84
|
setTimeout(() => {
|
|
62
|
-
|
|
63
|
-
service.
|
|
64
|
-
this.log(`
|
|
65
|
-
},
|
|
85
|
+
accessory.context.switchStates[id] = false;
|
|
86
|
+
service.updateCharacteristic(Characteristic.On, false);
|
|
87
|
+
this.log(`[${sw.name}] auto-off after ${sw.delayOff}ms`);
|
|
88
|
+
}, sw.delayOff);
|
|
66
89
|
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
67
92
|
|
|
68
|
-
|
|
69
|
-
|
|
93
|
+
return service;
|
|
94
|
+
}
|
|
70
95
|
|
|
71
|
-
|
|
72
|
-
|
|
96
|
+
getServiceClass(type) {
|
|
97
|
+
switch ((type || '').toLowerCase()) {
|
|
98
|
+
case 'switch': return Service.Switch;
|
|
99
|
+
case 'lightbulb': return Service.Lightbulb;
|
|
100
|
+
case 'fan': return Service.Fan;
|
|
101
|
+
case 'outlet':
|
|
102
|
+
default: return Service.Outlet;
|
|
103
|
+
}
|
|
73
104
|
}
|
|
74
105
|
|
|
75
|
-
|
|
76
|
-
|
|
106
|
+
configureAccessory(accessory) {
|
|
107
|
+
this.accessories.push(accessory);
|
|
77
108
|
}
|
|
78
|
-
}
|
|
109
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-multiple-switch",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Multiple switch
|
|
3
|
+
"version": "1.1.5",
|
|
4
|
+
"description": "Multiple switch platform for Homebridge",
|
|
5
5
|
"homepage": "https://github.com/azadaydinli/homebridge-multiple-switch",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": "Azad Aydınlı",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"fan",
|
|
20
20
|
"dummy",
|
|
21
21
|
"multiple",
|
|
22
|
-
"
|
|
22
|
+
"platform"
|
|
23
23
|
],
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|
|
@@ -29,4 +29,4 @@
|
|
|
29
29
|
"node": ">=14.17.0",
|
|
30
30
|
"homebridge": ">=1.3.0"
|
|
31
31
|
}
|
|
32
|
-
}
|
|
32
|
+
}
|