cremalink.ecam.builder module
Parametric ECAM command-frame construction.
Wire frame layout (verified against the decompiled Coffee Link builders and live LAN captures):
<0x0D> <len:1B> <family:2B> <payload…> <crc16:2B>
len counts the bytes from the length byte itself through the CRC —
i.e. len == total_frame_length - 1; it is derived from emitted
content so variable-length payloads are supported (FR-003). The CRC is
crc16_ccitt (init 0x1D0F, poly 0x1021) over every byte
preceding it (FR-004/008).
Transport encoding appends a 4-byte big-endian unix timestamp (never CRC-covered) and, on striker machines, the registered 4-byte app-id trailer (FR-005/007).
All functions are pure: no I/O, no network, no Home Assistant imports.
- cremalink.ecam.builder.BREW_DROP_TAGS = frozenset({8})
Param ids excluded from a brew recipe by the app’s
O()builder: param 8 (DUExPER) is always dropped; theE0predicate then keeps only ids < 23 or in {27, 28, 31, 33, 38, 39} (INDEX_LENGTH, ACCESSORIO, ICED, MUG_ADJUST, INTENSITY, RINSE). On the verified Soul corpus the two rules together remove tags {0x08, 0x19}.
- class cremalink.ecam.builder.BrewAction(*values)[source]
-
Action/strength byte of a
0x83brew frame.- START = 1
- STOP = 2
- cremalink.ecam.builder.DEFAULT_RECIPE = b'\x0f\x00\xfa\x1b\x01'
250 ml, temp index 1). The trailing brew trailer byte is NOT part of the recipe —
build_brewappends(profile_slot<<2)|accessoryitself. Opaque bytes — brews are normally built from the machine’s own0xA6recipe or a command-map entry; this is only a safe fallback.- Type:
Default recipe TLVs (captured hot-water command
- class cremalink.ecam.builder.PowerCommand(*values)[source]
-
Payloads of the
0x84 0x0Fpower/session family (verified).- SESSION_REFRESH = b'\x03\x02'
- STANDBY = b'\x01\x01'
- WAKE = b'\x02\x01'
- cremalink.ecam.builder.REQUEST_NAMES = {117: 'monitor', 131: 'brew', 132: 'power', 144: 'write_param', 149: 'read_param', 161: 'read_extended', 162: 'statistics', 164: 'profile_names', 165: 'profile_names_write', 166: 'recipe_values', 168: 'priority_list', 169: 'profile_select', 170: 'recipe_names', 176: 'factory_descriptor', 185: 'bean_select', 186: 'bean_system', 232: 'striker_handshake'}
Human-readable labels for request ids (diagnostics/logging).
- cremalink.ecam.builder.brew_param_included(param_id: int) bool[source]
The app-side
E0predicate: which recipe params go on the wire.
- cremalink.ecam.builder.build_bean_select(slot: int, profile: MachineProfile) bytes[source]
0D 06 B9 F0 <slot>— bean-system select (APKQ0``→``g0/selectBeanSystem/getPacketForSelectBean, DECODED.md).This is a gated write: the session must be announced first (protocol.md §14.5). The frame sits on §13’s untested list — structured after the verified
0xA9path, ack semanticsok=(b5==0)per the DECODED0xB9``→``h.mdispatch.
- cremalink.ecam.builder.build_bean_system(index: int, profile: MachineProfile) bytes[source]
0D 06 BA F0 <index>— bean-system slot read (APKU).
- cremalink.ecam.builder.build_brew(beverage_id: int, action: int | BrewAction, recipe: bytes | bytearray | Iterable[int], profile: MachineProfile, *, profile_slot: int = 0, accessory: int = 0) bytes[source]
Build a
0x83brew frame.0D LEN 83 F0 <bev> <action> <recipe…> <(profile_slot<<2)|accessory>— the frame names its profile in the trailer byte; the recipe bytes must be that same profile’s values (0xA6reads are profile-scoped).
- cremalink.ecam.builder.build_brew_params(beverage_id: int, action: int | BrewAction, params: Mapping[int, int], profile: MachineProfile, *, profile_slot: int = 0, accessory: int = 0) bytes[source]
Build a
0x83brew frame straight from a{param_id: value}map.Encodes each param as
<id><value>— 1 byte, or big-endian u16 forWIDE_TAGS— after applying the app’sE0filter (brew_param_included; id 8 dropped). Bean-system beverages (beverage_id0xC8–0xCD) sendaction | 0x80— the APKl0fromBeanSystemflag, which also retains param 2 for bev 200 (research.md R2/R10). Byte-identical tobuild_brew()given the same effective TLV set.
- cremalink.ecam.builder.build_factory_descriptor(beverage_id: int, profile: MachineProfile) bytes[source]
0D 06 B0 F0 <bev>— min/default/max descriptor read (APKY0).
- cremalink.ecam.builder.build_handshake_blob() bytes[source]
45 DA 37 88 34 EB AF FF FF FA+ CRC — non-striker session handshake blob (APKs0()/buildHandshakeBlob).No
0x0Dheader — the CRC covers the 10 payload bytes exactly like the app’scrc16(which iterateslen-2). The app’s connect sequence isdevice_connected→ this blob → traffic; without it the machine served property republishes and0xA2but ignored session commands (0x95silent,0x90acked-not- committed,0xA9unacked — observed 2026-10-14/25, §14.8).
- cremalink.ecam.builder.build_monitor_request(profile: MachineProfile) bytes[source]
0D 05 <monitor_id> 0F— monitor snapshot request (APKV).
- cremalink.ecam.builder.build_power(kind: PowerCommand, profile: MachineProfile) bytes[source]
Build an
0x84 0x0Fpower/session frame.
- cremalink.ecam.builder.build_priority_list(profile_slot: int, profile: MachineProfile) bytes[source]
0D 06 A8 F0 <prof>— per-profile ordered beverage list.
- cremalink.ecam.builder.build_profile_names(first: int, count: int, profile: MachineProfile) bytes[source]
0D 07 A4 F0 <first> <count>— profile-name read (APKt0).
- cremalink.ecam.builder.build_profile_select(profile_slot: int, profile: MachineProfile) bytes[source]
0D 06 A9 F0 <prof>— profile select (verified live).This is a gated write: the session must be announced first.
- cremalink.ecam.builder.build_read(request_id: int, args: bytes | bytearray | Iterable[int] = b'', profile: MachineProfile | None = None, *, flag: int | None = None) bytes[source]
Build a read-style request frame for the given request id.
argsis the raw payload after the flag byte. Flags:0x0Ffor the statistics family,0xF0(answer wanted) elsewhere — both verified on live LAN. Use thebuild_read_*helpers below for the structured payloads.
- cremalink.ecam.builder.build_read_block(param_id: int, count: int, profile: MachineProfile) bytes[source]
0D 08 <0x95|0xA1> <flag> <param:2B> <count>— APKr0block read.count > 4goes out as the0xA1extended read; the machine normalises the answer back to a0x95param list.
- cremalink.ecam.builder.build_read_param(param_id: int, profile: MachineProfile) bytes[source]
0D 08 95 <flag> <param:2B> <qty=1>— single parameter read.The app’s
buildParamRead(protocol.md §8) always carries the qty byte; the legacy qty-less len-7 form is only tolerated by the machine (answered sporadically — see §14.8’s 2026-10-14 captures where len-7 reads were dropped while0D 08app reads answered). Delegates tobuild_read_block()withcount=1, which emits the identical wire frame.
- cremalink.ecam.builder.build_read_params(first_param: int, last_param: int, profile: MachineProfile) bytes[source]
0D 09 95 <flag> <first:2B> <last:2B>— param range read (captured).
- cremalink.ecam.builder.build_recipe_names(first: int, count: int, profile: MachineProfile) bytes[source]
0D 07 AA F0 <first> <count>— custom recipe-name read (APKv0).
- cremalink.ecam.builder.build_recipe_values(profile_slot: int, beverage_id: int, profile: MachineProfile) bytes[source]
0D 07 A6 F0 <prof> <bev>— profile-scoped recipe read (APKM0).
- cremalink.ecam.builder.build_statistics_page(start_id: int, count: int, profile: MachineProfile) bytes[source]
0D 08 A2 0F <start_id:2B> <count:1B>— statistics page read.
- cremalink.ecam.builder.build_striker_handshake(profile: MachineProfile) bytes[source]
0D 06 E8 F0 00— striker session handshake (APKz0).
- cremalink.ecam.builder.build_write_param(param_id: int, value: int, profile: MachineProfile, *, flag: int | None = None) bytes[source]
Build a
0x90parameter-write frame.0D 0B 90 <flag> <param:2B> <u32:4B>— byte-identical to the app’sn0()builder: flag0xF0forparam >= 1000, else0x0F(protocol.md §14.5 verified90 0F 00 3E …committing under thedevice_connectedsession announce; a90 F0write without the announce only staged transiently).flagstays overridable.
- cremalink.ecam.builder.describe_request_frame(blob: bytes | bytearray) dict[source]
Summarize an outbound (
0x0D) request frame for logging.Best-effort and never raises: the returned dict always has a
framehex string; a well-formed request addsrequest_id,request(label fromREQUEST_NAMES),flag,params(hex) andcrc_ok. Transport trailers (timestamp/app-id) are trimmed first.
- cremalink.ecam.builder.encode_for_transport(frame: bytes | bytearray, profile: MachineProfile, *, timestamp: int | None = None, app_id: bytes | bytearray | None = None, raw: bool = False) str[source]
Base64-encode
frame + <ts:4B BE> [+ <app_id:4B>]for the wire.The timestamp is never CRC-covered; the striker app-id trailer follows it (FR-004/005/007).
raw=Trueskips frame validation — the non-strikers0()handshake blob is a validdata_requestpayload that carries no0x0Dheader (§14.8).
- cremalink.ecam.builder.merge_recipe_params(recipe: bytes | bytearray | Iterable[int], overrides: Mapping[int, int]) bytes[source]
Splice override values into a brew-ready recipe TLV byte string.
Existing entries keep their order and width (u16 per
WIDE_TAGS— mirrored fromcatalogto avoid an import cycle); override tags absent fromrecipeare appended. Pure — filtering for the wire (brew_param_included) is the caller’s job, as with the app’sO()builder (research.md R1–R2).