@camera.ui/sdk / sensor / ValveControl
Class: ValveControl<TStorage> ​
Defined in: sensor/valve.ts:123
A water or gas valve, or an irrigation zone. Override setTargetState(), setTargetPosition() and setDuration() to drive hardware and call the super method after success to sync the SDK state. Report what the hardware does with setCurrentState(), setCurrentPosition() and setRemaining().
A valve that opens part way adds ValveCapability.Position, one that closes by itself after a set time ValveCapability.Duration. setKind() says what the valve controls, index in the options orders the zones of one irrigation controller.
When the device refuses a command, throw from the override instead of calling super: the write fails for whoever sent it and the state stays as it was.
Example ​
class Zone extends ValveControl {
constructor(zone: number) {
super(`Zone ${zone}`, { index: zone });
this.setKind(ValveKind.Irrigation);
this.capabilities = [ValveCapability.Duration];
}
override async setTargetState(value: ValveState): Promise<void> {
await controller.run(this.index, value === ValveState.Open ? this.duration : 0);
await super.setTargetState(value);
}
}Extends ​
Sensor<ValveControlProperties,TStorage,ValveCapability>
Type Parameters ​
TStorage ​
TStorage extends object = Record<string, any>
Constructors ​
Constructor ​
new ValveControl<
TStorage>(name?,options?):ValveControl<TStorage>
Defined in: sensor/valve.ts:127
Parameters ​
name? ​
string = 'Valve'
options? ​
Returns ​
ValveControl<TStorage>
Overrides ​
Properties ​
category ​
readonlycategory:Control=SensorCategory.Control
Defined in: sensor/valve.ts:125
Category of the sensor: detection sensor, control, trigger or info.
Overrides ​
name ​
readonlyname:string
Defined in: sensor/base.ts:406
Name the plugin gave the sensor.
Inherited from ​
onAssignmentChanged ​
readonlyonAssignmentChanged:Observable<readonlystring[]>
Defined in: sensor/base.ts:440
Emits the camera id list whenever the user changes the sensor's camera assignments.
Inherited from ​
onCapabilitiesChanged ​
readonlyonCapabilitiesChanged:Observable<ValveCapability[]>
Defined in: sensor/base.ts:432
Emits the full capability list whenever it changes.
Inherited from ​
onConnectedChanged ​
readonlyonConnectedChanged:Observable<boolean>
Defined in: sensor/base.ts:442
Emits when the connected state changes.
Inherited from ​
onDeviceInfoChanged ​
readonlyonDeviceInfoChanged:Observable<SensorDevice|undefined>
Defined in: sensor/base.ts:446
Emits the device whenever the sensor joins or leaves one, or its device, names or main-sensor role change.
Inherited from ​
onPropertyChanged ​
readonlyonPropertyChanged:Observable<PropertyChangeOf<ValveControlProperties>>
Defined in: sensor/base.ts:430
Emits on every property change.
Inherited from ​
onPropertySpecsChanged ​
readonlyonPropertySpecsChanged:Observable<Readonly<Record<string,SensorPropertySpec>>>
Defined in: sensor/base.ts:448
Emits the property specs whenever the plugin changes them.
Inherited from ​
onSourceStateChanged ​
readonlyonSourceStateChanged:Observable<SensorSourceState|undefined>
Defined in: sensor/base.ts:444
Emits when the source state changes.
Inherited from ​
type ​
readonlytype:Valve=SensorType.Valve
Defined in: sensor/valve.ts:124
Type of the sensor, fixed per sensor class.
Overrides ​
Accessors ​
address ​
Get Signature ​
get address():
string|undefined
Defined in: sensor/base.ts:487
Current address at the source, e.g. a Home Assistant entity id. Display only.
Returns ​
string | undefined
Inherited from ​
assignedCameraIds ​
Get Signature ​
get assignedCameraIds(): readonly
string[]
Defined in: sensor/base.ts:520
Ids of the cameras the user assigned the sensor to.
Returns ​
readonly string[]
Ids of the cameras the user assigned the sensor to.
Inherited from ​
assignmentLocked ​
Get Signature ​
get assignmentLocked():
boolean
Defined in: sensor/base.ts:524
Whether the sensor is bound to the camera it was added to, so the user cannot assign it elsewhere.
Returns ​
boolean
Whether the sensor is bound to the camera it was added to, so the user cannot assign it elsewhere.
Inherited from ​
capabilities ​
Get Signature ​
get capabilities():
TCapability[]
Defined in: sensor/base.ts:545
Capabilities the sensor advertises.
Returns ​
TCapability[]
Set Signature ​
set capabilities(
value):void
Defined in: sensor/base.ts:550
Set capabilities, deduplicated, and notify backend plus local listeners.
Parameters ​
value ​
TCapability[]
Returns ​
void
Capabilities the sensor advertises.
Inherited from ​
connected ​
Get Signature ​
get connected():
boolean
Defined in: sensor/base.ts:516
Whether the sensor is registered and its plugin is connected.
Returns ​
boolean
Whether the sensor is registered and its plugin is connected.
Inherited from ​
currentPosition ​
Get Signature ​
get currentPosition():
number
Defined in: sensor/valve.ts:152
Current position, 0 (closed) to 100 (open).
Returns ​
number
currentState ​
Get Signature ​
get currentState():
ValveState
Defined in: sensor/valve.ts:142
Current state, a ValveState.
Returns ​
deviceInfo ​
Get Signature ​
get deviceInfo():
SensorDevice|undefined
Defined in: sensor/base.ts:499
Device the sensor belongs to, undefined without one and for a camera's own sensor.
Returns ​
SensorDevice | undefined
Device the sensor belongs to, undefined without one and for a camera's own sensor.
Inherited from ​
displayName ​
Get Signature ​
get displayName():
string
Defined in: sensor/base.ts:491
Full name shown to the user: inside a device the device name plus shortName, otherwise the plugin's name until the user renames the sensor.
Returns ​
string
Full name shown to the user: inside a device the device name plus shortName, otherwise the plugin's name until the user renames the sensor.
Inherited from ​
duration ​
Get Signature ​
get duration():
number
Defined in: sensor/valve.ts:162
Seconds the valve stays open before it closes by itself.
Returns ​
number
id ​
Get Signature ​
get id():
string
Defined in: sensor/base.ts:468
Entity id of the sensor, provisional on a new sensor until registration.
Returns ​
string
Entity id of the sensor, provisional on a new sensor until registration.
Inherited from ​
index ​
Get Signature ​
get index():
number
Defined in: sensor/valve.ts:177
Position of the valve on its device, from 1, 0 when not set.
Returns ​
number
isAssigned ​
Get Signature ​
get isAssigned():
boolean
Defined in: sensor/base.ts:512
Whether the sensor is assigned to at least one camera.
Returns ​
boolean
Inherited from ​
kind ​
Get Signature ​
get kind():
ValveKind|undefined
Defined in: sensor/valve.ts:172
What the valve controls, a ValveKind.
Returns ​
ValveKind | undefined
nativeId ​
Get Signature ​
get nativeId():
string|undefined
Defined in: sensor/base.ts:472
Durable identity the plugin supplied, e.g. an upstream device id.
Returns ​
string | undefined
Durable identity the plugin supplied, e.g. an upstream device id.
Inherited from ​
origin ​
Get Signature ​
get origin():
string|undefined
Defined in: sensor/base.ts:477
Source system the sensor was imported from, e.g. 'homeassistant'.
Returns ​
string | undefined
Inherited from ​
pluginId ​
Get Signature ​
get pluginId():
string|undefined
Defined in: sensor/base.ts:528
Id of the plugin that owns the sensor, set at registration.
Returns ​
string | undefined
Id of the plugin that owns the sensor, set at registration.
Inherited from ​
primary ​
Get Signature ​
get primary():
boolean
Defined in: sensor/base.ts:503
Whether the sensor is the main sensor of its device, called like the device when it stands alone.
Returns ​
boolean
Whether the sensor is the main sensor of its device, called like the device when it stands alone.
Inherited from ​
propertySpecs ​
Get Signature ​
get propertySpecs():
Readonly<Record<string,SensorPropertySpec>>
Defined in: sensor/base.ts:507
Specs of the properties the plugin narrowed or described, resolved against the type's. A property without an entry follows its type's spec.
Returns ​
Readonly<Record<string, SensorPropertySpec>>
Specs of the properties the plugin narrowed or described, resolved against the type's. A property without an entry follows its type's spec.
Inherited from ​
props ​
Get Signature ​
get
protectedprops():Readonly<TProperties>
Defined in: sensor/base.ts:856
Read-only view of the property values.
Returns ​
Readonly<TProperties>
Inherited from ​
remaining ​
Get Signature ​
get remaining():
number
Defined in: sensor/valve.ts:167
Seconds left until the open valve closes by itself.
Returns ​
number
shortName ​
Get Signature ​
get shortName():
string
Defined in: sensor/base.ts:495
Name inside its device, the same as displayName for a sensor without a device.
Returns ​
string
Name inside its device, the same as displayName for a sensor without a device.
Inherited from ​
sourceState ​
Get Signature ​
get sourceState():
SensorSourceState|undefined
Defined in: sensor/base.ts:482
State of the source behind an adopted sensor, as reported with setSourceState().
Returns ​
SensorSourceState | undefined
State of the source behind the sensor. Seen from another plugin it is also unavailable while the camera the sensor belongs to is offline. A sensor that is unavailable or removed takes no writes.
Inherited from ​
storage ​
Get Signature ​
get storage():
DeviceStorage<TStorage>
Defined in: sensor/base.ts:533
Per-sensor storage. Throws before registration.
Returns ​
DeviceStorage<TStorage>
Inherited from ​
storageSchema ​
Get Signature ​
get storageSchema():
JsonSchema[]
Defined in: sensor/base.ts:541
JSON schema of the per-sensor settings. Override it to get a settings UI.
Returns ​
Inherited from ​
targetPosition ​
Get Signature ​
get targetPosition():
number
Defined in: sensor/valve.ts:157
Target position, 0 (closed) to 100 (open).
Returns ​
number
targetState ​
Get Signature ​
get targetState():
ValveState
Defined in: sensor/valve.ts:147
Target state, Open or Closed.
Returns ​
Methods ​
getValue() ​
Call Signature ​
getValue<
K>(property):ValveControlProperties[K] |undefined
Defined in: sensor/base.ts:574
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 ValveControlProperties
Parameters ​
property ​
K
Returns ​
ValveControlProperties[K] | undefined
Inherited from ​
Call Signature ​
getValue(
property):unknown
Defined in: sensor/base.ts:575
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 ​
getValues() ​
getValues():
Readonly<TProperties>
Defined in: sensor/base.ts:591
Get a read-only snapshot of all property values.
Returns ​
Readonly<TProperties>
Shallow copy of every property currently held by the sensor.
Example ​
const snapshot = sensor.getValues();
console.log(snapshot);Inherited from ​
hasCapability() ​
hasCapability(
capability):boolean
Defined in: sensor/base.ts:634
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 ​
const dimmable = sensor.hasCapability('brightness');Inherited from ​
onStart() ​
protectedonStart():void|Promise<void>
Defined in: sensor/base.ts:953
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 ​
protected override onStart(): void {
this._timer = setInterval(() => this.poll(), 5_000);
}Inherited from ​
onStop() ​
protectedonStop():void|Promise<void>
Defined in: sensor/base.ts:966
Counterpart of onStart: tear down whatever it started, such as timers, subscriptions and external resources.
Returns ​
void | Promise<void>
Example ​
protected override onStop(): void {
if (this._timer) clearInterval(this._timer);
}Inherited from ​
setAddress() ​
setAddress(
address):void
Defined in: sensor/base.ts:669
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 ​
sensor.setAddress(entry.entity_id);Inherited from ​
setCurrentPosition() ​
setCurrentPosition(
position):void
Defined in: sensor/valve.ts:236
Report the position of the valve.
Parameters ​
position ​
number
0 (closed) to 100 (open).
Returns ​
void
Example ​
valve.setCurrentPosition(30);setCurrentState() ​
setCurrentState(
value):void
Defined in: sensor/valve.ts:206
Report the state of the valve.
Parameters ​
value ​
What the valve does right now.
Returns ​
void
Example ​
valve.setCurrentState(ValveState.Opening);setDeviceInfo() ​
setDeviceInfo(
device,options?):void
Defined in: sensor/base.ts:692
Put the sensor into a device, or take it out with undefined. Sensors of this plugin that report the same DeviceInfo.id form one device. Pass the device in the constructor options when it is known there, call this for what changes later: a new firmware, a rename at the source. Only a change reaches the host. Ignored for a sensor added with camera.addSensor(), its camera is its device.
Parameters ​
device ​
DeviceInfo | undefined
Device at the source, undefined to take the sensor out of its device
options? ​
Whether this sensor is the device's main sensor
Returns ​
void
Example ​
sensor.setDeviceInfo({ id: hub.serial, name: hub.name, manufacturer: 'Acme', firmware: hub.version }, { primary: true });Inherited from ​
setDisplayName() ​
setDisplayName(
value):void
Defined in: sensor/base.ts:566
Set the display name (the only mutable identifier on a sensor).
Parameters ​
value ​
string
Human-readable label shown in the UI.
Returns ​
void
Example ​
sensor.setDisplayName('Front Door Motion');Inherited from ​
setDuration() ​
setDuration(
seconds):Promise<void>
Defined in: sensor/valve.ts:251
Set how long the valve stays open. Override to drive hardware and call await super.setDuration(seconds) after success to sync the SDK state.
Parameters ​
seconds ​
number
Seconds until the open valve closes by itself.
Returns ​
Promise<void>
Example ​
await valve.setDuration(900);setKind() ​
setKind(
kind):void
Defined in: sensor/valve.ts:280
Say what the valve controls. Smart homes show it by its kind, and Home Assistant takes it as the device class.
Parameters ​
kind ​
What the valve controls.
Returns ​
void
Example ​
valve.setKind(ValveKind.Gas);setPropertySpec() ​
setPropertySpec<
K>(property,spec):void
Defined in: sensor/base.ts:717
Narrow or describe one property for this device: a range and step, the enum values it supports, the choices it offers with their names, a text limit. The host rejects a command outside it before it reaches the plugin. Pass it in the constructor options when it is known there, call this for what changes later. Only a change reaches the host.
Type Parameters ​
K ​
K extends ValveProperty
Parameters ​
property ​
K
Property to describe
spec ​
PropertySpecOverride | undefined
What the device accepts, undefined to follow the type's spec again
Returns ​
void
Example ​
alarm.setPropertySpec(SecuritySystemProperty.TargetState, {
values: [SecuritySystemState.AwayArm, SecuritySystemState.StayArm, SecuritySystemState.Disarmed],
});Inherited from ​
setRemaining() ​
setRemaining(
seconds):void
Defined in: sensor/valve.ts:265
Report how long the open valve has left.
Parameters ​
seconds ​
number
Seconds until it closes by itself, 0 when closed.
Returns ​
void
Example ​
valve.setRemaining(420);setSourceState() ​
setSourceState(
state):void
Defined in: sensor/base.ts:651
Report what the source behind this sensor looks like right now, for example unavailable while the device can't be reached. The host shows the state with its reason on the sensors page and never deletes on it. While it is unavailable or removed the sensor takes no writes.
Parameters ​
state ​
Current source state
Returns ​
void
Example ​
sensor.setSourceState(registryHasEntity ? 'connected' : 'removed');Inherited from ​
setTargetPosition() ​
setTargetPosition(
position):Promise<void>
Defined in: sensor/valve.ts:221
Open the valve to a position. Override to drive hardware and call await super.setTargetPosition(position) after success to sync the SDK state.
Parameters ​
position ​
number
0 (closed) to 100 (open).
Returns ​
Promise<void>
Example ​
await valve.setTargetPosition(50);setTargetState() ​
setTargetState(
value):Promise<void>
Defined in: sensor/valve.ts:192
Open or close the valve. Override to drive hardware and call await super.setTargetState(value) after success to sync the SDK state.
Parameters ​
value ​
ValveState.Open or ValveState.Closed.
Returns ​
Promise<void>
Example ​
await valve.setTargetState(ValveState.Open);updateModelSpec() ​
updateModelSpec():
void
Defined in: sensor/base.ts:875
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 ​
async onStart(): Promise<void> {
await this.loadModel();
this.updateModelSpec();
}Inherited from ​
updateValue() ​
updateValue(
property,value):Promise<void>
Defined in: sensor/base.ts:617
Generic property write coming from a consumer. Control sensors dispatch it to their semantic methods (setOn, setActive, setTargetState), so plugin overrides drive the hardware. Writes run one at a time per sensor in arrival order, a newer value of a property replaces one still waiting, a command always runs. Unknown or non-writable properties are ignored.
Plugin authors call the semantic methods on the concrete class instead.
Parameters ​
property ​
string
Property to write.
value ​
unknown
Value to write.
Returns ​
Promise<void>
Resolves once the device took the value, rejects with the setter's error, when nothing answered within 10 seconds or while the source is unavailable or removed.
Example ​
await light.updateValue(LightProperty.Brightness, 80);