OTA¶
Python API reference for the tolomeo.plugins.ota package.
OTAPlugin drives a firmware update from notification to installation. Derive from it and implement install_update and
monitor_update; the inherited OTAMixin methods handle the rest of the lifecycle. For the states and transitions, see
OTA State Machine; for the design rationale, see OTA Mechanism.
OTAPlugin¶
tolomeo.plugins.ota.OTAPlugin
¶
Bases: PluginBase, OTAMixin
OTA plugin implementation.
This plugin integrates the OTA update workflow into the Tolomeo
plugin architecture, combining the PluginBase interface with
OTAMixin for update state management. It provides real download,
installation, and lifecycle coordination behavior suitable for
deployment environments.
The class binds OTA state transitions to task manager events and ensures consistent synchronization between OTA status and task execution state.
Source code in tolomeo/plugins/ota/plugin.py
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | |
Meta
¶
__init__(logger=None)
¶
Initialize the OTA plugin instance.
Combines PluginBase and OTAMixin initializers, establishing
logging and OTA state tracking behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger | None
|
Optional logger instance for OTA operations. If None, a default logger is created. |
None
|
Source code in tolomeo/plugins/ota/plugin.py
after_setup()
async
¶
Bootstrap OTA state after plugin setup.
This hook is the single authoritative bootstrap for the OTA state
machine: it calls reset, which resolves to whatever the checkpoint
says — updated, paused, update_available, or any other
checkpointable state — rather than assuming a fixed starting state.
Source code in tolomeo/plugins/ota/plugin.py
before_setup()
async
¶
Configure OTA-related callbacks prior to plugin setup.
This hook prepares the OTA state machine and task manager by
registering event hooks for download errors and task state
transitions. It chains existing task manager callbacks with
OTA-specific handlers to ensure OTA state synchronization. It also
resolves the checkpoint file location and OTAOptions.allow_same_version
from self.options (readable now that connect has assigned self.id)
and assigns them to the state machine, which arms bootstrapping without
performing it — after_setup performs the actual bootstrap.
Raises:
| Type | Description |
|---|---|
Exception
|
If callback setup fails or task manager references are invalid. |
Source code in tolomeo/plugins/ota/plugin.py
OTAMixin¶
tolomeo.plugins.ota.plugin.OTAMixin
¶
Mixin providing OTA (Over-The-Air) update lifecycle management.
Uses ABCMeta so install_update and monitor_update are enforced. Both
bodies are ..., so an unenforced marker means a plugin that forgot one
instantiates cleanly and silently no-ops the firmware install.
Source code in tolomeo/plugins/ota/plugin.py
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 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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
fsm
property
¶
Get the OTA state machine instance.
options
property
¶
Declared, not implemented: PluginBase provides this.
Narrowed to OTAOptions here so the mixin's own reads are typed. The
host class resolves it against whatever model it declares — OTAOptions
or an extension of it.
state
property
¶
Get the current OTA state.
Returns:
| Type | Description |
|---|---|
str
|
The string representation of the current OTA state |
str
|
(e.g., "downloading", "paused", "update_ready"). |
__init__(logger=None)
¶
Create the OTA state machine; the logger and callbacks belong to PluginBase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger | None
|
Optional logger for the state machine. If None, it uses its own module logger. |
None
|
Source code in tolomeo/plugins/ota/plugin.py
abort_update()
async
¶
Abort a failed OTA update and restart from the beginning.
Cleans up any existing download task or partial file, and
transitions back to update_available.
Raises:
| Type | Description |
|---|---|
Exception
|
If cleanup or state reset fails |
Source code in tolomeo/plugins/ota/plugin.py
cancel_update()
async
¶
Cancel an in-flight update and clean up its partial download.
Raises:
| Type | Description |
|---|---|
Exception
|
Whatever the cleanup or the transition raised, after logging it. |
Source code in tolomeo/plugins/ota/plugin.py
clear_update()
async
¶
Discard the pending update and clean up its partial download.
Raises:
| Type | Description |
|---|---|
Exception
|
Whatever the cleanup or the transition raised, after logging it. |
Source code in tolomeo/plugins/ota/plugin.py
install_update()
abstractmethod
async
¶
Install the downloaded OTA update.
This method must be implemented by subclasses to perform the actual update process (e.g., applying firmware, rebooting, or verifying installation integrity).
Source code in tolomeo/plugins/ota/plugin.py
monitor_update()
abstractmethod
async
¶
Monitor the OTA update progress.
This method must be implemented by subclasses to periodically check update progress, collect metrics, or detect installation anomalies.
Source code in tolomeo/plugins/ota/plugin.py
notify_update(fw_name, fw_version, url=None, dest=None)
async
¶
Notify the system that an update is available.
Sets the pending update information and transitions the OTA state
machine to update_available, unless fw_version would roll the
installed firmware back: an older version is ignored, and so is the same
version unless OTAOptions.allow_same_version is set. An ignored update
leaves both the state and the pending update untouched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fw_name
|
str
|
Name of the firmware update |
required |
fw_version
|
str
|
Version of the firmware update, in Semantic Versioning 2.0.0 |
required |
url
|
str | None
|
Optional URL for the update package |
None
|
dest
|
Path | str | None
|
Optional destination path for the download |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the update was accepted, False if it was ignored. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in tolomeo/plugins/ota/plugin.py
pause_download()
async
¶
Pause the ongoing OTA download.
Requests the TaskManager to pause the active download task.
The OTA state machine will automatically transition to paused
through the state change callback.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the task manager is not initialized |
Exception
|
If the pause operation fails |
Source code in tolomeo/plugins/ota/plugin.py
reboot_system()
async
¶
Request a system reboot using systemd via D-Bus.
Attempts to start the systemd-reboot.service unit using the
system D-Bus. This method is typically called after a successful
update to reboot into the new firmware.
Raises:
| Type | Description |
|---|---|
Exception
|
If the D-Bus call fails or the service cannot be started |
Source code in tolomeo/plugins/ota/plugin.py
reset_state()
async
¶
Reset the OTA state machine to a clean baseline.
Cleans up any in-flight download, clears the pending update, removes the
persisted checkpoint, and drives the FSM through reset() back to
bootstrapping. With no checkpoint present, re-detection resolves to
updated.
Raises:
| Type | Description |
|---|---|
Exception
|
If cleanup or the reset transition fails. |
Source code in tolomeo/plugins/ota/plugin.py
resume_download()
async
¶
Resume a previously paused OTA download.
Requests the TaskManager to resume the paused download task.
If no task exists, creates a new one using the pending update info.
The OTA state machine will transition to downloading through
the state change callback.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the task manager is not initialized |
ValueError
|
If download URL is missing |
Exception
|
If the resume operation fails |
Source code in tolomeo/plugins/ota/plugin.py
start_download(url=None, dest=None)
async
¶
Start downloading the OTA update package.
This method coordinates with the TaskManager to create and start
a download task for the specified URL. It automatically manages
existing tasks, retries, and OTA state synchronization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str | None
|
Optional download URL. If None, uses the pending update URL |
None
|
dest
|
Path | str | None
|
Optional destination path for saving the downloaded file |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the download URL is missing |
RuntimeError
|
If the task manager is not initialized |
Exception
|
If task creation or execution fails |
Source code in tolomeo/plugins/ota/plugin.py
OTAOptions¶
tolomeo.plugins.ota.models.OTAOptions
¶
Bases: BaseModel
Deployment options for OTAPlugin, read from [plugins.<id>].
Declared as OTAPlugin's Meta.config_model. A plugin deriving from
OTAPlugin adds its own options by extending this model, so the fields
OTAPlugin itself reads stay present::
class SWUpdateOptions(OTAOptions):
socket_path: Path = Path("/run/swupdate.sock")
extra="forbid" turns a mistyped key into a startup error naming it.
hide_input_in_errors=True keeps the offending value out of that error,
exactly as tolomeo.config.Config does: the error reaches startup logs, and
an option may hold a secret.
Attributes:
| Name | Type | Description |
|---|---|---|
download_dir |
Path
|
Directory the update package is written to. |
download_filename |
str
|
Name the package is saved under. |
checkpoint_file |
Path
|
Where the OTA state snapshot is persisted, so an
interrupted update is recoverable across a restart. Defaults under
|
allow_same_version |
bool
|
Whether an update whose version equals the installed firmware's is accepted, whether notified or restored from the checkpoint. An older version never is. |
Source code in tolomeo/plugins/ota/models.py
download_dest
property
¶
Full path the update package is downloaded to.
OTAStateMachine¶
tolomeo.plugins.ota.fsm.OTAStateMachine
¶
Bases: StateMachine
State machine managing the OTA (Over-The-Air) update process.
This class encapsulates the state transitions for OTA updates, including update detection, download, installation, and failure recovery. It operates independently from any higher-level management logic and communicates state changes via a push callback.
Source code in tolomeo/plugins/ota/fsm.py
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 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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
checkpoint_file
property
writable
¶
Get where the checkpoint currently lives.
current_firmware
property
¶
Get the currently installed firmware info.
pending_update
property
¶
Get the pending update info.
push_callback
property
writable
¶
Get the registered push callback.
__init__(logger=None, checkpoint_file=None, *, defer_bootstrap=False, allow_same_version=False)
¶
Initialize the OTA state machine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger | None
|
Optional logger instance for state transitions and diagnostic output. If None, a default logger is created. |
None
|
checkpoint_file
|
Path | str | None
|
Path to the checkpoint file. If None, uses
|
None
|
defer_bootstrap
|
bool
|
When |
False
|
allow_same_version
|
bool
|
Whether an update to the installed version is
accepted, see |
False
|
Source code in tolomeo/plugins/ota/fsm.py
accepts_version(version)
¶
Tell whether an update to version would not roll the firmware back.
A newer version than the installed firmware's is accepted, an older one
never is, and the same one only when allow_same_version is set.
Versions compare by Semantic Versioning precedence, so build metadata
is ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
Version of the update, in Semantic Versioning 2.0.0 |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the update may proceed, False if it must be ignored. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in tolomeo/plugins/ota/fsm.py
clear_checkpoint()
¶
clear_pending_update()
¶
on_enter_bootstrapping()
¶
Handle the entry into the 'Bootstrapping' state.
This method is called when the state machine transitions to the 'Bootstrapping' state. It loads the saved checkpoint (if available), restores the firmware info, and transitions to the last checkpointed state.
A checkpointed update that accepts_version rejects is dropped, and the
machine resolves to updated: the firmware may have been updated by
other means while the checkpoint sat on disk.
A deferred machine has not yet been told where its checkpoint lives, so
this returns without reading anything until checkpoint_file is assigned.
Source code in tolomeo/plugins/ota/fsm.py
on_enter_state(event, source, target, **kwargs)
¶
Announce every state except the transient trip into bootstrapping.
Runs once per transition, after current_state has been updated to
target — unlike on_transition, which the underlying engine calls
before that assignment. Keying the guard on the target rather than the
source matters at startup: the state a restarted service resolves to is
reached from bootstrapping, and suppressing that left consumers with
no way to learn it short of asking GetOTAStatus.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
str
|
The name of the triggering event. |
required |
source
|
State
|
The state from which the transition originated. |
required |
target
|
State
|
The new state after the transition. |
required |
**kwargs
|
Any
|
Additional keyword arguments for transition hooks. |
{}
|
Source code in tolomeo/plugins/ota/fsm.py
on_exit_bootstrapping()
¶
on_transition(event, source, target, **kwargs)
¶
Handle actions after each state transition.
This method is automatically called by the underlying state machine
whenever a transition occurs, before current_state is updated to
target. It logs the transition and, if the target state is one
that can be restored from a checkpoint, saves the current state.
Pushing the updated state is handled separately by
on_enter_state, which the engine calls after the assignment — at
this point current_state still reports the source state, so a
push from here would announce the wrong value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
str
|
The name of the triggering event (e.g., 'download', 'install') |
required |
source
|
State
|
The state from which the transition originated |
required |
target
|
State
|
The new state after the transition |
required |
**kwargs
|
Any
|
Additional keyword arguments for transition hooks |
{}
|
Source code in tolomeo/plugins/ota/fsm.py
set_pending_update(name=None, version=None, url=None, download_path=None)
¶
Set or update the pending update information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Name of the firmware update |
None
|
version
|
str | None
|
Version of the firmware update |
None
|
url
|
str | None
|
URL from which to download the update |
None
|
download_path
|
str | Path | None
|
Path where the update will be saved |
None
|
Source code in tolomeo/plugins/ota/fsm.py
Firmware models¶
tolomeo.plugins.ota.models.InstalledFirmware
dataclass
¶
Firmware currently installed on the system.
Read from /usr/lib/os-release at runtime via load. The fields map
to FIRMWARE_NAME and BUILD_VERSION in that file.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The firmware name (e.g. |
version |
str
|
The firmware build version (e.g. |
Source code in tolomeo/plugins/ota/models.py
tolomeo.plugins.ota.models.PendingUpdate
dataclass
¶
A firmware update that is available to be applied.
Populated by OTAMixin.notify_update and persisted in the OTA
checkpoint file across reboots. All fields are optional because
the update info can be provided incrementally (e.g. URL given at
notify time, destination path confirmed at download time).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str | None
|
Firmware name of the pending update. |
version |
str | None
|
Firmware version of the pending update. |
url |
str | None
|
Download URL for the update package. |
download_path |
str | None
|
Local filesystem path where the artifact is saved.
|
Source code in tolomeo/plugins/ota/models.py
asdict()
¶
Render the pending update as a plain dict for serialisation.
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
The set fields only; unset ones are omitted rather than sent as |
Dict[str, str]
|
nulls, so a partially known update reads as such. |