Skip to content

Core API: stringly-typed state, null as the only error, no explicit API mode; not yet library-grade #120

Open

Description

@dzid26

Problem

One of the master plan's locked decisions is "Library-grade docs and API hygiene from now on". The current core API falls short of that in several ways.

  • Domain values are strings.
    • TeslaCommands.Charge.chargingState: String? turns the proto oneof into "Charging", "Complete", … (TeslaCommands.kt#L59-L71).`` Those strings are compared in core (BatterySample.isCharging), in the app (`chargingStateText`), in the CSV, in demo data and in tests.
    • TeslaConnection.sessions: List<String> holds enum names, and the UI checks contains("DOMAIN_VEHICLE_SECURITY") (MainScreen.kt#L487, BleTrackingService.kt#L121).``
    • parseActionStatus returns enum.name.
    • A typo or a rename still compiles and then fails silently. Use enums or the generated Wire types instead.
  • null is the only error signal.
    • TeslaSession.import/encrypt/decrypt and TeslaCrypto.decryptGcm (where runCatching{…}.getOrNull() swallows every exception) all return null, whether the cause is a wrong VIN, a bad tag, an exhausted counter or a malformed message. All the app can log is "session verification failed".
    • A sealed result type (or typed exceptions) is needed to drive Protocol: replies are routed by trial-decoding; car faults and session resyncs are silently dropped #111 and to show useful errors in the UI.
    • Error handling is also inconsistent: some parsers (TeslaVcsec.parse*, TeslaCommands.parse*) throw on malformed input while TeslaPairing catches, so callers wrap everything in runCatching.
  • Explicit API mode is off. Everything in core is public by default: AntiReplayWindow.updateSlidingWindow, TeslaCrypto.randomBytes, the Metadata hash contexts, the BleFramer constants, and so on. Turn on kotlin { explicitApi() } now and decide what is public before the binary-compatibility validator arrives in Phase 3.
  • Keying contradicts ADR-0004.
    • ADR-0004 makes the advertised name the identity and the address an attribute, but BleUiState.connections is keyed by address (BleModels.kt#L58-L72),`` while links are keyed by name.
    • UI and notification code join the two through vehicle.address lookups.
    • When an address changes, the old entry stays behind in the state.
  • The same helper exists several times. There are two private ByteArray.toHex() copies (TeslaBleController.kt#L1446, SettingsScreen.kt#L355), alongside the stdlib toHexString() that Format BLE names with stdlib toHexString #104 adopted in core. Three test files each define their own String.hex().

Related: #118, #111.

Activity

  1. dzid26 commented on Oct 21, 2026

    @dzid26
    CollaboratorAuthor

    Checked against main (8cbaab0) on 2026-10-21.

    Done

    Still open

    • TeslaConnection.sessions: List<String> still holds enum names, and the UI compares "DOMAIN_VEHICLE_SECURITY" as a string (MainScreen.kt:497, BleTrackingService.kt:227).
    • ByteArray.toHex() is still duplicated (TeslaBleController.kt:1555, SettingsScreen.kt:513, SessionHandshake.kt:243, PairingFlow.kt:427).
    • BleUiState.connections is still keyed by address (BleModels.kt:66), against ADR-0004.
    • No explicitApi() anywhere in the build files.
    • Not verified: whether the sealed result / typed error item survived the move to :protocol.

    Keeping this open for the remaining items.


    Generated by Claude Code

  2. dzid26 commented on Oct 21, 2026

    @dzid26
    CollaboratorAuthor

    Update: the duplicated ByteArray.toHex() helpers are gone, replaced by the stdlib toHexString() in #317 (merged as 8ca58f3).


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions