homebridge-dummy 0.7.0 → 0.9.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.
- package/README.md +20 -2
- package/config.schema.json +21 -0
- package/index.js +54 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,8 @@ Example config.json:
|
|
|
7
7
|
"accessories": [
|
|
8
8
|
{
|
|
9
9
|
"accessory": "DummySwitch",
|
|
10
|
-
"name": "My Switch 1"
|
|
10
|
+
"name": "My Switch 1",
|
|
11
|
+
"disableLogging": false
|
|
11
12
|
}
|
|
12
13
|
]
|
|
13
14
|
|
|
@@ -17,7 +18,9 @@ With this plugin, you can create any number of fake switches that will do nothin
|
|
|
17
18
|
|
|
18
19
|
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.
|
|
19
20
|
|
|
20
|
-
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
|
|
21
|
+
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 your 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.
|
|
22
|
+
|
|
23
|
+
If the disableLogging option is true, state changes (On/Off) will not be logged. The disableLogging option is per switch, so you can choose which ones will get log entries. If not supplied, the default value is false and state changes will be logged.
|
|
21
24
|
|
|
22
25
|
## Stateful Switches
|
|
23
26
|
|
|
@@ -34,6 +37,21 @@ The default behavior of a dummy switch is to turn itself off one second after be
|
|
|
34
37
|
|
|
35
38
|
```
|
|
36
39
|
|
|
40
|
+
## Dimmer Switches
|
|
41
|
+
|
|
42
|
+
By default, switches are toggle switches (on/off). You can configure your switch to be a dimmer switch, instead, storing a brightness value between 0 and 100. This can be done by passing the 'dimmer' argument in your config.json:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
"accessories": [
|
|
46
|
+
{
|
|
47
|
+
"accessory": "DummySwitch",
|
|
48
|
+
"name": "My Stateful Switch 1",
|
|
49
|
+
"dimmer": true
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
|
|
37
55
|
## Reverse Switches
|
|
38
56
|
|
|
39
57
|
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:
|
package/config.schema.json
CHANGED
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
"default": false,
|
|
17
17
|
"description": "The switch remains on instead of being automatically turned off."
|
|
18
18
|
},
|
|
19
|
+
"dimmer": {
|
|
20
|
+
"title": "Dimmer",
|
|
21
|
+
"type": "boolean",
|
|
22
|
+
"default": false,
|
|
23
|
+
"description": "Make the switch a dimmer instead of a toggle (on/off) switch"
|
|
24
|
+
},
|
|
19
25
|
"reverse": {
|
|
20
26
|
"title": "Reverse",
|
|
21
27
|
"type": "boolean",
|
|
@@ -39,7 +45,22 @@
|
|
|
39
45
|
"type": "boolean",
|
|
40
46
|
"default": false,
|
|
41
47
|
"description": "The timer will reset each time the switch is turned on. "
|
|
48
|
+
},
|
|
49
|
+
"brightness": {
|
|
50
|
+
"title": "Brightness",
|
|
51
|
+
"type": "integer",
|
|
52
|
+
"default": 0,
|
|
53
|
+
"placeholder": 0,
|
|
54
|
+
"maximum": 100,
|
|
55
|
+
"description": "Starting brightness (dimmer only)"
|
|
56
|
+
},
|
|
57
|
+
"disableLogging": {
|
|
58
|
+
"title": "DisableLogging",
|
|
59
|
+
"type": "boolean",
|
|
60
|
+
"default": false,
|
|
61
|
+
"description": "No state change information (On/Off) will be logged. "
|
|
42
62
|
}
|
|
63
|
+
|
|
43
64
|
}
|
|
44
65
|
}
|
|
45
66
|
}
|
package/index.js
CHANGED
|
@@ -16,17 +16,28 @@ function DummySwitch(log, config) {
|
|
|
16
16
|
this.log = log;
|
|
17
17
|
this.name = config.name;
|
|
18
18
|
this.stateful = config.stateful;
|
|
19
|
+
this.dimmer = config.dimmer;
|
|
20
|
+
this.brightness = config.brightness;
|
|
21
|
+
this.brightnessStorageKey = this.name + "Brightness";
|
|
19
22
|
this.reverse = config.reverse;
|
|
20
23
|
this.time = config.time ? config.time : 1000;
|
|
21
24
|
this.resettable = config.resettable;
|
|
22
25
|
this.timer = null;
|
|
23
26
|
this.random = config.random;
|
|
24
|
-
this.
|
|
27
|
+
this.disableLogging = config.disableLogging;
|
|
28
|
+
|
|
29
|
+
if (this.dimmer) {
|
|
30
|
+
this._service = new Service.Lightbulb(this.name);
|
|
31
|
+
this.modelString = "Dummy Dimmer";
|
|
32
|
+
} else {
|
|
33
|
+
this._service = new Service.Switch(this.name);
|
|
34
|
+
this.modelString = "Dummy Switch";
|
|
35
|
+
}
|
|
25
36
|
|
|
26
37
|
this.informationService = new Service.AccessoryInformation();
|
|
27
38
|
this.informationService
|
|
28
39
|
.setCharacteristic(Characteristic.Manufacturer, 'Homebridge')
|
|
29
|
-
.setCharacteristic(Characteristic.Model,
|
|
40
|
+
.setCharacteristic(Characteristic.Model, this.modelString)
|
|
30
41
|
.setCharacteristic(Characteristic.FirmwareRevision, HomebridgeDummyVersion)
|
|
31
42
|
.setCharacteristic(Characteristic.SerialNumber, 'Dummy-' + this.name.replace(/\s/g, '-'));
|
|
32
43
|
|
|
@@ -36,6 +47,11 @@ function DummySwitch(log, config) {
|
|
|
36
47
|
|
|
37
48
|
this._service.getCharacteristic(Characteristic.On)
|
|
38
49
|
.on('set', this._setOn.bind(this));
|
|
50
|
+
if (this.dimmer) {
|
|
51
|
+
this._service.getCharacteristic(Characteristic.Brightness)
|
|
52
|
+
.on('get', this._getBrightness.bind(this))
|
|
53
|
+
.on('set', this._setBrightness.bind(this));
|
|
54
|
+
}
|
|
39
55
|
|
|
40
56
|
if (this.reverse) this._service.setCharacteristic(Characteristic.On, true);
|
|
41
57
|
|
|
@@ -47,6 +63,17 @@ function DummySwitch(log, config) {
|
|
|
47
63
|
this._service.setCharacteristic(Characteristic.On, true);
|
|
48
64
|
}
|
|
49
65
|
}
|
|
66
|
+
|
|
67
|
+
if (this.dimmer) {
|
|
68
|
+
var cachedBrightness = this.storage.getItemSync(this.brightnessStorageKey);
|
|
69
|
+
if ((cachedBrightness == undefined) || cachedBrightness == 0) {
|
|
70
|
+
this._service.setCharacteristic(Characteristic.On, false);
|
|
71
|
+
this._service.setCharacteristic(Characteristic.Brightness, 0);
|
|
72
|
+
} else {
|
|
73
|
+
this._service.setCharacteristic(Characteristic.On, true);
|
|
74
|
+
this._service.setCharacteristic(Characteristic.Brightness, cachedBrightness);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
50
77
|
}
|
|
51
78
|
|
|
52
79
|
DummySwitch.prototype.getServices = function() {
|
|
@@ -57,6 +84,28 @@ function randomize(time) {
|
|
|
57
84
|
return Math.floor(Math.random() * (time + 1));
|
|
58
85
|
}
|
|
59
86
|
|
|
87
|
+
DummySwitch.prototype._getBrightness = function(callback) {
|
|
88
|
+
|
|
89
|
+
if ( ! this.disableLogging ) {
|
|
90
|
+
this.log("Getting " + "brightness: " + this.brightness);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
callback(null, this.brightness);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
DummySwitch.prototype._setBrightness = function(brightness, callback) {
|
|
97
|
+
|
|
98
|
+
if ( ! this.disableLogging ) {
|
|
99
|
+
var msg = "Setting brightness: " + brightness
|
|
100
|
+
this.log(msg);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this.brightness = brightness;
|
|
104
|
+
this.storage.setItemSync(this.brightnessStorageKey, brightness);
|
|
105
|
+
|
|
106
|
+
callback();
|
|
107
|
+
}
|
|
108
|
+
|
|
60
109
|
DummySwitch.prototype._setOn = function(on, callback) {
|
|
61
110
|
|
|
62
111
|
var delay = this.random ? randomize(this.time) : this.time;
|
|
@@ -66,7 +115,9 @@ DummySwitch.prototype._setOn = function(on, callback) {
|
|
|
66
115
|
msg = msg + " (random delay " + delay + "ms)"
|
|
67
116
|
}
|
|
68
117
|
}
|
|
69
|
-
this.
|
|
118
|
+
if( ! this.disableLogging ) {
|
|
119
|
+
this.log(msg);
|
|
120
|
+
}
|
|
70
121
|
|
|
71
122
|
if (on && !this.reverse && !this.stateful) {
|
|
72
123
|
if (this.resettable) {
|