LightBulb
This service is rc and may change in the future.
A light bulb controller.
import { LightBulb } from "@devicescript/core"
const lightBulb = new LightBulb()
Registers
intensity
Indicates the brightness of the light bulb. Zero means completely off and 0xffff means completely on. For non-dimmable lights, the value should be clamp to 0xffff for any non-zero value.
type:
Register<number>
(packing formatu0.16
)read and write
import { LightBulb } from "@devicescript/core"
const lightBulb = new LightBulb()
// ...
const value = await lightBulb.intensity.read()
await lightBulb.intensity.write(value)
- track incoming values
import { LightBulb } from "@devicescript/core"
const lightBulb = new LightBulb()
// ...
lightBulb.intensity.subscribe(async (value) => {
...
})
write
and read
will block until a server is bound to the client.
dimmable
Indicates if the light supports dimming.
type:
Register<boolean>
(packing formatu8
)optional: this register may not be implemented
constant: the register value will not change (until the next reset)
read only
import { LightBulb } from "@devicescript/core"
const lightBulb = new LightBulb()
// ...
const value = await lightBulb.dimmable.read()
write
and read
will block until a server is bound to the client.
on
Turns on of the light bulb with an optional intensity value.
import { LightBulb } from "@devicescript/core"
const lightBulb = new LightBulb()
await lightBulb.on(0.5)
off
Turns off of the light bulb, same as writing 0 to the intensity register.
import { LightBulb } from "@devicescript/core"
const lightBulb = new LightBulb()
await lightBulb.off()
toggle
The toggle method flips the brightness state.
import { LightBulb } from "@devicescript/core"
const lightBulb = new LightBulb()
await lightBulb.toggle()