Unit
Base unit module defining the Unit class.
A Unit represents a physical entity (plant or greenhouse) that has sensors attached to it and optionally actuators. Units are the primary organizational abstraction: each unit has its own database namespace and sensor set.
Unit
¶
Bases: HasSetupFunctionsMixin
A physical unit with attached sensors and optional actuation.
This is the base class for Plant and Greenhouse. It manages sensor registration, the sensing loop, and database persistence.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Unique identifier for this unit (used as DB namespace). |
|
db_client |
Database client for persisting measurements. |
|
sensors |
List of registered Sensor instances. |
Source code in pt/controller_3/src/plant_controller/unit.py
__init__(name, db_client)
¶
Initialize the unit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique name identifying this unit. |
required |
db_client
|
DatabaseClient
|
Database client for measurement persistence. |
required |
Source code in pt/controller_3/src/plant_controller/unit.py
register_sensor(new_sensor)
¶
Register a sensor with this unit.
Ensures no two sensors report the same parameter name within a unit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_sensor
|
A Sensor instance to attach to this unit. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a parameter name conflicts with an existing sensor. |
Source code in pt/controller_3/src/plant_controller/unit.py
start_sensing()
async
¶
Start all sensor reading loops concurrently.
Each sensor's reading_loop is launched as a task in a task group. This coroutine runs indefinitely.
Source code in pt/controller_3/src/plant_controller/unit.py
db_save_function(data)
¶
Persist measurement data to the database.
This method is passed to sensors and pumps as their save callback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Datapoint | list[Datapoint]
|
A single Datapoint or list of Datapoints to persist. |
required |
Source code in pt/controller_3/src/plant_controller/unit.py
get_sensing_capabilites()
¶
Return combined capabilities of all registered sensors.
Returns:
| Type | Description |
|---|---|
|
Dict mapping parameter names to their capability info dicts. |
Source code in pt/controller_3/src/plant_controller/unit.py
has_actuation()
¶
Return whether this unit has actuation capabilities.
Override in subclasses that have pumps or other actuators.