index ↓

hardware

client.hardware

The display backlight and the ambient light sensor. displaySetMode and displaySetLevel drive the backlight, stateGet reads the current state, and dimChanged reports dim settings a companion app changed.

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);
}

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

onDimChanged(handler: (DimSettings) => void): () => void

const off = client.hardware.onDimChanged((dimSettings) => {
  console.log(dimSettings.afterS);
});
// 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`.
  dimmed: boolean;
};

When the screen dims. A connected computer can also ask for a dim with hostState.away.

type DimSettings = {
  afterS?: number; // Seconds without input on the device or a connected computer, 15 to 86400. Null never dims.
  level: number; // `0.0` (dark) to `1.0`. Caps a manual level and scales an auto level.
};
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;
  dim: DimSettings;
  ambientLevel: number; // 0 to 100.
};