Skip to content

Command Layer

High-level, IDE-friendly interface for device operations.


Design Intent

Command wraps DeviceProtocol with named methods so callers never construct raw command strings. It is a pure abstraction — no state, no validation, no retry logic. All exceptions from the device propagate unchanged.


Command class

Constructed with any DeviceProtocol implementation:

from kazunoko import connect, Command

with connect() as device:
    cmd = Command(device)
    response = cmd.status()

All methods return DeviceResponse. Fields on the response depend on the specific command.

Info commands

Method Device command Key response fields
help() HELP help
status() GET_STATUS version, poll_count, threshold1..3, uptime
version() GET_VERSION version
uptime() GET_UPTIME uptime
mac_address() GET_MAC mac
queue_stats() GET_QUEUE queue stats

Configuration commands

Method Device command
poll_count(n) SET_POLL_COUNT <n>
deadtime(us) SET_DEADTIME <us>
threshold(channel, value) SET_THRESHOLD <ch> <value>
thresholds(dict) calls threshold() per channel
reset() RESET

Control and time

Method Device command
led(state) SET_LED <state>
rtc_time(unixtime) SET_RTC_TIME <unixtime>

Data

Method Device command
read() READ — returns one detection event

Low-level access

query(command_string) sends a raw command string for cases not covered by named methods:

response = cmd.query("CUSTOM_CMD 42")

Separation of concerns

Command never validates input. The device validates and returns an error response with status: "error" if the command is invalid. This keeps Command thin and avoids duplicating validation logic that already exists in firmware.

Command also never catches exceptions — they propagate to the caller so each use site can handle errors appropriately for its context (CLI shows a message and exits; scripts may retry; tests may assert on the exception).