cremalink.domain.device module

This module defines the core Device class, which represents a physical coffee machine. It serves as the primary high-level interface for interacting with a device, abstracting away the underlying transport and command details.

class cremalink.domain.device.BeanSystem(slot: int, name: str, selected: bool)[source]

Bases: object

One configured BeanAdapt slot (d25X_beansystem_N ba f0 blob).

slot is the bean-system index (1–6; slot 0 is the BeanAdapt ON/OFF feature flag, not a bean). name is the user-assigned bean name (UTF-16BE at [5..44], zero-stripped — DECODED G0/ loadBeanSystems); selected marks the machine’s currently selected bean (flag byte, research.md R10 / protocol.md §11).

name: str
selected: bool
slot: int
class cremalink.domain.device.Device(transport: DeviceTransport, dsn: str | None = None, model: str | None = None, nickname: str | None = None, ip: str | None = None, lan_key: str | None = None, scheme: str | None = None, is_online: bool | None = None, last_seen: str | None = None, firmware: str | None = None, serial: str | None = None, coffee_count: int | None = None, command_map: dict[str, ~typing.Any]=<factory>, property_map: dict[str, ~typing.Any]=<factory>, monitor_profile: MonitorProfile = <factory>, extra: dict[str, ~typing.Any]=<factory>, machine_profile: MachineProfile | None = None, n_profiles: int = 1, capabilities: dict[str, ~typing.Any]=<factory>, setting_levels: dict[str, int]=<factory>, statistics_source: str = 'native', statistics_datapoints: list[str] = <factory>, settings_datapoints: list[str] = <factory>, catalog_datapoints: list[str] = <factory>, monitor_bits: dict[str, list[str]]=<factory>, model_ref: dict[str, ~typing.Any]=<factory>, model_name: str | None = None, recipe_beverage_order: list[int] = <factory>, response_timeout: float = 8.0, response_poll: float = 0.25, write_confirm_seconds: float = 45.0, profile_poll_seconds: float = 30.0, app_id_refresh_seconds: float = 240.0, app_id_confirm_seconds: float = 10.0, app_id_confirm_poll: float = 3.0, app_id_confirm_own_seconds: float = 5.0, app_id_refresh_min_seconds: float = 60.0)[source]

Bases: object

Represents a coffee machine, providing methods to control and monitor it.

This class holds the device’s state (e.g., IP, model) and uses a DeviceTransport object to handle the actual communication. Device-specific capabilities are loaded from a “device map” file.

transport

The transport object responsible for communication.

Type:

cremalink.transports.base.DeviceTransport

dsn

Device Serial Number.

Type:

str | None

model

The model identifier of the device.

Type:

str | None

nickname

A user-defined name for the device.

Type:

str | None

ip

The local IP address of the device.

Type:

str | None

lan_key

The key used for LAN-based authentication.

Type:

str | None

scheme

The communication scheme (e.g., ‘http’, ‘mqtt’).

Type:

str | None

is_online

Boolean indicating if the device is currently reachable.

Type:

bool | None

last_seen

Timestamp of the last communication.

Type:

str | None

firmware

The device’s firmware version.

Type:

str | None

serial

The device’s serial number.

Type:

str | None

coffee_count

The total number of coffees made.

Type:

int | None

command_map

A mapping of command aliases to their hex codes.

Type:

dict[str, Any]

property_map

A mapping of property aliases to their technical names.

Type:

dict[str, Any]

monitor_profile

Configuration for parsing monitor data.

Type:

cremalink.parsing.monitor.profile.MonitorProfile

extra

A dictionary for any other miscellaneous data.

Type:

dict[str, Any]

PARAM_CURRENT_PROFILE: ClassVar[int] = 1006

Param behind striker d286_mach_sett_profile — on striker it is the live selected-profile register (f2() asserts the envelope param id). On the Soul it answers 0x95 but does NOT track 0xA9 selections — verified 2026-10-25: display on profile 2 while the register still read 0. On non-striker it is only a boot-state hint, never truth (DECODED.md §335).

app_id_confirm_own_seconds: float = 5.0

a machine that still holds it republishes nothing, so the wait only costs time (seen live: no answer within 10 s). Real confirmations took 3–5 s.

Type:

Shorter wait when the cloud already shows our id

app_id_confirm_poll: float = 3.0
app_id_confirm_seconds: float = 10.0

How long to wait for the machine to confirm a registration, and the spacing of the checks while waiting (the app checks once after a few seconds; a few spaced reads keep the request count low).

app_id_refresh_min_seconds: float = 60.0

Inside the refresh window an explicit refresh frame is sent at most this often; every frame carrying our id extends the registration too (a command sent with an app’s id kept that registration alive).

app_id_refresh_seconds: float = 240.0

App-id registration (app_device_connected, striker machines): the machine drops a registration ~300 s after the last refresh, so a registration older than this is renewed instead of refreshed.

bean_systems() → list[BeanSystem][source]

Configured BeanAdapt slots with their user-assigned names.

Reads the republished d25X_beansystem_N blobs — the same ba f0 frames the app’s U(index)/0xBA slot reads produce (protocol.md §11 — on LAN the answers republish the d25x properties rather than answering data_response). Frame layout per DECODED G0/loadBeanSystems: id @[4], name UTF-16BE @[5..44] zero-stripped, flag bytes before the CRC (01 01 = configured+selected, 00 00 = empty slot — research.md R10). Unconfigured/undecodable slots are skipped.

beverage_catalog(*, fetch_priority: bool = True) → list[Beverage][source]

Brewable beverages for the selector, priority-ordered.

Built from the app’s model table (static — zero machine requests) filtered to the union of the profile’s drink-menu order and the command-map brew entries. The menu order costs one cached GET per profile; pass fetch_priority=False (standby / startup) to use only what is already cached, falling back to command-map order. Labels are resolved by callers (command-map name → Beverage.name → Beverage <id>).

brew(beverage_id: int, recipe: bytes | None = None, profile_slot: int | None = None, accessory: int = 0, *, overrides: Mapping[int, int] | None = None, action: int | None = None, params: RecipeParams | None = None) → Any[source]

Start brewing beverage_id — optionally with param overrides.

profile_slot=None resolves to the last 0xA9-acked profile (current_profile); recipe=None fetches the profile-scoped recipe bytes from the republished a6f0 property — both per the FR-001 coherence rule (frame names its profile, recipe must be that profile’s). do() uses the same live-recipe path, taking beverage id, action and trailer from the stored frame and falling back to the captured recipe when the machine does not republish one.

overrides ({param_id: raw_value}) is a one-off brew: the values are merged into the recipe TLVs and the machine’s stored recipe is untouched (the 0x83 PREPARE_BEVERAGE path — no SAVE_BEVERAGE write; research.md R1–R2). Overrides are validated against recipe_params() bounds; management tags and params absent from the recipe are rejected (ValueError). Passing params (a prior recipe_params() result) skips the second machine read and builds the frame straight from its values map. Bean-system beverages (0xC8–0xCD) send action | 0x80 and read the selected bean’s bs_recipe datapoint (research.md R10).

brew_entry(beverage_id: int) → dict[source]

The command-map entry carrying beverage_id ({} if none).

capabilities: dict[str, Any]
catalog_datapoints: list[str]
coffee_count: int | None = None
command_map: dict[str, Any]
configure() → None[source]

Configures the underlying transport.

current_profile: int = 0
custom_recipe_names() → dict[int, str][source]

Custom recipe names by beverage id, as the last cloud seed saw them.

declared_catalog() → RecipeCatalogue[source]

The advisory catalogue declared by the app’s model table.

Uses model_ref.recipe_declaration (an appModelId whose table entry stands in for this model) or else model_ref.appModelId. Empty when the table declares no recipes.

do(drink_name: str) → Any[source]

Executes a command by its friendly name (e.g., ‘espresso’).

Map entries are decoded fields, not captured frames:

  • power (standby/wake/session_refresh) builds via build_power.

  • beverage_id entries build via build_brew. With a recipe_datapoint the recipe is fetched live from the machine’s republished profile-scoped property (0xA6) and the brew fails closed if it is unavailable; entries without one use their stored recipe hex (models with no recipe catalogue), and a recipe-less stop frame uses the default recipe.

  • Entries holding only a raw command hex are sent verbatim.

Built frames go through the session gate.

Parameters:

drink_name – The name of the command to execute, as defined in the command_map.

Returns:

The response from the transport.

Raises:
  • ValueError – If the command name is not found in the device map.

  • ConnectionError – If no recipe is available for a brew entry.

dsn: str | None = None
extra: dict[str, Any]
favorite_beverages(profile_slot: int | None = None) → list[int] | None[source]

The profile’s favourite drinks in favourite order, or None.

Read from the cloud snapshot (dNNN_favorite_priority_<p>, family 0xAC) together with the catalogue seed — no machine request. None means unknown (no such datapoint, or no snapshot yet); an empty list means the profile has no favourites.

firmware: str | None = None
firmware_info() → dict[str, str][source]

Firmware versions — machine datapoint plus cloud module data.

machine: the machine’s own firmware (software_version datapoint, e.g. Striker_cb_demo 1.1.0 Oct 18 2022); wifi_module and wifi_module_updated_at: the Wi-Fi module’s firmware and when the cloud last updated it (cloud transport only). Keys whose value is unknown are left out.

On LAN the datapoint lands in the server’s property store only after the machine republishes it, so a miss triggers one request_property round-trip — verified: the Soul answers a software_version GET with the same string the cloud mirrors (protocol.md §14.7, captures/lan_software_version.json). Cloud transports cannot request properties and read the store only.

classmethod from_map(transport: DeviceTransport, device_map_path: str | None = None, *, event_logger: Logger | None = None, **kwargs) → Device[source]

Factory method to create a Device instance with a loaded device map.

If device_map_path is not provided, it attempts to find one using the device’s model.

Parameters:
  • transport – The communication transport to use.

  • device_map_path – Optional path to the device map JSON file.

  • **kwargs – Additional attributes to set on the Device instance.

Returns:

A configured Device instance.

get_commands() → list[str][source]

Returns a list of all available command names from the device map.

get_monitor() → MonitorView[source]

Retrieves and parses monitoring data into a structured, human-readable view.

Returns:

A MonitorView instance containing parsed status information.

get_monitor_frame() → MonitorFrame | None[source]

Decodes the raw monitor data into a MonitorFrame for low-level analysis.

Returns:

A MonitorFrame if decoding is successful, otherwise None.

get_monitor_snapshot() → MonitorSnapshot[source]

Retrieves the latest raw monitoring data from the transport.

get_profiles() → list[ProfileSlot][source]

Read the occupied profile slots (a4f0 blobs, profile-scoped).

The blobs are republished as dNNN_profiles_* (Soul) or dNNN_profile_name* (striker/ECAM452 over the cloud, which has no response mailbox for the 0xA4 fallback).

get_properties() → Any[source]

Fetches all available properties from the device.

get_property(name: str) → Any[source]

Fetches a single property by its alias or technical name.

Parameters:

name – The alias or name of the property to fetch.

Returns:

The value of the requested property.

get_property_aliases() → list[str][source]

Returns a list of all available property aliases from the device map.

get_setting_bits(*, refresh: bool = True) → dict[str, bool | None][source]

Read boolean bit settings as {key: on/off} (param 0x003F).

Same read strategy as get_settings(): republished dNNN 95-blobs first, 0x95 mailbox read for params without one. Capability-gated settings the map marks unsupported are omitted; unreadable params yield None — never a fabricated False.

refresh=False harvests only what is already in the property store — no request_property GETs and no 0x95 fallback. Used by the HA coordinator’s tracking poll: get_settings refreshes the store first, then this reads param 0x003F off it without queuing a second GET round (protocol.md §14.11 — republished dNNN is the WiFi read channel).

get_settings(*, hints: Collection[str] | None = None, keys: Collection[str] | None = None) → dict[str, int | None][source]

Read writable settings as {key: raw_option_index}.

Republished dNNN 95-blobs are read first; settings without a stored blob fall back to a 0x95 mailbox read. Capability- gated settings the map marks unsupported are omitted.

hints narrows the re-requested datapoints to names containing one of the hint substrings (datapoint_hint semantics) — the HA coordinator passes the entity-backed hints so the periodic refresh queues ~3 GETs instead of the full six (observed 2026-10-30: the full lane burst-starved interactive commands on the one-command-per-poll drain). keys narrows the evaluated settings to the given map keys — entities refreshing a single setting pass their own key so sibling keys don’t each sink into a seconds-long 0x95 fallback.

get_statistics() → StatisticsReport[source]

Fetch the machine’s usage statistics.

statistics_source == "native" maps page the 0xA2 table via the response mailbox; "cloud_counters" maps resolve logical counters against the transport’s property snapshot.

health() → Any[source]

Checks the health of the device connection.

ip: str | None = None
is_online: bool | None = None
lan_key: str | None = None
last_seen: str | None = None
machine_profile: MachineProfile | None = None
model: str | None = None
model_name: str | None = None

Display name from the device map (model_name key) — e.g. “PrimaDonna Soul”. None for maps that do not name the model.

model_ref: dict[str, Any]
monitor_bits: dict[str, list[str]]

exclude (bits the model does not have) and disabled_by_default (bits that may exist but are unverified). Empty = every documented bit applies.

Type:

Per-model monitor-bit policy from the device map

monitor_profile: MonitorProfile
n_profiles: int = 1
nickname: str | None = None
profile_poll_seconds: float = 30.0

Min seconds between param-0x03EE current-profile reads — callers may hook this to a ~1 s monitor cycle, far too chatty for a register that only changes on a profile switch.

property_map: dict[str, Any]
read_catalog(*, settle: float = 0.5) → RecipeCatalogue[source]

Build the recipe catalogue.

Machines that publish recipe datapoints are read per-name and parsed; maps without catalog_datapoints (striker models) get the model-table declaration instead.

recipe_beverage_order: list[int]
recipe_params(beverage_id: int, *, profile_slot: int | None = None, catalog: RecipeCatalogue | None = None) → RecipeParams[source]

Effective parameters + bounds for (profile, beverage).

Costs at most two machine reads and no catalogue sweep (protocol.md §13/§14.12, research.md R11): the recipe’s 0xB0 bounds (one GET, cached for the process) and the profile’s live 0xA6/bs_recipe values. A full catalog (from read_catalog()) may be supplied; its a6f0 profile records then serve as the values source. BeanAdapt beverages always live-read bs_recipe — the 6 bean slots share bev id 0xC8. Falls back to 0xB0 defaults (or the command-map stored recipe) with source="default" — never raises on a failed machine read. ValueError only for a beverage neither the model table nor the command map knows.

recipe_priority_loaded(profile_slot: int | None = None) → bool[source]

Whether the profile’s drink-menu order has been read already.

refresh_current_profile(*, force: bool = False) → int | None[source]

Refresh current_profile — striker reads 0x03EE, non-striker keeps the last-asserted profile.

On striker the register is read back whenever it is stale. On non-striker the app never asks the machine for the profile — 0xA9 is told-never-asked and 0x03EE does not follow panel/app selects, so the read only seeds the initial state (when current_profile is still 0/unknown) and can never overwrite a selection this process asserted or confirmed. Throttled to profile_poll_seconds; the read runs under the session gate (§14.8).

refresh_monitor() → Any[source]

Requests a refresh of the device’s monitoring data.

resolve_property(alias: str, default: str | None = None) → str[source]

Translates a property alias to its technical name using the property_map.

Parameters:
  • alias – The property alias to resolve.

  • default – A default value to return if the alias is not found.

Returns:

The resolved technical name, or the alias/default if not found.

response_poll: float = 0.25
response_timeout: float = 8.0
scheme: str | None = None
seed_catalog_from_properties(properties: Mapping[str, Any]) → int[source]

Fill the descriptor + menu-order caches from a bulk snapshot.

properties is {datapoint name: base64 value} — the cloud properties.json fetch (the app’s one-shot store sync, research.md R11). Only this map’s catalog_datapoints are considered and only the slow-changing families are taken: 0xB0 factory descriptors and 0xA8 menu orders. Per-profile 0xA6 recipe values are deliberately NOT seeded — the cloud copy can be stale (protocol.md §13) and a stale value would brew the wrong amount; those stay a live read. Returns the number of descriptors seeded (0 → the caller keeps the lazy LAN path).

select_bean_system(slot: int) → bool[source]

Switch the BeanAdapt bean system (session-gated 0xB9).

0xB9 is on protocol.md §13’s untested write list — it goes through the same gated path as the verified 0xA9 profile select: device_connected announce (_send_gated) → 0D 06 B9 F0 <slot> → optional <ok> ack (h.m(ok=(b5==0)), DECODED dispatcher). Like 0xA9 on non-striker the app has no read-back for the select — a nack-free send counts as applied; an explicit nack returns False.

select_profile(index: int) → bool[source]

Switch the active profile (session-gated 0xA9).

Wakes a standby machine first. On striker a matching positive ack is required (the a9 ack path updates EcamMachine.B). On non-striker the app treats 0xA9 as fire-and-retry — its connect storm sends it ~11× and the 2026-10-14 cloud capture shows zero acks, while the machine still applies the selection (DECODED.md “Current profile — never fetched on non-striker”). There is no machine-side read-back on Soul: after a nack-free send the asserted index becomes the truth, matching the app’s UserData.USER_PROFILE_SELECTED model.

selected_bean_slot() → int | None[source]

The machine’s currently selected BeanAdapt slot (1–6).

Bean-name blobs (d25X_beansystem_N, ba f0 family) end with two flag bytes: captured values mark the configured+selected bean 01 01 (byte 49 = configured, byte 50 = selected) vs 00 00 empty slots (research.md R10). Returns the flagged slot, else the first configured one, else None.

property selected_profile: int | None

The last acknowledged 0xA9 profile index, if any.

send_command(command: str) → Any[source]

Encodes and sends a raw hex command to the device via the transport.

Parameters:

command – The hex command string to send.

Returns:

The response from the transport.

send_frame(frame: bytes) → Any[source]

Encode a protocol frame (timestamp + optional app-id trailer) and send it via the transport’s command channel.

serial: str | None = None
session_refresh() → Any[source]

Refresh the write-gate session.

Non-striker machines re-announce device_connected; striker machines send the 84 0f 03 02 refresh frame.

set_setting(key: str, option_index: int) → bool[source]

Write a writable setting (session-gated 0x90 + ack/read-back).

Follows protocol.md §14.5: device_connected announce (via _send_gated()) → 0x90. §14.5 woke the machine for its test; by product decision this library never wakes it — configuration writes are attempted in standby as well: the machine processes data_request while in_standby (§14.8 — 0xA2 reads were answered there) and the official app exposes config changes in standby (only profile selection is gated). §14.5 confirmed the commits on the machine’s display and recorded no ack for them, so the ack is treated as optional: the write counts as committed when a read-back — mailbox answer or the republished dNNN backing property — shows the new value. An unconfirmed write is retried once with a fresh session announce — the machine rate-limits and drops frames under load (observed 2026-10-14).

Returns True when the write is confirmed and False when the machine nacked it or reports a different value. Raises ValueError for unknown keys/options and TimeoutError when neither an ack nor a read-back arrives.

set_setting_bit(key: str, on: bool) → bool[source]

Flip a boolean flag inside a shared param word (0x90 write).

Reads the param’s current u32 first — the flag is merged so unrelated bits survive (the app’s f0 write does exactly this; protocol.md §14.8). Standby does not block configuration writes: the machine processes data_request while in_standby and the app exposes these toggles there. An unreadable base value aborts with TimeoutError — a blind write could clobber other settings. Returns True on confirmed state, False when the machine reports a different value.

setting_levels: dict[str, int]

How many levels of a writable setting the model offers (map key setting_levels, e.g. {"temperature": 3}); unlisted settings offer their default_levels (or every option).

setting_options(key: str) → dict[int, str][source]

The options of a writable setting this model offers (index -> label).

The map’s setting_levels caps how many levels count, like the app, which offers as many coffee temperatures as the machine reports in param 194 (three on the Eletta Explore, four on the Soul).

settings_datapoints: list[str]
standby() → Any[source]

Send the machine to standby (84 0f 01 01).

statistics_datapoints: list[str]
statistics_source: str = 'native'
stop_brew() → Any[source]

Stop the running brew (the verified 83 f0 .. 02 frame).

transport: DeviceTransport
wake() → Any[source]

Wake the machine (84 0f 02 01).

write_confirm_seconds: float = 45.0

Post-write confirmation window — longer than response_timeout because the machine can commit 0x90 writes sluggishly under load (the app’s own re-read waits ~2 s; we budget generously and poll the republished property meanwhile). Over the cloud the republished value of a committed write took up to ~21 s to show (ECAM452), so a shorter window reported accepted writes as failed and resent them. A confirmed write still returns as soon as seen.

exception cremalink.domain.device.MachineStandbyError[source]

Bases: RuntimeError

The requested operation needs a machine that is switched on.

class cremalink.domain.device.RecipeParams(profile_slot: int, beverage_id: int, values: dict[int, int], source: Literal['profile', 'default'], bounds: dict[int, tuple[int, int, int]], bean_slot: int | None = None)[source]

Bases: object

Effective brew parameters for one (profile_slot, beverage_id).

values are raw machine units per param id — parsed from the live 0xA6 recipe blob (source="profile") or the 0xB0 descriptor defaults when the read fails (source="default"; a stored command-map recipe hex also counts as a non-live default). bounds are the 0xB0 (min, def, max) triples. bean_slot names the detected BeanAdapt slot whose bs_recipe datapoint fed the values for bean-system beverages (research.md R10).

bean_slot: int | None = None
beverage_id: int
bounds: dict[int, tuple[int, int, int]]
profile_slot: int
source: Literal['profile', 'default']
values: dict[int, int]