Skip to content

@camera.ui/sdk / sensor / Sensor

Abstract Class: Sensor<TProperties, TStorage, TCapability>

Defined in: sensor/base.ts:185

Abstract base class for all sensors. Plugins extend this (or use specialized subclasses like MotionSensor, LightControl, etc.) to implement sensor logic.

Properties are managed through a reactive proxy — setting a property via this.props automatically notifies the backend and local listeners if the value changed.

Extended by

Type Parameters

TProperties

TProperties extends object

Sensor-specific property interface (e.g., MotionSensorProperties)

TStorage

TStorage extends object = Record<string, any>

Persistent storage schema for per-sensor config

TCapability

TCapability extends string = string

Capability enum type (e.g., PTZCapability)

Implements

Constructors

Constructor

new Sensor<TProperties, TStorage, TCapability>(name): Sensor<TProperties, TStorage, TCapability>

Defined in: sensor/base.ts:225

Parameters

name

string

Returns

Sensor<TProperties, TStorage, TCapability>

Properties

_requiresFrames?

optional _requiresFrames?: boolean

Defined in: sensor/base.ts:223


category

abstract readonly category: SensorCategory

Defined in: sensor/base.ts:187


id

readonly id: string

Defined in: sensor/base.ts:190

Implementation of

SensorLike.id


name

readonly name: string

Defined in: sensor/base.ts:189

Implementation of

SensorLike.name


onAssignmentChanged

readonly onAssignmentChanged: Observable<boolean>

Defined in: sensor/base.ts:209


onCapabilitiesChanged

readonly onCapabilitiesChanged: Observable<TCapability[]>

Defined in: sensor/base.ts:200

Observable for capability changes. Emits the full capabilities array when capabilities change.

Implementation of

SensorLike.onCapabilitiesChanged


onPropertyChanged

readonly onPropertyChanged: Observable<PropertyChangeOf<TProperties>>

Defined in: sensor/base.ts:198

Observable for property changes. Emits { property, value, timestamp } when any property changes.

Implementation of

SensorLike.onPropertyChanged


type

abstract readonly type: SensorType

Defined in: sensor/base.ts:186

Implementation of

SensorLike.type

Accessors

cameraId

Get Signature

get cameraId(): string

Defined in: sensor/base.ts:257

Camera ID this sensor belongs to. Throws if sensor not yet added to a camera.

Returns

string


capabilities

Get Signature

get capabilities(): TCapability[]

Defined in: sensor/base.ts:277

Optional feature flags advertised by this sensor (e.g., PTZ pan/tilt/zoom)

Returns

TCapability[]

Set Signature

set capabilities(value): void

Defined in: sensor/base.ts:282

Set capabilities and notify the backend. Automatically deduplicates.

Parameters
value

TCapability[]

Returns

void

Implementation of

SensorLike.capabilities


displayName

Get Signature

get displayName(): string

Defined in: sensor/base.ts:233

Returns

string

Implementation of

SensorLike.displayName


isAssigned

Get Signature

get isAssigned(): boolean

Defined in: sensor/base.ts:252

Whether this sensor has been assigned to a camera in the backend

Returns

boolean


pluginId

Get Signature

get pluginId(): string | undefined

Defined in: sensor/base.ts:264

Returns

string | undefined

Implementation of

SensorLike.pluginId


props

Get Signature

get protected props(): Readonly<TProperties>

Defined in: sensor/base.ts:295

Read-only access to the internal property store. Subclasses use this to read current state when implementing semantic methods (e.g., if (this.blocked) return).

Returns

Readonly<TProperties>


storage

Get Signature

get storage(): DeviceStorage<TStorage>

Defined in: sensor/base.ts:269

Per-sensor persistent storage. Throws if sensor not yet added to a camera.

Returns

DeviceStorage<TStorage>


storageSchema

Get Signature

get storageSchema(): JsonSchema[]

Defined in: sensor/base.ts:216

Override to provide a JSON schema for per-sensor storage settings UI

Returns

JsonSchema[]

Methods

getValue()

Call Signature

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

Defined in: sensor/base.ts:303

Get the current value of a sensor property. Type-safe via the generic overload — call with a property enum value to get a properly typed result.

Type Parameters
K

K extends string | number | symbol

Parameters
property

K

Returns

TProperties[K] | undefined

Implementation of

SensorLike.getValue

Call Signature

getValue(property): unknown

Defined in: sensor/base.ts:304

Get the current value of a sensor property. Type-safe via the generic overload — call with a property enum value to get a properly typed result.

Parameters
property

string

Returns

unknown

Implementation of

SensorLike.getValue


getValues()

getValues(): Readonly<TProperties>

Defined in: sensor/base.ts:320

Get a read-only snapshot of all property values.

Returns

Readonly<TProperties>

Frozen view of every property currently held by the sensor.

Example

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

Implementation of

SensorLike.getValues


hasCapability()

hasCapability(capability): boolean

Defined in: sensor/base.ts:423

Parameters

capability

string

Returns

boolean

Implementation of

SensorLike.hasCapability


onAssigned()

protected onAssigned(): void | Promise<void>

Defined in: sensor/base.ts:473

Lifecycle hook: the sensor just became assigned to a camera. Override to start background work that should only run while this sensor is live — polling loops, event subscriptions, timers, external connections.

Called AFTER cameraId, storage, and RPC channels are wired up, so the override can safely access this.cameraId, this.storage, and publish properties via the semantic helper methods.

Errors thrown here are caught and logged — they will NOT break assignment bookkeeping. If your work can fail, handle it inside the override.

Paired 1:1 with onDeassigned — for every onAssigned call there is exactly one matching onDeassigned later (on deassignment or cleanup).

Default: no-op. Most sensors don't need lifecycle hooks.

Returns

void | Promise<void>

Example

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

onDeassigned()

protected onDeassigned(): void | Promise<void>

Defined in: sensor/base.ts:493

Lifecycle hook: the sensor is being deassigned. Override to tear down whatever was started in onAssigned — clear timers, close subscriptions, release external resources.

Always called exactly once for each prior onAssigned. Also called from _cleanup if the sensor is being removed while still assigned, so you can rely on this as the single teardown point.

Default: no-op.

Returns

void | Promise<void>

Example

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

setDisplayName()

setDisplayName(value): void

Defined in: sensor/base.ts:247

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

updateValue()

abstract updateValue(property, value): void | Promise<void>

Defined in: sensor/base.ts:335

External-consumer entry point that satisfies the SensorLike.updateValue contract. Each concrete sensor class implements this — read-only sensors leave it as a no-op, control sensors dispatch known properties to the appropriate semantic methods (setOn, setActive, setTargetState, etc.) so plugin overrides drive hardware. Unknown / non-writable properties are silently ignored.

Plugin authors must not call this — they should call the semantic methods directly on the concrete sensor class.

Parameters

property

string

value

unknown

Returns

void | Promise<void>

Implementation of

SensorLike.updateValue