cremalink.ecam.catalog module

Machine recipe catalogue — parse the recipe-bearing blob families.

Ported from delonghi_coffeelink’s catalog.py (same authorial grammar, pure Python — no HA, no I/O).

Every recipe-bearing datapoint is a self-describing binary blob:

d0 <len> <family 2B> [<profile 1B>] <bevid 1B> <TLV params…> <crc16>

The CRC is the same CRC16 AUG-CCITT the command builder uses, so a blob can be proved intact before anything is derived from it. Families:

family

meaning

b0 f0

factory descriptor — the capability schema (min/default/max)

a6 f0

per-profile instance — the current value of each parameter

a8 f0

a per-profile ordered short list of beverage ids

a4 f0

profile names (UTF-16BE, user-entered)

aa f0

custom-recipe slot names

ba f0

bean-system names

Rules that make it parseable without per-beverage special cases:

  • TLV: tags 0x01, 0x09 and 0x0F carry a 16-bit big-endian value, every other tag carries 8 bits. In a b0f0 descriptor the same tags carry a triple (min, default, max).

  • Parse by family, never by property name. Datapoint numbering differs per model; the blob header is identical.

Deliberate refusals (a beverage that lies is worse than one missing):

  • A blob failing any gate (prefix, declared length, CRC) is unreadable, never absent.

  • A TLV walk leaving a trailing byte returns None — a partial parse could build a wrong brew command, so the whole walk is refused.

  • a8f0 lists are per-profile recency orderings, NOT the brewable set.

class cremalink.ecam.catalog.Beverage(bev_id: int, kind: str, declared: bool = False, ranges: dict = <factory>, profiles: dict = <factory>, in_priority_list: bool | None = None, priority_position: dict = <factory>, defined: bool | None = None, profiles_differ: bool = False, off_default: dict | None = None, source_properties: tuple = (), name: str | None = None, ingredients: tuple[int, ...]=(), use_for_custom: bool | None = None)[source]

Bases: object

One catalogue beverage.

bev_id: int
declared: bool = False
defined: bool | None = None
in_priority_list: bool | None = None
ingredients: tuple[int, ...] = ()
kind: str
name: str | None = None
off_default: dict | None = None
priority_position: dict
profiles: dict
profiles_differ: bool = False
ranges: dict
source_properties: tuple = ()
use_for_custom: bool | None = None
cremalink.ecam.catalog.CUSTOM_SLOT_IDS = frozenset({230, 231, 232, 233, 234, 235})

Beverage-id ranges that are not one of the built-in drinks.

class cremalink.ecam.catalog.RecipeCatalogue(fingerprint: tuple, source: str, beverages: dict[int, ~cremalink.ecam.catalog.Beverage], priority_lists: dict[int, list[int]], names: dict[str, dict[int, str]], stats: dict, favorite_lists: dict[int, list[int]] = <factory>)[source]

Bases: object

The parsed recipe catalogue — advisory only; brew never depends on it.

beverages: dict[int, Beverage]
favorite_lists: dict[int, list[int]]

per-profile favourites (0xAC), in the machine’s favourite order

fingerprint: tuple
names: dict[str, dict[int, str]]
priority_lists: dict[int, list[int]]
source: str
stats: dict
cremalink.ecam.catalog.TEXT_BLOB_FAMILIES = frozenset({b'\xa4\xf0', b'\xaa\xf0', b'\xba\xf0'})

Families carrying user-entered names — diagnostics redact their content.

cremalink.ecam.catalog.WIDE_TAGS = frozenset({1, 9, 15})

TLV tags whose value is 16-bit big-endian; every other tag is 8-bit.

cremalink.ecam.catalog.blob_family(value: Any) → bytes | None[source]

The family bytes of a machine blob, read without decoding all of it.

cremalink.ecam.catalog.build_catalog(properties: dict) → RecipeCatalogue[source]

Build the machine’s beverage catalogue from property values.

cremalink.ecam.catalog.build_declared_catalog(model: str | None) → RecipeCatalogue[source]

Build an advisory catalogue from the app’s model table.

Carries what the table declares — beverage ids, names and the parameter ids each drink uses — and nothing the machine alone knows: no min/default/max ranges and no per-profile values. Use it when the machine publishes no recipe datapoints (striker models) or to cross-check a machine-built catalogue with diff_declared().

cremalink.ecam.catalog.catalog_beverage_ids(catalog: RecipeCatalogue | None) → set[int][source]

Every beverage id the machine declared, whatever its kind.

cremalink.ecam.catalog.decode_blob(value: Any) → dict | None[source]

Classify one datapoint value as a machine blob, or None.

Three gates: 0xd0 prefix, declared length, CRC. The length gate is declared <= len(raw): the machine appends a 4-byte timestamp to some datapoints, and strict equality misgrades those live channels as truncated.

cremalink.ecam.catalog.decode_custom_names(payload: bytes) → dict[int, str][source]

Slot → name from an aa f0 custom-recipe names payload.

Layout (ECAM452 cloud d053_custom_name_13 / d054_custom_name_46): <first slot> <last slot> then per slot 20 bytes UTF-16BE name and one icon byte. Slots without a readable name are skipped.

cremalink.ecam.catalog.decode_text(payload: bytes) → str | None[source]

Decode the first UTF-16BE name in a text blob payload.

cremalink.ecam.catalog.diff_declared(machine: RecipeCatalogue, declared: RecipeCatalogue) → dict[source]

Compare a machine-built catalogue with the model-table declaration.

A non-empty result flags model-map drift (wrong recipe_declaration or a firmware that changed the drink set) — not a catalogue failure.

cremalink.ecam.catalog.fingerprint(properties: dict) → tuple[source]

A change-detection key over catalogue datapoints, and only those.

cremalink.ecam.catalog.iter_blobs(properties: dict) → Iterator[tuple[str, dict]][source]

Yield (property_name, decoded_blob) for every machine blob.

Blobs inside a JSON bundle datapoint are yielded one by one as <property_name>/<key>.

cremalink.ecam.catalog.load_model_declaration(model: str | None) → dict | None[source]

The app’s own recipe declaration for an appModelId, or None.

Source: MachinesModels.json (Coffee Link 4.9.6) — shipped as resources/model_recipes.json for the Wi-Fi families only (PD_SOUL, PD_SOUL_BETTER, STRIKER_BEST). STRIKER_GOOD declares no recipes in the table, so it has no entry.

cremalink.ecam.catalog.parse_tlv(payload: bytes) → dict[int, int] | None[source]

Parse a TLV parameter payload; None if it does not consume exactly.

cremalink.ecam.catalog.parse_triples(payload: bytes) → dict[int, tuple[int, int, int]] | None[source]

Parse a factory descriptor into tag -> (min, default, max).