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.2.tar.gz (19.8 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.2-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: atorch_ble-0.1.2.tar.gz
  • Upload date:
  • Size: 19.8 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.2.tar.gz
Algorithm Hash digest
SHA256 f66625ba6e25f11e9ccc9083f66c6369c0250b23d233ba58ebf81df606cd953d
MD5 6662f9656cdb80f56a28e2e538305c2c
BLAKE2b-256 b5f41e204a0a1df94910c70317b4af74fbe23dc1b7e319fb207d21c9872c8287

See more details on using hashes here.

Provenance

The following attestation bundles were made for atorch_ble-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: atorch_ble-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 96e0a8458e7e170a8453ee38c669679baef7a661cc963645cc55211e932dc72b
MD5 188e30f54c9397b7526c4b2413d6346f
BLAKE2b-256 b69f649afea8dbd4575686a9bfc820335b389e836ad1bae60bfdbeea81828891

See more details on using hashes here.

Provenance

The following attestation bundles were made for atorch_ble-0.1.2-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