nfarina / homebridge-dummy

Dummy switches for Homebridge: https://github.com/nfarina/homebridge
277 stars 83 forks source link

Add support for a dimmer/brightness option; including documentation. … #71

Closed justinmm2 closed 1 year ago

justinmm2 commented 1 year ago

I was thinking about this back in October, and finally got off my ass and did it tonight :) (This time I opted to set up an actual HB install on my desktop, instead of hand-editing files on my Synology docker container..)

I did my best to emulate your style where possible! I'm no HB guru, and happy to receive criticism. If this needs to be a separate plugin, that's fine, but I'm hoping this is a managable addition!

In short, I needed to add "Dimmer" and "Brightness" configuration options. "Dimmer" allows the user to make a dimmer instead of an on/off switch by using a Lightbulb Service; this allows storing values from 0 to 100 as the bulb's brightness. "Brightness" is simply a starting, default value; I wish I knew how to hide it from the config; I tried keywords like "hidden", but to no avail.

Because the brightness setting callback is an additional callback (only created when a dimmer is being used), it piggybacks off the existing _setOn(). Effectively, a dimmer (technically Lightbulb) has all the properties and callbacks of the normal dummy switch, but it also calls the _setBrightness() callback in order to set/store the brightness. Thus, if you set stateful = false, the dimmer will go back to 0% after the delay period; random delays still work, etc.

Cheers! J

justinmm2 commented 1 year ago

@nfarina Just wanted to ping this again now that it's been a few weeks (and we're mostly past the holidays!)

nfarina commented 1 year ago

Ah, thanks for pinging me about this, I don't know how this slipped off my radar!! This is a great suggestion and your implementation looks perfect. Happy to merge and will publish it now!