openlifu.io.LIFUUserConfig.LifuUserConfig

class openlifu.io.LIFUUserConfig.LifuUserConfig(header: LifuUserConfigHeader | None = None, json_data: Dict[str, Any] | None = None)[source]

Bases: object

Encapsulates the Lifu configuration stored in device flash.

The configuration is stored as a JSON blob with metadata including: - magic number for validation - version for compatibility - sequence number (monotonically increasing) - CRC for integrity

__init__(header: LifuUserConfigHeader | None = None, json_data: Dict[str, Any] | None = None)[source]

Initialize LifuUserConfig

Parameters:
  • header – Configuration header metadata

  • json_data – Configuration JSON data as a dictionary

classmethod from_wire_bytes(data: bytes) LifuUserConfig[source]

Parse configuration from wire format bytes

Wire format:

[header: 16 bytes][json: json_len bytes]

Parameters:

data – Raw bytes from device

Returns:

LifuUserConfig instance

Raises:

ValueError – If data is invalid or malformed

get(key: str, default: Any = None) Any[source]

Get a configuration value by key

get_json_str() str[source]

Get JSON configuration as a formatted string

set(key: str, value: Any)[source]

Set a configuration value by key

set_json_str(json_str: str)[source]

Set configuration from JSON string

Parameters:

json_str – JSON string to parse

Raises:

json.JSONDecodeError – If JSON is invalid

to_dict() Dict[str, Any][source]

Get the configuration as a dictionary

to_wire_bytes() bytes[source]

Convert configuration to wire format for sending to device

Returns:

Wire format [header][json_bytes]

Return type:

bytes

update(updates: Dict[str, Any])[source]

Update multiple configuration values