config.py
Versioned, secret-free TOML configuration for the HA=1-only agent.
Overview
Versioned, secret-free TOML configuration for the HA=1-only agent.
used by __init__.py agent.py cli.py mqtt.py
API
Cclass ConfigError(ValueError)
A configuration error safe to present without echoing configuration values.
_boolean, _integer, _mapping, _parse_device, _parse_mqtt, _reject_unknown, _string, config_from_mappingCclass MqttConfig
Broker connection settings with a secret reference, never a secret value.
_parse_mqttCclass DeviceConfig
One stable lock identifier and its serial connection preferences.
_parse_deviceCclass AgentConfig
The first version of the standalone-agent configuration contract.
config_from_mappingF_mapping(value: Any, field: str) -> Mapping[str, Any]
Coerce value to a dict; raise ConfigError if not a table (Mapping).
config_from_mapping · calls ConfigErrorF_string(value: Any, field: str, *, optional: bool=False) -> Optional[str]
Coerce value to a non-empty string, returning None if optional and value is None; raise ConfigError otherwise.
_parse_device, _parse_mqtt · calls ConfigErrorF_boolean(value: Any, field: str, *, default: bool=False) -> bool
Coerce value to bool, returning default if None; raise ConfigError if not a bool.
_parse_mqtt · calls ConfigErrorF_integer(value: Any, field: str, *, default: int) -> int
Coerce value to int, returning default if None; raise ConfigError if not an int or is a bool.
_parse_device, _parse_mqtt, config_from_mapping · calls ConfigErrorF_reject_unknown(values: Mapping[str, Any], allowed: set[str], field: str) -> None
Raise ConfigError if values contains any keys not in allowed.
_parse_device, _parse_mqtt, config_from_mapping · calls ConfigErrorF_parse_mqtt(values: Mapping[str, Any]) -> MqttConfig
Validate and parse the MQTT configuration block, checking all keys are recognized, validating port and password sources, enforcing mutual exclusivity of authentication methods, and returning an MqttConfig struct.
config_from_mapping · calls ConfigError, MqttConfig, _boolean, _integer, _reject_unknown, _stringF_parse_device(device_id: str, values: Mapping[str, Any]) -> DeviceConfig
Validate and parse one device configuration block, checking device ID format, rejecting unknown keys, validating serial port and baud rate ranges, and returning a DeviceConfig struct.
config_from_mapping · calls ConfigError, DeviceConfig, _integer, _reject_unknown, _stringFconfig_from_mapping(values: Mapping[str, Any]) -> AgentConfig
Validate a parsed TOML mapping without retaining raw secret values.
load_config, serialize_config · calls AgentConfig, ConfigError, _integer, _mapping, _parse_device, _parse_mqtt, _reject_unknownFload_config(path: Path) -> AgentConfig
Load a bounded TOML file and return validated, secret-free settings.
ConfigError, config_from_mappingF_toml_string(value: str) -> str
JSON-encode string with ensure_ascii=False for TOML serialization.
serialize_configFserialize_config(config: AgentConfig) -> str
Serialize validated configuration without resolving any secret reference.
write_config · calls ConfigError, _toml_string, config_from_mappingFwrite_config(path: Path, config: AgentConfig) -> None
Atomically write configuration with user-only permissions where supported.
ConfigError, serialize_configFredacted_config(config: AgentConfig) -> dict[str, Any]
Return diagnostics-safe configuration without secret references or device paths.