Sensor
sensor
sensor domain implementation (read-only).
SPEC
module-attribute
SPEC: DomainSpec[Sensor] = register_domain(DomainSpec(name='sensor', entity_cls=Sensor))
The DomainSpec registered with the shared DomainRegistry.
Sensor
Bases: Entity
A read-only Home Assistant sensor entity.
Exposes the sensor's value, unit of measurement, and device class.
The value property automatically coerces numeric state strings
to float.
Source code in src/haclient/domains/sensor.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
unit_of_measurement
property
unit_of_measurement: str | None
Unit of the sensor value, if provided.
device_class
property
device_class: str | None
Device class (e.g. "temperature").
value
property
value: float | str | None
Sensor value coerced to float if numeric.
Returns:
| Type | Description |
|---|---|
float or str or None
|
|
on_value_change
on_value_change(func: ValueChangeHandler) -> ValueChangeHandler
Register a listener for sensor value changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
Sync or async callable invoked with the previous and current
sensor state strings as |
required |
Returns:
| Type | Description |
|---|---|
callable
|
The same func, returned for decorator use. |
Source code in src/haclient/domains/sensor.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |