Skip to content

@camera.ui/sdk / sensor / BatteryInfo

Class: BatteryInfo<TStorage> ​

Defined in: sensor/battery.ts:62

Battery info sensor. Reports battery level, charging state, and low-battery alerts.

Plugin authors call setLevel(value), setCharging(state), and setLow(value) to push updates from the device.

Extends ​

Type Parameters ​

TStorage ​

TStorage extends object = Record<string, any>

Constructors ​

Constructor ​

new BatteryInfo<TStorage>(name?, options?): BatteryInfo<TStorage>

Defined in: sensor/battery.ts:66

Parameters ​

name? ​

string = 'Battery'

options? ​

SensorOptions

Returns ​

BatteryInfo<TStorage>

Overrides ​

Sensor.constructor

Properties ​

category ​

readonly category: Info = SensorCategory.Info

Defined in: sensor/battery.ts:64

Overrides ​

Sensor.category


name ​

readonly name: string

Defined in: sensor/base.ts:238

Inherited from ​

Sensor.name


onAssignmentChanged ​

readonly onAssignmentChanged: Observable<readonly string[]>

Defined in: sensor/base.ts:266

Inherited from ​

Sensor.onAssignmentChanged


onCapabilitiesChanged ​

readonly onCapabilitiesChanged: Observable<BatteryCapability[]>

Defined in: sensor/base.ts:258

Inherited from ​

Sensor.onCapabilitiesChanged


onConnectedChanged ​

readonly onConnectedChanged: Observable<boolean>

Defined in: sensor/base.ts:268

Inherited from ​

Sensor.onConnectedChanged


onPropertyChanged ​

readonly onPropertyChanged: Observable<PropertyChangeOf<BatteryInfoProperties>>

Defined in: sensor/base.ts:256

Inherited from ​

Sensor.onPropertyChanged


type ​

readonly type: Battery = SensorType.Battery

Defined in: sensor/battery.ts:63

Overrides ​

Sensor.type

Accessors ​

address ​

Get Signature ​

get address(): string | undefined

Defined in: sensor/base.ts:300

Returns ​

string | undefined

Inherited from ​

VibrationSensor.address


assignedCameraIds ​

Get Signature ​

get assignedCameraIds(): readonly string[]

Defined in: sensor/base.ts:316

Returns ​

readonly string[]

Inherited from ​

Sensor.assignedCameraIds


assignmentLocked ​

Get Signature ​

get assignmentLocked(): boolean

Defined in: sensor/base.ts:320

Returns ​

boolean

Inherited from ​

Sensor.assignmentLocked


capabilities ​

Get Signature ​

get capabilities(): TCapability[]

Defined in: sensor/base.ts:339

Returns ​

TCapability[]

Set Signature ​

set capabilities(value): void

Defined in: sensor/base.ts:344

Set capabilities, deduplicated, and notify backend plus local listeners.

Parameters ​
value ​

TCapability[]

Returns ​

void

Inherited from ​

Sensor.capabilities


charging ​

Get Signature ​

get charging(): ChargingState

Defined in: sensor/battery.ts:80

Returns ​

ChargingState


connected ​

Get Signature ​

get connected(): boolean

Defined in: sensor/base.ts:312

Returns ​

boolean

Inherited from ​

Sensor.connected


displayName ​

Get Signature ​

get displayName(): string

Defined in: sensor/base.ts:304

Returns ​

string

Inherited from ​

Sensor.displayName


id ​

Get Signature ​

get id(): string

Defined in: sensor/base.ts:284

Returns ​

string

Inherited from ​

Sensor.id


isAssigned ​

Get Signature ​

get isAssigned(): boolean

Defined in: sensor/base.ts:308

Returns ​

boolean

Inherited from ​

VibrationSensor.isAssigned


level ​

Get Signature ​

get level(): number

Defined in: sensor/battery.ts:76

Returns ​

number


low ​

Get Signature ​

get low(): boolean

Defined in: sensor/battery.ts:84

Returns ​

boolean


nativeId ​

Get Signature ​

get nativeId(): string | undefined

Defined in: sensor/base.ts:288

Returns ​

string | undefined

Inherited from ​

Sensor.nativeId


origin ​

Get Signature ​

get origin(): string | undefined

Defined in: sensor/base.ts:292

Returns ​

string | undefined

Inherited from ​

VibrationSensor.origin


pluginId ​

Get Signature ​

get pluginId(): string | undefined

Defined in: sensor/base.ts:324

Returns ​

string | undefined

Inherited from ​

Sensor.pluginId


props ​

Get Signature ​

get protected props(): Readonly<TProperties>

Defined in: sensor/base.ts:558

Returns ​

Readonly<TProperties>

Inherited from ​

Sensor.props


sourceState ​

Get Signature ​

get sourceState(): SensorSourceState | undefined

Defined in: sensor/base.ts:296

Returns ​

SensorSourceState | undefined

Inherited from ​

VibrationSensor.sourceState


storage ​

Get Signature ​

get storage(): DeviceStorage<TStorage>

Defined in: sensor/base.ts:328

Returns ​

DeviceStorage<TStorage>

Inherited from ​

Sensor.storage


storageSchema ​

Get Signature ​

get storageSchema(): JsonSchema[]

Defined in: sensor/base.ts:335

Returns ​

JsonSchema[]

Inherited from ​

VibrationSensor.storageSchema

Methods ​

getValue() ​

Call Signature ​

getValue<K>(property): BatteryInfoProperties[K] | undefined

Defined in: sensor/base.ts:368

Get the current value of a sensor property. Calling the generic overload with a property enum value gives a properly typed result.

Type Parameters ​
K ​

K extends keyof BatteryInfoProperties

Parameters ​
property ​

K

Returns ​

BatteryInfoProperties[K] | undefined

Inherited from ​

Sensor.getValue

Call Signature ​

getValue(property): unknown

Defined in: sensor/base.ts:369

Get the current value of a sensor property. Calling the generic overload with a property enum value gives a properly typed result.

Parameters ​
property ​

string

Returns ​

unknown

Inherited from ​

Sensor.getValue


getValues() ​

getValues(): Readonly<TProperties>

Defined in: sensor/base.ts:385

Get a read-only snapshot of all property values.

Returns ​

Readonly<TProperties>

Shallow copy of every property currently held by the sensor.

Example ​

ts
const snapshot = sensor.getValues();
console.log(snapshot);

Inherited from ​

Sensor.getValues


hasCapability() ​

hasCapability(capability): boolean

Defined in: sensor/base.ts:411

Check whether the sensor advertises a capability.

Parameters ​

capability ​

string

Capability flag to look for.

Returns ​

boolean

True if the sensor currently advertises it.

Example ​

ts
const dimmable = sensor.hasCapability('brightness');

Inherited from ​

Sensor.hasCapability


onStart() ​

protected onStart(): void | Promise<void>

Defined in: sensor/base.ts:647

Lifecycle hook, called once the sensor is registered and live (storage and RPC are wired up). Override it to start work whose lifetime matches the sensor's: polling loops, event subscriptions, timers.

Errors thrown here are swallowed, not logged. Handle failures inside the override. Paired 1:1 with onStop, which runs on removal, plugin shutdown or cleanup.

Returns ​

void | Promise<void>

Example ​

ts
protected override onStart(): void {
  this._timer = setInterval(() => this.poll(), 5_000);
}

Inherited from ​

Sensor.onStart


onStop() ​

protected onStop(): void | Promise<void>

Defined in: sensor/base.ts:660

Counterpart of onStart: tear down whatever it started, such as timers, subscriptions and external resources.

Returns ​

void | Promise<void>

Example ​

ts
protected override onStop(): void {
  if (this._timer) clearInterval(this._timer);
}

Inherited from ​

Sensor.onStop


setAddress() ​

setAddress(address): void

Defined in: sensor/base.ts:444

Report the sensor's current address at the source, e.g. after a Home Assistant entity was renamed. The identity (nativeId) stays.

Parameters ​

address ​

string

Current address at the source

Returns ​

void

Example ​

typescript
sensor.setAddress(entry.entity_id);

Inherited from ​

Sensor.setAddress


setCharging() ​

setCharging(value): void

Defined in: sensor/battery.ts:113

Report the current charging state.

Parameters ​

value ​

ChargingState

Current charging state from the ChargingState enum.

Returns ​

void

Example ​

ts
import { ChargingState } from '@camera.ui/sdk';
battery.setCharging(ChargingState.Charging);

setDisplayName() ​

setDisplayName(value): void

Defined in: sensor/base.ts:360

Set the display name (the only mutable identifier on a sensor).

Parameters ​

value ​

string

Human-readable label shown in the UI.

Returns ​

void

Example ​

ts
sensor.setDisplayName('Front Door Motion');

Inherited from ​

Sensor.setDisplayName


setLevel() ​

setLevel(value): void

Defined in: sensor/battery.ts:98

Report a new battery level (percentage). Clamped to [0, 100].

Parameters ​

value ​

number

Battery level percentage in the range 0-100.

Returns ​

void

Example ​

ts
battery.setLevel(87);

setLow() ​

setLow(value): void

Defined in: sensor/battery.ts:127

Report whether the battery is critically low.

Parameters ​

value ​

boolean

True when the battery has crossed the low-battery threshold.

Returns ​

void

Example ​

ts
battery.setLow(true);

setSourceState() ​

setSourceState(state): void

Defined in: sensor/base.ts:427

Report what the source behind this sensor looks like right now. The host shows the state with its reason on the sensors page and never deletes on it. Only meaningful for adopted sensors.

Parameters ​

state ​

SensorSourceState

Current source state

Returns ​

void

Example ​

typescript
sensor.setSourceState(registryHasEntity ? 'connected' : 'removed');

Inherited from ​

Sensor.setSourceState


updateModelSpec() ​

updateModelSpec(): void

Defined in: sensor/base.ts:577

Re-announces the model spec, e.g. once the models finished loading.

The spec a detector reports at registration is what it knows at that moment: models that load in the background are missing from it. Call this after loading, the server replaces its copy.

Returns ​

void

Example ​

typescript
async onStart(): Promise<void> {
  await this.loadModel();
  this.updateModelSpec();
}

Inherited from ​

Sensor.updateModelSpec