cremalink.local_server_app.state module
This module defines the state management for the local server application. It centralizes all runtime data, including device configuration, cryptographic keys, command queues, and the latest received device data.
- class cremalink.local_server_app.state.LocalServerState(settings: ServerSettings, logger)[source]
Bases:
objectManages the runtime state of the local server in a thread-safe manner.
This class acts as a state machine, holding all information related to the device connection, including credentials, cryptographic session keys, pending commands, and the most recent data snapshots (monitor and properties). An asyncio.Lock is used to prevent race conditions when accessing state from different asynchronous tasks.
- async configure(dsn: str, device_ip: str, lan_key: str, device_scheme: str = 'https', monitor_property_name: str | None = None) None[source]
Configures the state with new device details and resets the session. If the device details are unchanged, this is a no-op.
- async get_property_value(property_name: str) Any | None[source]
Retrieves a single property value from the last known snapshot.
- async handle_datapoint(decrypted_json: dict) None[source]
Processes a decrypted data payload from the device, updating the appropriate data snapshot (properties or monitor).
- async init_crypto(random_1: str, time_1: str | int) None[source]
Derives and initializes all session keys using values from the key exchange.
- log(event: str, details: dict | None = None) None[source]
Convenience method for logging with redacted details.
- async next_command_payload() Dict[str, Any][source]
Retrieves the next command from the queue for sending to the device. If the queue is empty, it returns an empty “heartbeat” payload.
- async queue_command(command: str) None[source]
Adds a high-level device command to the outgoing queue.