homebridge-dummy 0.9.1 → 1.0.0-alpha.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +13 -2
  2. package/README.md +146 -81
  3. package/config.schema.json +150 -54
  4. package/dist/accessory/base.d.ts +23 -0
  5. package/dist/accessory/base.js +69 -0
  6. package/dist/accessory/base.js.map +1 -0
  7. package/dist/accessory/lightbulb.d.ts +15 -0
  8. package/dist/accessory/lightbulb.js +50 -0
  9. package/dist/accessory/lightbulb.js.map +1 -0
  10. package/dist/accessory/onoff.d.ts +16 -0
  11. package/dist/accessory/onoff.js +56 -0
  12. package/dist/accessory/onoff.js.map +1 -0
  13. package/dist/accessory/switch.d.ts +8 -0
  14. package/dist/accessory/switch.js +10 -0
  15. package/dist/accessory/switch.js.map +1 -0
  16. package/dist/homebridge/index.d.ts +3 -5
  17. package/dist/homebridge/index.js +4 -136
  18. package/dist/homebridge/index.js.map +1 -1
  19. package/dist/homebridge/platform.d.ts +15 -0
  20. package/dist/homebridge/platform.js +97 -0
  21. package/dist/homebridge/platform.js.map +1 -0
  22. package/dist/homebridge/settings.d.ts +3 -1
  23. package/dist/homebridge/settings.js +3 -1
  24. package/dist/homebridge/settings.js.map +1 -1
  25. package/dist/homebridge-ui/public/index.html +35 -0
  26. package/dist/homebridge-ui/public/ui.js +1 -0
  27. package/dist/homebridge-ui/server.d.ts +1 -0
  28. package/dist/homebridge-ui/server.js +15 -0
  29. package/dist/homebridge-ui/server.js.map +1 -0
  30. package/dist/i18n/en.d.ts +47 -12
  31. package/dist/i18n/en.js +53 -13
  32. package/dist/i18n/en.js.map +1 -1
  33. package/dist/i18n/i18n.d.ts +47 -12
  34. package/dist/i18n/template.d.ts +47 -12
  35. package/dist/i18n/zz.d.ts +47 -12
  36. package/dist/model/timer.d.ts +12 -0
  37. package/dist/model/timer.js +64 -0
  38. package/dist/model/timer.js.map +1 -0
  39. package/dist/model/types.d.ts +60 -0
  40. package/dist/model/types.js +13 -0
  41. package/dist/model/types.js.map +1 -0
  42. package/dist/tools/configMigration.d.ts +3 -0
  43. package/dist/tools/configMigration.js +86 -0
  44. package/dist/tools/configMigration.js.map +1 -0
  45. package/dist/tools/log.d.ts +14 -0
  46. package/dist/tools/log.js +25 -0
  47. package/dist/tools/log.js.map +1 -0
  48. package/dist/tools/storage.d.ts +4 -2
  49. package/dist/tools/storage.js +7 -4
  50. package/dist/tools/storage.js.map +1 -1
  51. package/dist/tools/validation.d.ts +3 -0
  52. package/dist/tools/validation.js +13 -0
  53. package/dist/tools/validation.js.map +1 -0
  54. package/package.json +33 -24
  55. package/src/homebridge-ui/public/index.html +35 -0
package/CHANGELOG.md CHANGED
@@ -2,12 +2,23 @@
2
2
 
3
3
  All notable changes to homebridge-dummy will be documented in this file.
4
4
 
5
- ## 0.9.1 (2025-06-25)
6
-
7
5
  ⚠️ Plugin has a new owner/maintainer and will undergo significant cleanup and modernization in the near term. If you experience issues you can always downgrade to the last stable version v0.9.0
8
6
 
9
7
  Please report any issues you encounter here: https://github.com/mpatfield/homebridge-dummy/issues
10
8
 
9
+ ## 1.0.0-alpha.0 (XXXX-XX-XX)
10
+
11
+ # ‼️ This version is a complete code rewrite. Automations using Homebridge Dummy accessories will need to be reconfigured.
12
+
13
+ More details [here](https://github.com/mpatfield/homebridge-dummy?tab=readme-ov-file#v100-migration).
14
+
15
+ ## 0.9.2 (2025-06-26)
16
+
17
+ ### Fixed
18
+ - Stateful switches not persisting across homebridge restarts
19
+
20
+ ## 0.9.1 (2025-06-25)
21
+
11
22
  ### ⚠️ BREAKING
12
23
  - node-persist updated from major version 2 to 4, so stateful and dimmer switches may lose their previously saved states
13
24
 
package/README.md CHANGED
@@ -1,125 +1,190 @@
1
+ <!--
2
+ <p align="center">
3
+ <img src="https://github.com/mpatfield/homebridge-dummy/blob/latest/img/banner.png?raw=true" width="600">
4
+ </p>
5
+ -->
1
6
 
2
- # "Dummy Switches" Plugin
7
+ <span align="center">
3
8
 
4
- Example config.json:
9
+ # homebridge-dummy
5
10
 
6
- ```
7
- "accessories": [
8
- {
9
- "accessory": "DummySwitch",
10
- "name": "My Switch 1",
11
- "disableLogging": false
12
- }
13
- ]
11
+ Homebridge plugin to create fake accessories for assisting with advanced Apple HomeKit automations
14
12
 
15
- ```
13
+ [![verified-by-homebridge](https://badgen.net/badge/homebridge/verified/purple)](https://github.com/homebridge/homebridge/wiki/Verified-Plugins)
14
+ [![hoobs-certified](https://badgen.net/badge/HOOBS/certified/yellow)](https://plugins.hoobs.org/plugin/homebridge-dummy)
15
+ [![npm](https://img.shields.io/npm/dw/homebridge-dummy)](https://www.npmjs.com/package/homebridge-dummy)
16
+ [![npm](https://img.shields.io/npm/dt/homebridge-dummy)](https://www.npmjs.com/package/homebridge-dummy)
16
17
 
17
- 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.
18
+ </span>
18
19
 
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.
20
+ ## Disclaimer
20
21
 
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
+ Any issues or damage resulting from use of this plugin are not the fault of the developer. Use at your own risk.
22
23
 
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.
24
+ ## v1.0 Migration
24
25
 
25
- ## Stateful Switches
26
+ ### tl;dr
26
27
 
27
- 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:
28
+ ‼️ There are significant code changes between v0.9 and v1.0 which means you will need to reconfigure HomeKit automations after upgrading. Homebridge Dummy will try to migrate old accessories in Homebridge so you don't need to recreate everything.
28
29
 
29
- ```
30
- "accessories": [
31
- {
32
- "accessory": "DummySwitch",
33
- "name": "My Stateful Switch 1",
34
- "stateful": true
35
- }
36
- ]
30
+ ### Why?
37
31
 
38
- ```
32
+ The original HomebridgeDummy was written almost 10 years ago and uses the now deprecated [Accessory Plugin](https://developers.homebridge.io/#/api/accessory-plugins) architecture.
39
33
 
40
- ## Dimmer Switches
34
+ While this still works okay for now, migrating the code to use [Platform Plugins](https://developers.homebridge.io/#/api/platform-plugins) will future-proof Homebridge Dummy and allow for more modern and robust design patterns.
41
35
 
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:
36
+ v1.0 doesn't include any new features but will make it much easier to improve and extend this plugin going forward.
43
37
 
44
- ```
45
- "accessories": [
46
- {
47
- "accessory": "DummySwitch",
48
- "name": "My Stateful Switch 1",
49
- "dimmer": true
50
- }
51
- ]
38
+ ### Drawbacks
52
39
 
53
- ```
40
+ Unfortunately, there is no built-in way to migrate existing accessory plugins to platform plugins. This means that all accessories will be considered "new" by HomeKit, so any existing automations or room setups will be lost.
54
41
 
55
- ## Reverse Switches
42
+ However, Homebridge Dummy will try to migrate the accessory configurations to the new system to prevent you having to set them all up again in Homebridge.
56
43
 
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:
44
+ ### Migration Flow
58
45
 
59
- ```
60
- "accessories": [
61
- {
62
- "accessory": "DummySwitch",
63
- "name": "My Stateful Switch 1",
64
- "reverse": true
65
- }
66
- ]
46
+ Once you have installed v1.0, click on the icon to configure the Homebridge Dummy plugin in the Homebridge UI and it will walk you through the necessary questionnaire.
67
47
 
48
+ Alternatively, you can add the following to "platforms" in your config.json
49
+
50
+ ```json
51
+ {
52
+ "name": "Homebridge Dummy",
53
+ "platform": "HomebridgeDummy",
54
+ "migrationNeeded": true
55
+ }
68
56
  ```
69
57
 
70
- ## Timed Switches
58
+ You will need to restart Homebridge after completing the flow for changes to take effect.
71
59
 
72
- You may also want to create a timed switch that turns itself off after being on for a given time (for example, five seconds). This can be done by passing the 'time' argument in your config.json:
60
+ ⚠️ If you are using child bridges with v0.9, you will need to restart Homebridge _twice_ for migrated accessories to show up correctly.
73
61
 
74
- ```
62
+ You may safely ignore any "No plugin was found…" errors you see in the Homebridge logs. These should go away after a few Homebridge restarts.
63
+
64
+ ### Problems?
65
+
66
+ This is a highly experimental flow and may not work as intended. If you see "Sorry, something went wrong with the accessory migration" or encounter other issues, please [create an issue](https://github.com/mpatfield/homebridge-dummy/issues/new?template=new-issue.md).
67
+
68
+ The first thing the flow does is create a backup called `config.json.bak` in your Homebridge directory. If all else fails, you can replace your `config.json` with the backup and downgrade to Homebridge Dummy v0.9 to restore everything back to normal.
69
+
70
+ ## About
71
+
72
+ With this plugin, you can create any number of fake accessories that will do nothing when triggered. This can be very useful for advanced automation with HomeKit scenes.
73
+
74
+ Currently, only Lightbulbs and Switches are supported but we plan to add more options over the coming months.
75
+
76
+ ## Configuration
77
+
78
+ Using the Homebridge Config UI is the easiest way to set up this plugin. However, if you wish to do things manually then you will need to add the following to your Homebridge `config.json`:
79
+
80
+ ```json
81
+ {
82
+ "name": "Homebridge Dummy",
75
83
  "accessories": [
76
84
  {
77
- "accessory": "DummySwitch",
78
- "name": "My Stateful Switch 1",
79
- "time": 5000
80
- }
81
- ]
82
-
85
+ "name": "string",
86
+ "type": "Lightbulb | Switch",
87
+ "timer": {
88
+ "delay": 1,
89
+ "units": "SECONDS | MINUTES | HOURS",
90
+ "random": false
91
+ },
92
+ "defaultOn": false,
93
+ "defaultBrightness": 100,
94
+ "disableLogging": false
95
+ }
96
+ // ...additional accessories...
97
+ ],
98
+ "platform": "HomebridgeDummy"
99
+ }
83
100
  ```
84
101
 
85
- ## Resettable Timed Switches
102
+ All fields are optional unless noted with an asterisk (*)
103
+
104
+ - `name`* - The display name for the accessory in HomeKit
105
+ - `type`* - The type of accessory, currently `Lightbulb` and `Switch` are supported
106
+
107
+ - `timer.delay` — If defined, the switch will automatically toggle after this many seconds/minutes/hours
108
+ - `timer.units` — The units to use for delay above (`SECONDS`, `MINUTES`, or `HOURS`). *Required if delay is set.
109
+ - `timer.random` — If true, the delay will be randomized with a maximum value of `timer.delay`
86
110
 
87
- You may also want to create a timed switch that is reset each time it is activated. This way, the original timer is reset instead of creating a new timer.
88
- This can be done by passing the 'resettable' argument in your config.json:
111
+ - `defaultOn` If true, the states are reversed so that the default state is _on_. Only applicable to Switches.
89
112
 
113
+ - `defaultBrightness` — If set, lightbulb will have additional dimmer settings with this default brightness percentage
114
+
115
+ - `disableLogging` — If true, state changes will not be logged
116
+
117
+ ## Examples
118
+
119
+ ### Stateful Switch
120
+ ```json
121
+ {
122
+ "name": "Stateful",
123
+ "type": "Switch"
124
+ }
90
125
  ```
91
- "accessories": [
92
- {
93
- "accessory": "DummySwitch",
94
- "name": "My Stateful Switch 1",
95
- "time": 5000,
96
- "resettable": true
97
- }
98
- ]
99
126
 
127
+ ### Timer Switch
128
+ ```json
129
+ {
130
+ "name": "Timer",
131
+ "type": "Switch",
132
+ "timer": {
133
+ "delay": 10,
134
+ "units": "SECONDS"
135
+ }
136
+ }
100
137
  ```
101
138
 
102
- ## Random Timed Switches
139
+ ### "Reversed" Switch (i.e. Default On)
140
+ ```json
141
+ {
142
+ "name": "Default On",
143
+ "type": "Switch",
144
+ "timer": {
145
+ "delay": 5,
146
+ "units": "SECONDS"
147
+ },
148
+ "defaultOn": true
149
+ }
150
+ ```
103
151
 
104
- You might want to create a switch that given a random time turns itself off.
105
- This can be achieved by enabling 'random'.
106
- Each time a non-stateful, random timed switch is triggered, the time is set to a random value between 0 and 'time' milliseconds.
107
- A random period within one hour is defined as follows in your config.json:
152
+ ### Timer Lightbulb
153
+ ```json
154
+ {
155
+ "name": "Lightbulb",
156
+ "type": "Lightbulb",
157
+ "timer": {
158
+ "delay": 5,
159
+ "units": "SECONDS"
160
+ }
161
+ }
162
+ ```
108
163
 
164
+ ### Stateful Dimmer Lightbulb
165
+ ```json
166
+ {
167
+ "name": "Dimmer",
168
+ "type": "Lightbulb",
169
+ "defaultBrightness": 42
170
+ }
109
171
  ```
110
- "accessories": [
111
- {
112
- "accessory": "DummySwitch",
113
- "name": "My Stateful Random Switch 1",
114
- "time": 3600000,
115
- "random": true
116
- }
117
- ]
118
172
 
173
+ ### Random Timer Switch
174
+ ```json
175
+ {
176
+ "name": "Random",
177
+ "type": "Switch",
178
+ "timer": {
179
+ "delay": 2,
180
+ "units": "MINUTES",
181
+ "random": true
182
+ }
183
+ }
119
184
  ```
120
185
 
121
186
  ## Credits
122
187
 
123
- Special thanks to [@nfarina](https://github.com/nfarina) for creating the original version of this plugin and maintaining it for almost 10\(!!!\) years
188
+ Special thanks to [@nfarina](https://github.com/nfarina) for creating the original version of this plugin and maintaining it for almost 10 (!!!) years
124
189
 
125
190
  And to the amazing creators/contributors of [Homebridge](https://homebridge.io) who made this plugin possible!
@@ -1,66 +1,162 @@
1
1
  {
2
- "pluginAlias": "DummySwitch",
3
- "pluginType": "accessory",
4
- "singular": false,
5
- "schema": {
2
+ "pluginAlias": "HomebridgeDummy",
3
+ "pluginType": "platform",
4
+ "singular": true,
5
+ "customUi": true,
6
+ "customUiPath": "./dist/homebridge-ui",
7
+ "schema": {
8
+ "type": "object",
9
+ "definitions": {
10
+ "timer": {
6
11
  "type": "object",
7
12
  "properties": {
13
+ "delay": {
14
+ "type": "integer",
15
+ "title": "${config.title.delay}",
16
+ "minimum": 1
17
+ },
18
+ "units": {
19
+ "type": "string",
20
+ "title": "${config.title.units}",
21
+ "enum": [ "SECONDS", "MINUTES", "HOURS"],
22
+ "enumNames": ["${config.enumNames.seconds}", "${config.enumNames.minutes}", "${config.enumNames.hours}"]
23
+ },
24
+ "random": {
25
+ "type": "boolean",
26
+ "title": "${config.title.random}",
27
+ "description": "${config.description.random}"
28
+ }
29
+ }
30
+ }
31
+ },
32
+ "properties": {
33
+ "name": {
34
+ "type": "string",
35
+ "default": "Homebridge Dummy"
36
+ },
37
+ "accessories": {
38
+ "type": "array",
39
+ "items": {
40
+ "type": "object",
41
+ "properties": {
8
42
  "name": {
9
- "title": "Name",
10
- "type": "string",
11
- "required": true
12
- },
13
- "stateful": {
14
- "title": "Stateful",
15
- "type": "boolean",
16
- "default": false,
17
- "description": "The switch remains on instead of being automatically turned off."
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
- },
25
- "reverse": {
26
- "title": "Reverse",
27
- "type": "boolean",
28
- "default": false,
29
- "description": "The switch's default state is on."
43
+ "type": "string",
44
+ "title": "${config.title.name}" ,
45
+ "required": true
30
46
  },
31
- "time": {
32
- "title": "Time",
33
- "type": "number",
34
- "default": 1000,
35
- "description": "The switch will turn off after this number of milliseconds. Not used if the switch is stateful."
47
+ "type": {
48
+ "type": "string",
49
+ "title": "${config.title.type}",
50
+ "enum": ["Lightbulb", "Switch"],
51
+ "enumNames": ["${config.enumNames.lightbulb}", "${config.enumNames.switch}"],
52
+ "required": true
36
53
  },
37
- "random": {
38
- "title": "Random",
39
- "type": "boolean",
40
- "default": false,
41
- "description": "Randomize the time until a switch turns off. Not used if the switch is stateful."
54
+ "timer": { "$ref": "#/definitions/timer" },
55
+ "defaultBrightness": {
56
+ "type": "number",
57
+ "minimum": 0,
58
+ "maximum": 100,
59
+ "title": "${config.title.defaultBrightness}"
42
60
  },
43
- "resettable": {
44
- "title": "Resettable",
45
- "type": "boolean",
46
- "default": false,
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)"
61
+ "defaultOn": {
62
+ "type": "boolean",
63
+ "title": "${config.title.defaultOn}"
56
64
  },
57
65
  "disableLogging": {
58
- "title": "DisableLogging",
59
- "type": "boolean",
60
- "default": false,
61
- "description": "No state change information (On/Off) will be logged. "
66
+ "title": "${config.title.disableLogging}",
67
+ "type": "boolean"
62
68
  }
63
-
69
+ }
70
+ }
71
+ }
72
+ }
73
+ },
74
+ "layout": [
75
+ {
76
+ "type": "array",
77
+ "key": "accessories",
78
+ "notitle": true,
79
+ "items": [
80
+ {
81
+ "type": "fieldset",
82
+ "expandable": true,
83
+ "title": "${config.title.accessory}",
84
+ "items": [
85
+ {
86
+ "type": "div",
87
+ "displayFlex": true,
88
+ "flex-direction": "row",
89
+ "items": [
90
+ {
91
+ "key": "accessories[].name",
92
+ "flex": "1 1 0"
93
+ },
94
+ {
95
+ "key": "accessories[].type",
96
+ "flex": "1 1 0"
97
+ }
98
+ ]
99
+ },
100
+ {
101
+ "type": "fieldset",
102
+ "title": "${config.title.timer}",
103
+ "description": "${config.description.timer}",
104
+ "condition": {
105
+ "functionBody": "return model.accessories?.[arguments[1]]?.type;"
106
+ },
107
+ "items": [
108
+ {
109
+ "type": "div",
110
+ "displayFlex": true,
111
+ "flex-direction": "row",
112
+ "items": [
113
+ {
114
+ "key": "accessories[].timer.delay",
115
+ "flex": "1 1 0"
116
+ },
117
+ {
118
+ "key": "accessories[].timer.units",
119
+ "flex": "1 1 0"
120
+ }
121
+ ]
122
+ },
123
+ "accessories[].timer.random"
124
+ ]
125
+ },
126
+ {
127
+ "type": "fieldset",
128
+ "title": "${config.title.options}",
129
+ "condition": {
130
+ "functionBody": "return ['Lightbulb','Switch'].includes(model.accessories?.[arguments[1]]?.type);"
131
+ },
132
+ "items": [
133
+ {
134
+ "type": "div",
135
+ "displayFlex": true,
136
+ "flex-direction": "row",
137
+ "items": [
138
+ {
139
+ "key": "accessories[].defaultOn",
140
+ "flex": "1 1 0"
141
+ },
142
+ {
143
+ "key": "accessories[].disableLogging",
144
+ "flex": "1 1 0"
145
+ }
146
+ ]
147
+ },
148
+ {
149
+ "key": "accessories[].defaultBrightness",
150
+ "flex": "1 1 0",
151
+ "condition": {
152
+ "functionBody": "return ['Lightbulb'].includes(model.accessories?.[arguments[1]]?.type);"
153
+ }
154
+ }
155
+ ]
156
+ }
157
+ ]
64
158
  }
159
+ ]
65
160
  }
66
- }
161
+ ]
162
+ }
@@ -0,0 +1,23 @@
1
+ import { PlatformAccessory, Service } from 'homebridge';
2
+ import { CharacteristicType, DummyAccessoryConfig, ServiceType } from '../model/types.js';
3
+ import { Log } from '../tools/log.js';
4
+ export declare abstract class DummyAccessory {
5
+ protected readonly Service: ServiceType;
6
+ protected readonly Characteristic: CharacteristicType;
7
+ protected readonly accessory: PlatformAccessory;
8
+ protected readonly config: DummyAccessoryConfig;
9
+ protected readonly log: Log;
10
+ protected readonly persistPath: string;
11
+ private readonly caller;
12
+ static identifier(config: DummyAccessoryConfig): string;
13
+ protected readonly accessoryService: Service;
14
+ private readonly timer;
15
+ constructor(Service: ServiceType, Characteristic: CharacteristicType, accessory: PlatformAccessory, config: DummyAccessoryConfig, log: Log, persistPath: string, caller: string);
16
+ protected abstract getAccessoryService(): Service;
17
+ teardown(): void;
18
+ protected get identifier(): string;
19
+ protected startTimer(callback: () => Promise<void>): void;
20
+ protected cancelTimer(): void;
21
+ protected assert(...keys: (keyof any)[]): boolean;
22
+ protected logIfDesired(message: string, ...parameters: string[]): void;
23
+ }
@@ -0,0 +1,69 @@
1
+ import { LEGACY_ALIAS, PLATFORM_NAME } from '../homebridge/settings.js';
2
+ import getVersion from '../tools/version.js';
3
+ import { Timer } from '../model/timer.js';
4
+ import { assert } from '../tools/validation.js';
5
+ export class DummyAccessory {
6
+ Service;
7
+ Characteristic;
8
+ accessory;
9
+ config;
10
+ log;
11
+ persistPath;
12
+ caller;
13
+ static identifier(config) {
14
+ if (config.legacy) {
15
+ return `${LEGACY_ALIAS}:${config.name}`;
16
+ }
17
+ ;
18
+ return `${PLATFORM_NAME}:${config.type}:${config.name.replace(/\s+/g, '')}`;
19
+ }
20
+ accessoryService;
21
+ timer;
22
+ constructor(Service, Characteristic, accessory, config, log, persistPath, caller) {
23
+ this.Service = Service;
24
+ this.Characteristic = Characteristic;
25
+ this.accessory = accessory;
26
+ this.config = config;
27
+ this.log = log;
28
+ this.persistPath = persistPath;
29
+ this.caller = caller;
30
+ this.timer = new Timer(config.name, config.disableLogging ? undefined : log);
31
+ accessory.getService(Service.AccessoryInformation)
32
+ .setCharacteristic(Characteristic.Name, config.name)
33
+ .setCharacteristic(Characteristic.ConfiguredName, config.name)
34
+ .setCharacteristic(Characteristic.Manufacturer, 'Homebridge')
35
+ .setCharacteristic(Characteristic.SerialNumber, accessory.UUID)
36
+ .setCharacteristic(Characteristic.Model, caller)
37
+ .setCharacteristic(Characteristic.FirmwareRevision, getVersion());
38
+ this.accessoryService = this.getAccessoryService();
39
+ }
40
+ teardown() {
41
+ this.timer.teardown();
42
+ }
43
+ get identifier() {
44
+ return DummyAccessory.identifier(this.config);
45
+ }
46
+ startTimer(callback) {
47
+ if (!this.config.timer?.delay) {
48
+ return;
49
+ }
50
+ if (!assert(this.log, this.caller, this.config.timer, 'units')) {
51
+ return;
52
+ }
53
+ this.timer.start(this.config.timer, callback);
54
+ }
55
+ cancelTimer() {
56
+ this.timer.cancel();
57
+ }
58
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
+ assert(...keys) {
60
+ return assert(this.log, this.config.name, this.config, ...keys);
61
+ }
62
+ logIfDesired(message, ...parameters) {
63
+ if (this.config.disableLogging) {
64
+ return;
65
+ }
66
+ this.log.always(message, ...parameters);
67
+ }
68
+ }
69
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/accessory/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EA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AI,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YAC/B,OAAO;QACT,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
2
+ import { OnOffAccessory } from './onoff.js';
3
+ import { CharacteristicType, LightbulbConfig, ServiceType } from '../model/types.js';
4
+ import { Log } from '../tools/log.js';
5
+ export declare class LightbulbAccessory extends OnOffAccessory {
6
+ private isDimmer;
7
+ private brightness;
8
+ constructor(Service: ServiceType, Characteristic: CharacteristicType, accessory: PlatformAccessory, lightbulbConfig: LightbulbConfig, log: Log, persistPath: string);
9
+ private get brightnessStorageKey();
10
+ private initializeBrightness;
11
+ protected getAccessoryService(): Service;
12
+ logOnState(value: CharacteristicValue): void;
13
+ protected getBrightness(): Promise<CharacteristicValue>;
14
+ protected setBrightness(value: CharacteristicValue): Promise<void>;
15
+ }