flexmeasures.data.services.automation_copies
Copying automations along with the asset subtree they belong to (see copy_asset).
Functions
- flexmeasures.data.services.automation_copies.copy_automations(asset_id_map: dict[int, int], sensor_id_map: dict[int, int], destination_account_id: int | None) list[SkippedAutomation]
Copy the automations of a freshly copied asset subtree, leaving each copy inactive.
Every automation on a copied asset is copied onto the corresponding new asset, with its references to sensors inside the subtree pointed at the new sensors. A copy keeps its name, type, cron expression and timezone, but starts inactive and with a fresh cursor, so that it inherits neither the original’s run history nor its queued jobs. A copy waits for the copies of the automations its original waits for, where those were copied, too, and for the very automations its original waits for otherwise.
An automation that cannot be copied safely is skipped rather than failing the asset copy: the copied asset, its sensors and the other automations are kept. Each skipped automation is logged and returned, so that the caller can report it.
- Parameters:
asset_id_map – Mapping of every original asset ID in the copied subtree to its new asset ID.
sensor_id_map – Mapping of every original sensor ID in the copied subtree to its new sensor ID.
destination_account_id – The account the copy belongs to, or None if the copy is public.
- Returns:
The automations that were skipped, in the order they were considered.
Classes
- class flexmeasures.data.services.automation_copies.SkippedAutomation(automation_id: int, name: str, asset_id: int, reason: str)
One automation that was left out of an asset copy, and why.
Exceptions
- exception flexmeasures.data.services.automation_copies.AutomationNotCopyable
Raised when one automation cannot be copied safely.
The asset copy goes ahead without it, so the message is shown to whoever asked for the copy; phrase it as a complete sentence that says what stood in the way.