Sync with GitHub fork (upstream v0.4.0b1 + BLE fixes), own the library dependency, bump tooling #1
Loading…
Reference in a new issue
No description provided.
Delete branch "chore/sync-github-fork"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Brings this repo up to date with timstoop/nissan-leaf-obd-ble on GitHub and moves the dependency path under our control.
Commits
main: upstream v0.4.0b1 (override system, UUID setup flow) plus the BLE reliability fixes. Tree is identical to GitHubmainatcd1c8f1. The one commit that only existed here is already contained there (evolved with a fallback), so it is not re-applied.py-nissan-leaf-obd-blenow comes fromgit.timstoop.nl/tim/py-nissan-leaf-obd-ble, pinned to a tag, instead of the movingmainof a GitHub fork.ruff-check, mypy v2.4.0).ruff.tomlpins the lint rules to the previous defaults (E4/E7/E9/F). ruff 0.17 defaults are much broader and would flag existing code.thirdparty(isort section name insetup.cfg).ruff format. Python ASTs of all changed modules are identical before and after.v0.2.0(the library release was renamed from 0.1.2.post1).Merge order
This integration cannot install its dependency until the library has the tag:
v0.2.0on the merge commit.Checked
pre-commit run --all-filespasses (all hooks).Not included
pyupgrade --py37-plusandsetup.cfgmypypython_version = 3.7are stale but unchanged here.Generated with Claude Code
This fixes the longstanding "integration only reads data right after restart, never during normal polling" symptom on the Leaf, which manifested as State of Charge updating once at HA startup and then staying frozen until the next restart even while the car was charging on the driveway. Root cause: The Leaf's VCM ECU at CAN header 797 sleeps within seconds of bus inactivity. py_nissan_leaf_obd_ble's command loop in api.py sends 0210C0 ("Mystery") as the very first query; if the response has zero messages, the loop breaks out via: if command.name == "unknown" and len(response.messages) == 0: break and async_get_data returns an empty dict. The first 0210C0 effectively wakes the CAN bus, but the ECU is not responsive in time for that query's own response. The coordinator sees an empty dict, treats it as "car probably off", and switches to slow_poll (5 min). The next cycle re-runs ATZ + full ELM init, which lets the ECU sleep again, so we are right back to a single failed Mystery and the car is silently mis-classified as off. Why the integration restart appeared to "fix" it every time: async_setup_entry runs async_config_entry_first_refresh, then registers _async_specific_device_found via bluetooth.async_register_callback. The register call fires the callback immediately for the currently visible advertisement, which schedules a second coordinator.async_request_refresh roughly 50ms after the first refresh's BLE session closes. That back-to-back second refresh hits the ECU during the wake window left by the first Mystery and succeeds. Regular polling has no equivalent trigger, so single Mystery failures are sticky. The fix: When async_get_data returns an empty dict, immediately retry within the same _async_update_data call. The retry's fresh OBD.create + ELM init + Mystery takes roughly 10 seconds, by which time the ECU has woken up and responds normally; the rest of the 797 / 743 / 79B sweep then returns full data. Only after both attempts come back empty do we conclude the car is off and back off to slow_poll, preserving the original behavior for the genuinely-off case. Verified live: After deploying and restarting HA on a charging Leaf, each 30s fast_poll cycle logs: first attempt returned type=dict len=0 First attempt empty, retrying immediately to catch ECU wake-up retry attempt returned type=dict len=24-28 Car is on, polling: interval = 0:00:30 and SoC ticks up as expected (87.5 -> 88.8 -> ... during charging).