data_model: fix apply_procedural paths for extract_all snapshot format
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -393,18 +393,17 @@ def apply_procedural(record: dict) -> dict:
|
||||
"""
|
||||
proc: dict = {}
|
||||
|
||||
range_at_soc = _get(record, "electric_drive", "range", "value")
|
||||
soc = _get(record, "electric_drive", "battery", "soc", "value")
|
||||
range_at_soc = _get(record, "sensor", "electric_range", "value")
|
||||
soc = _get(record, "sensor", "battery_level", "value")
|
||||
if range_at_soc is not None and soc:
|
||||
proc["range_at_100"] = _phys(round(100 * float(range_at_soc) / float(soc), 1), "km")
|
||||
|
||||
# ── add computed fields here ──────────────────────────────────────────
|
||||
# Use _get(record, "domain", "statusObject", "field", "value") to
|
||||
# safely read any nested value. Always use {"value": ..., "unit": ...}
|
||||
# format so the GUI picks up the field automatically.
|
||||
# Use _get(record, "sensor"|"binary_sensor"|..., "attr_name", "value")
|
||||
# Always use {"value": ..., "unit": ...} format so the GUI picks it up.
|
||||
#
|
||||
# Example — usable energy estimated from SOC and battery capacity:
|
||||
# soc = _get(record, "electric_drive", "battery", "soc", "value")
|
||||
# soc = _get(record, "sensor", "battery_level", "value")
|
||||
# if soc is not None:
|
||||
# proc["energy_stored"] = {"value": round(soc / 100 * 77.0, 1), "unit": "kWh"}
|
||||
# ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user