feat(drivers): accept the canonical driver spellings alongside the current ones#667
Conversation
…rrent ones srcfl/device-drivers is the single source for our drivers and is converting its catalog to the Blixt L1 host API and the @srcful/data-models emit keys. Doing that in one step is not possible: emitTelemetry unmarshals "w" and rejects a payload without it, so the first converted driver would take its site's telemetry down. Accept both spellings instead, so neither side has to move first. host.emit reads W when w is absent and SoC_nom_fract when soc is absent. When both are present the lowercase key wins, so a driver that sets both during conversion keeps the value it means as primary. Unknown fields were already preserved verbatim, so nothing else changes. write, write_registers and now_ms are registered as aliases of modbus_write, modbus_write_multi and millis. Nothing is removed. The older names keep working until the catalog has moved and the two can be retired together. Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0c7a67a408
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if env.SoC == nil { | ||
| env.SoC = env.CanonicalSoC |
There was a problem hiding this comment.
Convert canonical vehicle SoC to percent
When a vehicle driver emits canonical SoC_nom_fract (for example, 0.87), this fallback stores it unchanged even though DerVehicle SoC uses the 0..100 percentage scale. telemetry.PickBestVehicle therefore interprets that reading as 0.87% rather than 87%, which can distort loadpoint planning and charging decisions; convert the fraction for DerVehicle while retaining fractional semantics for battery/V2X readings.
Useful? React with 👍 / 👎.
| CanonicalW *float64 `json:"W,omitempty"` | ||
| CanonicalSoC *float64 `json:"SoC_nom_fract,omitempty"` |
There was a problem hiding this comment.
Normalize canonical phase-current fields
When a site-meter driver completes the same canonical migration and emits L1_A/L2_A/L3_A without their lowercase counterparts, only W and SoC_nom_fract are recognized here and the canonical phase keys remain unchanged in DerReading.Data. control.perPhaseOverageW unmarshals only l1_a/l2_a/l3_a, so it sees no current and silently disables the per-phase breaker clamp while the meter otherwise appears healthy; accept these canonical aliases before storing the payload or teach the safety consumer both spellings.
AGENTS.md reference: AGENTS.md:L31-L31
Useful? React with 👍 / 👎.
Summary
srcfl/device-driversis the single source for our drivers and is convertingits catalog to the Blixt L1 host API and the
@srcful/data-modelsemit keys.Doing that in one step is not possible from the driver side.
emitTelemetryunmarshals
"w"and returnsemit_telemetry: %s missing required wwhen it isabsent, so the first converted driver would take its site's telemetry down.
This accepts both spellings, so neither repository has to move first.
What changed
host.emitreadsWwhenwis absent, andSoC_nom_fractwhensocisabsent. When both are present the lowercase key wins, so a driver that
emits both during conversion keeps the value it means as primary. Unknown
fields were already preserved verbatim in the reading's
Datapayload, sonothing else about the shape changes.
Host functions
write,write_registersandnow_msare registered asaliases of
modbus_write,modbus_write_multiandmillis.Nothing is removed. The older names keep working until the catalog has moved,
and the two sets can then be retired together.
Why these names
Blixt L1 is where the driver contract was worked through, so
device-driversuses it as the naming reference and FTW adapts. Two details it gets right:
decode_u32_be, notdecode_u32. FTWalready agrees here; it registers only the
_beand_lespellings.@srcful/data-modelsusesW/SoC_nom_fract. Blixt reads each emit tableby exact key and drops a mistyped key without an error, which makes case a
contract rather than a convention.
Tests
go/internal/drivers/lua_canonical_names_test.go:readings, including SoC from
SoC_nom_fract;write,write_registers,now_msand the three original names all resolveto functions, and
now_msreturns the same kind of value asmillis.go test ./internal/drivers/ ./internal/telemetry/ ./internal/nova/passes.Not in this PR
set_model,set_rated_w,set_warmup_sanddecode_stringexist in Blixtand not here. They are host services rather than arithmetic, so a driver cannot
supply them itself. They need their own change once we agree on the semantics.
Helpers that are pure arithmetic —
decode_f32_be,decode_u64,scale— aredeliberately not added. The catalog now carries those in the driver's own
Lua, which is where device logic belongs and keeps the host surface smaller.
🤖 Generated with Claude Code