Plant
Plant unit module.
A Plant is a Unit that has both sensors and a water pump attached. It manages pump schedules and provides watering actuation in addition to the base sensing functionality.
Plant
¶
Bases: Unit
A plant unit with sensors and a calibrated water pump.
Plants are configured via JSON files in ~/.plant_controller/plants/.
Each plant has one pump and one or more sensors, all specified in the
config. Watering is controlled by a pump schedule loaded from
~/.plant_controller/pump_schedules/<plant_name>.json.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
The parsed plant configuration dict. |
|
config_path |
Filesystem path to the plant's JSON config file. |
|
pump |
The pump instance attached to this plant. |
|
schedule |
The active PumpSchedule instance. |
|
schedule_location |
Path to the pump schedule JSON file. |
Source code in pt/controller_3/src/plant_controller/plant.py
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
__init__(config, db_client, busses, schedules_directory, config_path=None)
¶
Initialize the plant from a configuration dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict
|
Parsed plant config (must include 'name', 'sensors', and 'actuators.water_pump' sections). |
required |
db_client
|
DatabaseClient
|
Database client for persisting data. |
required |
busses
|
dict[str, Bus]
|
Dict of available bus instances. |
required |
schedules_directory
|
str
|
Directory containing pump schedule JSONs. |
required |
config_path
|
str | None
|
Path to the config file (for saving changes back). |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If required config fields are missing. |
Source code in pt/controller_3/src/plant_controller/plant.py
update_schedule(schedule)
¶
Validate and apply a new pump schedule, persisting it to disk.
Cancels any currently running schedule coroutine so that it restarts with the new configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schedule
|
dict[str, Any]
|
A schedule config dict with 'type' and 'schedule' keys. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the schedule config is invalid. |
Source code in pt/controller_3/src/plant_controller/plant.py
save_configuration()
¶
Persist the current config dict back to the JSON file.
Raises:
| Type | Description |
|---|---|
ValueError
|
If no config_path was provided at init time. |
Source code in pt/controller_3/src/plant_controller/plant.py
sensor_specific_config_save_function(sensor_name)
¶
Create a config save callback scoped to a specific sensor.
Returns a callable that, when called with keyword arguments, merges
them into the sensor's kwargs section in the plant config and
persists the result to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_name
|
Name of the sensor in the config's |
required |
Returns:
| Type | Description |
|---|---|
Callable
|
A callable accepting |
Source code in pt/controller_3/src/plant_controller/plant.py
save_pump_calibration(slope, offset)
¶
Save new pump calibration parameters to the plant config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slope
|
float
|
Linear calibration slope (seconds per ml). |
required |
offset
|
float
|
Linear calibration offset (seconds). |
required |
Source code in pt/controller_3/src/plant_controller/plant.py
start_watering()
async
¶
Run the pump schedule in a loop, restarting on cancellation.
When the schedule's cancel scope is cancelled (e.g. after an update_schedule call), the schedule is re-parsed from disk and restarted.
Source code in pt/controller_3/src/plant_controller/plant.py
has_actuation()
¶
parse_config(path)
staticmethod
¶
Parse a plant JSON config file, injecting the filename as 'name'.
If 'name' is already in the config file, the filename will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the plant's JSON configuration file. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Config dict with 'name' key added from the filename. |
Source code in pt/controller_3/src/plant_controller/plant.py
setup_functions()
¶
Collect setup functions from the pump and all sensors.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
Dict mapping action names (e.g. 'pump.calibrate') to dicts |
dict[str, dict[str, Any]]
|
with 'description' and 'function' keys. |