@joshjohanning/homebridge-fakeswitch 1.0.0

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.
@@ -0,0 +1,30 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+ branches: [main]
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: read
14
+ pull-requests: read
15
+
16
+ steps:
17
+ - name: Checkout repository
18
+ uses: actions/checkout@v6
19
+
20
+ - name: Setup Node.js
21
+ uses: actions/setup-node@v6
22
+ with:
23
+ node-version: '20'
24
+ cache: 'npm'
25
+
26
+ - name: Install dependencies
27
+ run: npm ci
28
+
29
+ - name: Check npm version compatibility
30
+ uses: joshjohanning/npm-version-check-action@v2
@@ -0,0 +1,110 @@
1
+ name: Publish Package
2
+
3
+ on:
4
+ release:
5
+ types: [created]
6
+ workflow_dispatch:
7
+ inputs:
8
+ npm:
9
+ description: 'Publish to NPM'
10
+ type: boolean
11
+ default: false
12
+ gh:
13
+ description: 'Publish to GitHub Packages'
14
+ type: boolean
15
+ default: true
16
+
17
+ jobs:
18
+ build:
19
+ runs-on: ubuntu-latest
20
+
21
+ permissions:
22
+ contents: read
23
+ id-token: write
24
+ attestations: write
25
+
26
+ steps:
27
+ - name: Checkout
28
+ uses: actions/checkout@v6
29
+
30
+ - name: Setup Node.js
31
+ uses: actions/setup-node@v6
32
+ with:
33
+ node-version: 20
34
+ cache: 'npm'
35
+
36
+ - name: Install dependencies
37
+ run: npm ci
38
+
39
+ - name: Build package tarball
40
+ run: npm pack
41
+
42
+ - name: Attest build provenance
43
+ uses: actions/attest@v4
44
+ with:
45
+ subject-path: '*.tgz'
46
+
47
+ - name: Upload tarball
48
+ uses: actions/upload-artifact@v7
49
+ with:
50
+ name: package
51
+ path: '*.tgz'
52
+ retention-days: 1
53
+
54
+ publish_npm:
55
+ needs: build
56
+ if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.npm) }}
57
+
58
+ runs-on: ubuntu-latest
59
+
60
+ permissions:
61
+ contents: read
62
+ id-token: write
63
+
64
+ steps:
65
+ - name: Download tarball
66
+ uses: actions/download-artifact@v8
67
+ with:
68
+ name: package
69
+
70
+ - name: Setup Node.js
71
+ uses: actions/setup-node@v6
72
+ with:
73
+ node-version: 20
74
+ registry-url: 'https://registry.npmjs.org'
75
+
76
+ # Ensure npm 11.5.1 or later is installed
77
+ - name: Update npm
78
+ run: npm install -g npm@latest
79
+
80
+ - name: NPM publish
81
+ run: npm publish *.tgz --access public --provenance
82
+ env:
83
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
84
+
85
+ publish_gh:
86
+ needs: build
87
+ if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.gh) }}
88
+
89
+ runs-on: ubuntu-latest
90
+
91
+ permissions:
92
+ contents: read
93
+ packages: write
94
+
95
+ steps:
96
+ - name: Download tarball
97
+ uses: actions/download-artifact@v8
98
+ with:
99
+ name: package
100
+
101
+ - name: Setup Node.js
102
+ uses: actions/setup-node@v6
103
+ with:
104
+ node-version: 20
105
+ registry-url: 'https://npm.pkg.github.com'
106
+
107
+ - name: GitHub Packages publish
108
+ run: npm publish *.tgz --access public
109
+ env:
110
+ NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/index.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ var Service, Characteristic, HomebridgeAPI;
4
+
5
+ module.exports = function(homebridge) {
6
+
7
+ Service = homebridge.hap.Service;
8
+ Characteristic = homebridge.hap.Characteristic;
9
+ HomebridgeAPI = homebridge;
10
+ homebridge.registerAccessory("homebridge-fakeswitch", "FakeSwitch", FakeSwitch);
11
+ }
12
+
13
+ function FakeSwitch(log, config) {
14
+ this.log = log;
15
+ this.name = config.name;
16
+ this.stateful = config.stateful;
17
+ this.reverse = config.reverse;
18
+ this._service = new Service.Switch(this.name);
19
+
20
+ this.cacheDirectory = HomebridgeAPI.user.persistPath();
21
+ this.storage = require('node-persist');
22
+ this.storage.initSync({dir:this.cacheDirectory, forgiveParseErrors: true});
23
+
24
+ this._service.getCharacteristic(Characteristic.On)
25
+ .on('set', this._setOn.bind(this));
26
+
27
+ if (this.reverse) this._service.setCharacteristic(Characteristic.On, true);
28
+
29
+ if (this.stateful) {
30
+ var cachedState = this.storage.getItemSync(this.name);
31
+ if((cachedState === undefined) || (cachedState === false)) {
32
+ this._service.setCharacteristic(Characteristic.On, false);
33
+ } else {
34
+ this._service.setCharacteristic(Characteristic.On, true);
35
+ }
36
+ }
37
+ }
38
+
39
+ FakeSwitch.prototype.getServices = function() {
40
+ return [this._service];
41
+ }
42
+
43
+ FakeSwitch.prototype._setOn = function(on, callback) {
44
+
45
+ this.log("Setting switch to " + on);
46
+
47
+ if (on && !this.reverse && !this.stateful) {
48
+ setTimeout(function() {
49
+ this._service.setCharacteristic(Characteristic.On, false);
50
+ }.bind(this), 1000);
51
+ } else if (!on && this.reverse && !this.stateful) {
52
+ setTimeout(function() {
53
+ this._service.setCharacteristic(Characteristic.On, true);
54
+ }.bind(this), 1000);
55
+ }
56
+
57
+ if (this.stateful) {
58
+ this.storage.setItemSync(this.name, on);
59
+ }
60
+
61
+ callback();
62
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@joshjohanning/homebridge-fakeswitch",
3
+ "version": "1.0.0",
4
+ "description": "A simple fake/dummy switch plugin for Homebridge; forked from thncode/homebridge-fakeswitch",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "homebridge-plugin",
8
+ "homebridge",
9
+ "fakeswitch",
10
+ "dummy-switch"
11
+ ],
12
+ "engines": {
13
+ "node": "^22.12.0 || ^24.0.0",
14
+ "homebridge": "^1.6.0 || ^2.0.0"
15
+ },
16
+ "author": {
17
+ "name": "Josh Johanning"
18
+ },
19
+ "contributors": [
20
+ {
21
+ "name": "Thomas Nemec"
22
+ }
23
+ ],
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/joshjohanning/homebridge-fakeswitch.git"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/joshjohanning/homebridge-fakeswitch/issues"
30
+ },
31
+ "homepage": "https://github.com/joshjohanning/homebridge-fakeswitch#readme",
32
+ "main": "index.js",
33
+ "dependencies": {
34
+ "node-persist": "^4.0.4"
35
+ }
36
+ }
package/readme.md ADDED
@@ -0,0 +1,49 @@
1
+ # "Dummy Switches" Plugin
2
+
3
+ Example config.json:
4
+
5
+ ```
6
+ "accessories": [
7
+ {
8
+ "accessory": "DummySwitch",
9
+ "name": "My Switch 1"
10
+ }
11
+ ]
12
+
13
+ ```
14
+
15
+ With this plugin, you can create any number of fake switches that will do nothing when turned on (and will automatically turn off right afterward, simulating a stateless switch). This can be very useful for advanced automation with HomeKit scenes.
16
+
17
+ For instance, the Philips Hue app will automatically create HomeKit scenes for you based on Hue Scenes you create. But what if you want to create a scene that contains both Philips Hue actions and other actions (like turning on the coffee maker with a WeMo outlet)? You are forced to either modify the Hue-created scene (which can be a HUGE list of actions if you have lots of lights) or build your own HomeKit lighting scenes.
18
+
19
+ Instead, you can link scenes using these dummy switches. Let's say you have a Hue Scene called "Rise and Shine" that you want to activate in the morning. And you have also setup the system HomeKit scene "Good Morning" to turn on your coffee maker and disarm you security system. You can add a single dummy switch to your Good Morning scene, then create a Trigger based on the switching-on of the dummy switch that also activates Rise And Shine.
20
+
21
+ ## Stateful Switches
22
+
23
+ The default behavior of a dummy switch is to turn itself off one second after being turned on. However you may want to create a dummy switch that remains on and must be manually turned off. You can do this by passing an argument in your config.json:
24
+
25
+ ```
26
+ "accessories": [
27
+ {
28
+ "accessory": "DummySwitch",
29
+ "name": "My Stateful Switch 1",
30
+ "stateful": true
31
+ }
32
+ ]
33
+
34
+ ```
35
+
36
+ ## Reverse Switches
37
+
38
+ You may also want to create a dummy switch that turns itself on one second after being turned off. This can be done by passing the 'reverse' argument in your config.json:
39
+
40
+ ```
41
+ "accessories": [
42
+ {
43
+ "accessory": "DummySwitch",
44
+ "name": "My Stateful Switch 1",
45
+ "reverse": true
46
+ }
47
+ ]
48
+
49
+ ```