integration/homeassistant/src/openaliro_ha/agent.py
openaliro/openaliro
Module

agent.py

Runnable standalone-agent orchestration over the shared serial library.

integration/homeassistant/src/openaliro_ha/agent.py12 documented symbols

Overview

Runnable standalone-agent orchestration over the shared serial library.

depends on config.py models.py mqtt.py serial_session.py serial_transport.py  ·  used by __init__.py cli.py

API

Cclass AgentError(RuntimeError)

integration/homeassistant/src/openaliro_ha/agent.py:22

A safe agent failure with no raw serial, broker, or console details.

called by doctor, probe_device, run_device

Cclass DoctorDeviceResult

integration/homeassistant/src/openaliro_ha/agent.py:27

One diagnostics-safe device result.

called by doctor

F_publisher(config: AgentConfig, device: DeviceConfig) -> MqttPublisher

integration/homeassistant/src/openaliro_ha/agent.py:37

Create an MQTT publisher from the agent and device configuration.

Fsession_for_device(device: DeviceConfig) -> SerialSession

integration/homeassistant/src/openaliro_ha/agent.py:42

Build a reconnecting serial session that resolves `auto` on every open.

called by probe_device

Fconnection_factory()

integration/homeassistant/src/openaliro_ha/agent.py:45

Factory coroutine to open a serial connection to the device: resolve the serial port from device.serial_port and device.serial_identity, then open the connection at device.baud.

Fdoctor(config: AgentConfig, *, publisher_factory: PublisherFactory=_publisher, session_factory: Callable[[DeviceConfig], SerialSession]=session_for_device) -> tuple[DoctorDeviceResult, ...]

integration/homeassistant/src/openaliro_ha/agent.py:53

Validate serial protocol and broker connectivity without publishing events.

calls AgentError, DoctorDeviceResult

Fprobe_device(device: DeviceConfig) -> SessionState

integration/homeassistant/src/openaliro_ha/agent.py:88

Probe one selected port before configuration persists any settings.

calls AgentError, session_for_device

Cclass _DistanceThrottle

integration/homeassistant/src/openaliro_ha/agent.py:102

Rate-limit distance publishes without hiding real movement.

Ranging emits one reading per block, roughly every 192 ms, which is far more than Home Assistant needs. Publish at most once per interval, but let a large change through immediately so an approach or retreat is never delayed.

called by run_device

F_DistanceThrottle.__init__(self, *, min_interval: float=DISTANCE_MIN_INTERVAL_S, significant_change_mm: int=DISTANCE_SIGNIFICANT_CHANGE_MM, clock: Callable[[], float]=time.monotonic) -> None

integration/homeassistant/src/openaliro_ha/agent.py:110

Initialize the distance throttle with optional minimum publish interval in seconds, minimum significant change in millimeters, and a clock function. Default min_interval is DISTANCE_MIN_INTERVAL_S, default significant_change_mm is DISTANCE_SIGNIFICANT_CHANGE_MM, and default clock is time.monotonic.

F_DistanceThrottle.allows(self, distance_mm: int) -> bool

integration/homeassistant/src/openaliro_ha/agent.py:124

Report whether this reading should be published, recording it if so.

called by run_device

Frun_device(config: AgentConfig, device: DeviceConfig, stop_event: asyncio.Event, *, publisher_factory: PublisherFactory=_publisher, session_factory: Callable[[DeviceConfig], SerialSession]=session_for_device) -> None

integration/homeassistant/src/openaliro_ha/agent.py:140

Publish one device's approved observations until a caller stops the agent.

called by run  ·  calls AgentError, _DistanceThrottle, _DistanceThrottle.allows

Frun(config: AgentConfig, stop_event: Optional[asyncio.Event]=None) -> None

integration/homeassistant/src/openaliro_ha/agent.py:188

Run every configured lock concurrently until the supplied event is set.

calls run_device