index ↓
hardware
client.hardware The display backlight and the ambient light sensor. displaySetMode and displaySetLevel drive
the backlight, and stateGet reads the current state.
requests
you ask, the daemon answers. await the tagged result and check .ok
stateGet(): Promise<TypedRequestResult<HardwareStateReply, never>>
push form: onStateReply (subscribe instead of awaiting)
const res = await client.hardware.stateGet();
if (res.ok) {
console.log(res.response.state);
} type Result =
| { ok: true; response: HardwareStateReply }
| { ok: false; kind: 'domain'; error: never }
| { ok: false; kind: 'protocol'; error: WireError }; commands
fire-and-forget. the promise resolves once the daemon has taken the message
displaySetMode(DisplaySetMode): Promise<void>
await client.hardware.displaySetMode({ mode: 'auto' }); displaySetLevel(DisplaySetLevel): Promise<void>
await client.hardware.displaySetLevel({ level: 0 }); events
the daemon pushes these unprompted. subscribing returns an unsubscribe function
onAmbientLightUpdate(handler: (AmbientLightUpdate) => void): () => void
const off = client.hardware.onAmbientLightUpdate((update) => {
console.log(update.ambientLevel);
});
// call off() to unsubscribe onBrightnessChanged(handler: (BrightnessState) => void): () => void
const off = client.hardware.onBrightnessChanged((state) => {
console.log(state.mode);
});
// call off() to unsubscribe types
shapes referenced above, as the sdk types them
Room brightness, 0 (dark) to 100 (bright).
type AmbientLightUpdate = {
ambientLevel: number;
}; type BrightnessState = {
mode: BrightnessMode;
level: number; // 0.0 to 1.0, as last set by `setLevel`.
effectiveLevel: number; // 0.0 to 1.0. Follows `level` in `manual` mode and the light sensor in `auto`.
}; type HardwareStateReply = {
state: HardwareState;
}; type DisplaySetMode = {
mode: BrightnessMode;
}; Call displaySetMode with manual first, or the level is ignored.
type DisplaySetLevel = {
level: number; // Backlight level, `0.0` (dimmest) to `1.0` (brightest).
}; type BrightnessMode =
| 'auto' // The device sets the backlight from its ambient light sensor.
| 'manual' // `setLevel` sets the backlight.; type HardwareState = {
brightness: BrightnessState;
ambientLevel: number; // 0 to 100.
};