Skip to main content

KOReader telemetry snapshot model and Home Assistant command protocol (parsing, command builders, coalescing command queue).

Project description

pykoreader

CI PyPI

Pure-Python model of the KOReader telemetry snapshot and the Home Assistant command protocol: snapshot parsing, command builders, and a coalescing, capped command queue. No Home Assistant or network dependencies.

Used by the ha-koreader Home Assistant integration, but usable standalone.

Install

pip install pykoreader

Usage

from pykoreader import Snapshot, CommandQueue, parse_payload, commands

# Parse an incoming webhook body (a decoded JSON object) into a typed snapshot.
snap = parse_payload({"battery_level": 80, "reading": True, "book_title": "Foundation"})
print(snap.battery_level, snap.book_title)   # 80 Foundation

# Build and queue commands for the device's next check-in.
queue = CommandQueue()
queue.add(commands.set_frontlight(40))
queue.add(commands.set_frontlight(60))       # idempotent: replaces the previous one
queue.add(commands.show_message("Time to sleep", timeout=10))
print(queue.drain())                         # returns pending commands and clears

API

  • Snapshot / Snapshot.from_payload(mapping) — typed telemetry fields; unknown keys kept in .extra.
  • parse_payload(raw) — validate a decoded body is an object and return a Snapshot (raises ValueError otherwise).
  • commands — builders: set_frontlight, set_warmth, set_frontlight_power, set_wifi, page_turn, goto_page, goto_chapter, toggle_bookmark, set_dark_mode, suspend, restart, refresh, sync_now, show_message; plus type constants and COALESCE_TYPES.
  • CommandQueueadd(command), drain(), pending, len(). Coalesces idempotent types (last-write-wins), caps at MAX_QUEUED_COMMANDS.

License

MIT

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

pykoreader-0.2.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

pykoreader-0.2.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file pykoreader-0.2.0.tar.gz.

File metadata

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

File hashes

Hashes for pykoreader-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3a54afb128d211673f93e431a5289a6b36fab5d51ebece29180a208c3179b4b8
MD5 dcffe1e6ce9c6c0e5b83844e620daf36
BLAKE2b-256 f0a7b176a55ba1f5dbb950b1ce7a99d739ea351fbc55e4428b55e79eb335d7f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pykoreader-0.2.0.tar.gz:

Publisher: release.yml on hudsonbrendon/pykoreader

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

File details

Details for the file pykoreader-0.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pykoreader-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38c34d60e1f92abc795e896ca282721a487bb8f2cd7ea15deeebffedad7b14c6
MD5 0a39c605c15507fd308ba85c2eb30e58
BLAKE2b-256 f4dee8236a7f518824010094a779d18b7ce54b42ac0e783790e96431cf7fe021

See more details on using hashes here.

Provenance

The following attestation bundles were made for pykoreader-0.2.0-py3-none-any.whl:

Publisher: release.yml on hudsonbrendon/pykoreader

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