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.0.tar.gz (17.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.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: atorch_ble-0.1.0.tar.gz
  • Upload date:
  • Size: 17.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.0.tar.gz
Algorithm Hash digest
SHA256 722fd0e156d1eb9779962371c5d1e438e86e16f05dc8464f2aac8c9bca8d8a35
MD5 39d51cda8ebecc8829db15c8198ec313
BLAKE2b-256 7b4ffcdeedfdf2e48b7df55cbb2b096aa1f69aa779bec9a2c5a7e0747786898e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: atorch_ble-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 553bc05eddf9fb76ef765836ef13892fdb13b6bb3b00be39e054dbffd1033ad5
MD5 0561e726ddb2f91ce7cc00443d9ae171
BLAKE2b-256 3da3f71bf6314933bee9248ec38f9ca9d43eda781b8ecc3fff69fa72a1f09883

See more details on using hashes here.

Provenance

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