flexmeasures.data.services.generic_assets
Functions
- flexmeasures.data.services.generic_assets.create_asset(asset_data: dict) GenericAsset
Create an asset.
Does not validate data or commit the session. Creates an audit log.
- flexmeasures.data.services.generic_assets.delete_asset(asset: GenericAsset)
Delete an asset.
Does not commit the session. Creates an audit log.
- flexmeasures.data.services.generic_assets.format_json_field_change(field_name: str, old_value, new_value) str
Format JSON field changes using dictdiffer.
This function attempts to provide a detailed diff of changes between two JSON-like structures. If the structures are not dicts or lists, or if an error occurs, it fall back to a simple change description.
- Parameters:
field_name – Name of the field being changed.
old_value – The old value of the field.
new_value – The new value of the field.
- Returns:
A formatted string describing the changes.
Example input 1
{ "field_name": "flex_context", "old_value": {'site-production-capacity': '1500 kW', 'site-peak-production': '20000kW', 'inflexible-device-sensors': []}, "new_value": {'site-production-capacity': '15000 kW', 'site-peak-production': '20000kW', 'inflexible-device-sensors': []} }
Example output 1
Updated: flex_context, change site-production-capacity:: 1500 kW -> 15000 kW
Example input 2
{ "field_name": "flex_context", "old_value": {'site-production-capacity': '15000 kW', 'site-peak-production': '20000kW'}, "new_value": {'site-peak-production': '20000kW'} }
Example output 2
- flexmeasures.data.services.generic_assets.patch_asset(db_asset: GenericAsset, asset_data: dict) GenericAsset
Patch an asset.
Throws validation error as it checks JSON fields (e.g. attributes) for validity explicitly. Does not commit the session. Creates an audit log.