flexmeasures.data.services.group_membership_audit
Note in the audit log of a device group when its membership changes.
A device joins a group through the group field of its own flex-model, so the group’s asset is never edited when a device joins or leaves it. Without these entries, the history of a group’s membership could only be pieced together from the audit logs of every asset that ever named it.
The changes are picked up from the session, so they are noted whichever way an asset was created, edited, moved or deleted: through the API, the UI, the CLI or a script. An asset deleted with one delete statement, as delete_asset does, never passes through the session, and neither do its offspring and their sensors, so delete_asset notes those changes itself, with note_deletion.
A report automation over a group may narrow it down to members of one asset type. Changing a member’s type then moves it in or out of what the report aggregates, which is noted on the group’s asset too, and creating such an automation notes which members it starts out with.
Functions
- flexmeasures.data.services.group_membership_audit.note_deletion(asset: GenericAsset) None
Note the membership changes of deleting the given asset in one statement, which no flush gets to see.
Deleting an asset that way, as delete_asset does, also deletes its offspring and their sensors through the database, so none of them passes through Session.deleted. Call this right before that statement, while they can all still be looked up.
- flexmeasures.data.services.group_membership_audit.note_report_selection(automation, reporter) None
Note on a group’s asset which of its members a new report automation aggregates, when it aggregates only one asset type.
The later notes on members entering or leaving the selection then have a starting point.