Skip to main content

Standalone parser for the Atorch BLE protocol (J7-C / UC96 and related USB/AC/DC meters).

Project description

atorch-ble

A standalone Python parser for the Atorch BLE protocol used by USB/AC/DC power meters such as the J7-C and UC96. The package provides byte-level notification-frame reassembly, packet decoding, and typed dataclasses for measurements, with no Home Assistant dependency so it can be used from any async or sync Python program. This package is consumed by the atorch_ble Home Assistant integration, which declares it as a manifest.json requirement following the Bluetooth-Devices org pattern that keeps raw byte parsing out of HA Core.

Status: v0.1 — initial release, J7-C / packet type 0x03 only.

Installation

pip install atorch-ble

Requires Python 3.12 or newer.

Usage

from atorch_ble import AtorchBleParser, UnsupportedPacketType, UsbMeterReading

# A canonical 36-byte J7-C USB-meter frame (synthetic, derived from the
# documented byte layout). In real use you'd feed the bytes you receive
# from a bleak notification callback.
frame = bytes.fromhex(
    "ff55010300020000007b0001c800000315010f0110001b01020304"
    "000000000000ec0000"
)

parser = AtorchBleParser()
try:
    readings: list[UsbMeterReading] = parser.feed(frame)
except UnsupportedPacketType as exc:
    # Raised for non-J7-C packet types (e.g. DL24/UD18 DC meters).
    print(f"unsupported packet type: 0x{exc.packet_type:02x}")
    readings = []

for r in readings:
    print(f"voltage:     {r.voltage_v} V")
    print(f"current:     {r.current_a} A")
    print(f"capacity:    {r.capacity_mah} mAh")
    print(f"energy:      {r.energy_wh} Wh")
    print(f"D+ / D-:     {r.voltage_dplus_v} V / {r.voltage_dminus_v} V")
    print(f"temperature: {r.temperature_c} C")
    print(f"duration:    {r.duration_s} s")

AtorchBleParser.feed() accepts raw bytes from a single BLE notification callback (zero, partial, one, or multiple frames) and returns the list of fully decoded UsbMeterReading instances. Recoverable decode failures (bad length, magic, direction byte, or checksum mismatch) are swallowed and recorded on parser.error_count / parser.last_error; UnsupportedPacketType is re-raised so callers can surface it to the user.

Supported devices

Device Packet type Status
J7-C 0x03 Confirmed against documented byte layout
UC96 0x03 Same protocol family, untested
DL24 / UD18 0x01–0x02 Detected; raises UnsupportedPacketType

Development

git clone https://github.com/dallanwagz/atorch-ble
cd atorch-ble
pip install -e ".[dev]"
pytest

Quality gates: ruff for lint and formatting, mypy --strict for typing, and pytest with a 95% coverage floor.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

atorch_ble-0.1.1.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

atorch_ble-0.1.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file atorch_ble-0.1.1.tar.gz.

File metadata

  • Download URL: atorch_ble-0.1.1.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for atorch_ble-0.1.1.tar.gz
Algorithm Hash digest
SHA256 434bc8d46394e41ded98c1e173df0984284d8d84f586f2260b6ddc1ea0a30998
MD5 1442f976667e32c339e46c5e30784d39
BLAKE2b-256 5a6f4eb9d88fd60ac32ee620303836afc359462ad4a8851a3327d6f8606d1f80

See more details on using hashes here.

Provenance

The following attestation bundles were made for atorch_ble-0.1.1.tar.gz:

Publisher: release.yml on dallanwagz/atorch-ble

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file atorch_ble-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: atorch_ble-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for atorch_ble-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b5c5c8865c1cbe6fdb7039656f69bb51707438ba29153a7da011f75a0b8d6a8
MD5 c59073215a7388a977f8a26b14b58065
BLAKE2b-256 2e8c825d88243db79412002fb2cc2da56d0a23b398d92877c9f1b6a2e921eeff

See more details on using hashes here.

Provenance

The following attestation bundles were made for atorch_ble-0.1.1-py3-none-any.whl:

Publisher: release.yml on dallanwagz/atorch-ble

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page