cremalink.ecam package
Transport-independent ECAM protocol layer.
Pure Python: frame builders, answer parsers, machine dialect profiles,
the write-gate session helper, native 0xA2 statistics, profile-name
blobs, writable settings and the recipe catalogue. No network or Home
Assistant imports live here — callers hand transports in.
- class cremalink.ecam.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:
objectOne catalogue beverage.
- class cremalink.ecam.BrewAction(*values)[source]
-
Action/strength byte of a
0x83brew frame.- START = 1
- STOP = 2
- class cremalink.ecam.MachineProfile(key: str, command_property: str, trailer: str, session: str, monitor_request_ids: frozenset[int], profile_entry_size: int, grinder_scale: float)[source]
Bases:
objectDialect declaration a device binds to via
machine_profile.Fields:
key: stable identifier ("non_striker"/"striker").command_property: property frames are written to (data_requestvsapp_data_request).trailer: transport suffix after the timestamp (NONEtimestamp only,APP_ID4-byte registered app id).session: write-gate mechanism (plain unix timestamp write todevice_connectedvs0xE8handshake +84 0f 03 02registration).monitor_request_ids: request ids that carry monitor frames (the device map’smonitor_profilestays authoritative per data-model.md; this is informational).profile_entry_size: bytes per profile entry in0xA4blobs (21 non-striker / 22 striker incl. mug byte).grinder_scale: multiplier applied to bean-system grinder values on striker (write*2, read/2per APKO0/G0).
- class cremalink.ecam.PowerCommand(*values)[source]
-
Payloads of the
0x84 0x0Fpower/session family (verified).- SESSION_REFRESH = b'\x03\x02'
- STANDBY = b'\x01\x01'
- WAKE = b'\x02\x01'
- class cremalink.ecam.ProfileSlot(index: int, name: str, icon: int, mug: int | None = None)[source]
Bases:
objectOne occupied machine profile slot.
- class cremalink.ecam.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:
objectThe parsed recipe catalogue — advisory only; brew never depends on it.
- class cremalink.ecam.SessionGate(profile: ~cremalink.ecam.machine_profiles.MachineProfile, announce: ~collections.abc.Callable[[], ~typing.Any], *, refresh_seconds: int = 240, clock: ~collections.abc.Callable[[], float] = <built-in function time>)[source]
Bases:
objectTracks session freshness and performs announces on demand.
Constructed per device/transport — per-entry state only.
announceis the profile-appropriate way to (re)open the session:non-striker:
write_property(connected_property, unix_ts)striker: the
0xE8handshake +84 0f 03 02registration callback (run once), returning the registered app-id bytes.
- announced_at
unix time of the last successful announce (0 = never).
- ensure_fresh(now: float | None = None) bool[source]
Announce the session when stale. Returns True iff an announce ran.
- invalidate() None[source]
Force the next gated write to re-announce (e.g. after an ack indicated the write was ignored).
- class cremalink.ecam.StatisticEntry(a2_id: int, raw: int, label: str | None, value: int | float, unit: str | None)[source]
Bases:
objectOne interpreted A2 statistic.
- class cremalink.ecam.StatisticsReport(source: str, entries: dict[int, ~cremalink.ecam.statistics.StatisticEntry]=<factory>, complete: bool = False, fetched_at: float = <factory>, data_updated_at: float | None = None, cloud_counters: dict[str, int | float | None]=<factory>, breakdowns: dict[str, dict]=<factory>)[source]
Bases:
objectResult of one statistics fetch.
- cloud_counters: dict[str, int | float | None]
logical cloud counters when source == “cloud_counters”
- data_updated_at: float | None = None
when the cloud last received a statistics datapoint from the machine (epoch);
Nonewhere the transport has no per-datapoint times
- entries: dict[int, StatisticEntry]
- class cremalink.ecam.WritableSetting(key: str, param_id: int, options: dict[int, str], capability: str, datapoint_hint: str = '', default_levels: int | None = None)[source]
Bases:
objectA capability-gated machine setting writable via
0x90.
- cremalink.ecam.answer_flag(frame: bytes | bytearray) int[source]
The echoed request flag —
byte[3]of the0xD0blob.
- cremalink.ecam.answer_id(frame: bytes | bytearray) int[source]
The echoed request id —
byte[2]of the0xD0blob.
- cremalink.ecam.blob_family(value: Any) bytes | None[source]
The family bytes of a machine blob, read without decoding all of it.
- cremalink.ecam.brew_param_included(param_id: int) bool[source]
The app-side
E0predicate: which recipe params go on the wire.
- cremalink.ecam.build_bean_system(index: int, profile: MachineProfile) bytes[source]
0D 06 BA F0 <index>— bean-system slot read (APKU).
- cremalink.ecam.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.build_catalog(properties: dict) RecipeCatalogue[source]
Build the machine’s beverage catalogue from property values.
- cremalink.ecam.build_factory_descriptor(beverage_id: int, profile: MachineProfile) bytes[source]
0D 06 B0 F0 <bev>— min/default/max descriptor read (APKY0).
- cremalink.ecam.build_monitor_request(profile: MachineProfile) bytes[source]
0D 05 <monitor_id> 0F— monitor snapshot request (APKV).
- cremalink.ecam.build_power(kind: PowerCommand, profile: MachineProfile) bytes[source]
Build an
0x84 0x0Fpower/session frame.
- cremalink.ecam.build_priority_list(profile_slot: int, profile: MachineProfile) bytes[source]
0D 06 A8 F0 <prof>— per-profile ordered beverage list.
- cremalink.ecam.build_profile_names(first: int, count: int, profile: MachineProfile) bytes[source]
0D 07 A4 F0 <first> <count>— profile-name read (APKt0).
- cremalink.ecam.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.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.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.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.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.build_recipe_names(first: int, count: int, profile: MachineProfile) bytes[source]
0D 07 AA F0 <first> <count>— custom recipe-name read (APKv0).
- cremalink.ecam.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.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.build_striker_handshake(profile: MachineProfile) bytes[source]
0D 06 E8 F0 00— striker session handshake (APKz0).
- cremalink.ecam.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.catalog_beverage_ids(catalog: RecipeCatalogue | None) set[int][source]
Every beverage id the machine declared, whatever its kind.
- cremalink.ecam.counter_breakdown(val: Any) dict | None[source]
Return the per-recipe JSON breakdown of a counter, else
None.
- cremalink.ecam.decode_a2_page(frame: bytes | bytearray) list[tuple[int, int]][source]
0xA2/0xA1statistics page →[(id, raw_u32), …].Records are 6 bytes
<id:2B> <u32:4B>starting at payload offset 2 (APKh.uparser); trailing partial records are ignored.
- cremalink.ecam.decode_blob(value: Any) dict | None[source]
Classify one datapoint value as a machine blob, or
None.Three gates:
0xd0prefix, declared length, CRC. The length gate isdeclared <= len(raw): the machine appends a 4-byte timestamp to some datapoints, and strict equality misgrades those live channels as truncated.
- cremalink.ecam.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.fingerprint(properties: dict) tuple[source]
A change-detection key over catalogue datapoints, and only those.
- cremalink.ecam.interpret(entries: Iterable[tuple[int, int]], *, source: str = 'native', complete: bool = False, fetched_at: float | None = None) StatisticsReport[source]
Fold
(a2_id, raw)pairs into a labelledStatisticsReport.Unlabeled ids pass through with
label=None— they are real machine data, just not display-named.
- cremalink.ecam.is_sync_timeout(frame: bytes | bytearray) bool[source]
0xE1— machine reports busy/sync-timeout; abort the pending read.Tolerant by design: a blob that does not parse cannot be an abort.
- cremalink.ecam.parse_a9_ack(frame: bytes | bytearray) tuple[int, bool][source]
0xA9profile-select ack →(profile, ok)—<prof> <ok=00>.
- cremalink.ecam.parse_counter_value(val: Any) int | None[source]
Return the integer state for a counter value, or
None.Plain integers pass through; a JSON object is summed over its integer sub-values; anything else yields
None(unknown).
- cremalink.ecam.parse_profile_names(blob: bytes | bytearray, profile: MachineProfile) list[ProfileSlot][source]
Parse one
a4f0envelope into occupiedProfileSlots.Never raises on malformed input — unparseable content yields
[](callers treat a missing page as “no slots”, never a crash).
- cremalink.ecam.parse_settings(blob: bytes | bytearray) dict[int, int][source]
Parse a
0x95answer/stored blob into{param_id: raw_u32}.Shape-tolerant: short stored values, full republish blobs (descriptor tail ignored), ack echoes (no values) and all-zero unknown-parameter blobs are all handled without raising.
- cremalink.ecam.parse_simple_ack(frame: bytes | bytearray) tuple[int, bool][source]
Generic
<ok:1B>ack — used by0x83/0xA5/0xAB/0xB9/0xBB/0xE2answers. Returns(answer_id, ok).
- cremalink.ecam.parse_tlv(payload: bytes) dict[int, int] | None[source]
Parse a TLV parameter payload;
Noneif it does not consume exactly.
- cremalink.ecam.parse_triples(payload: bytes) dict[int, tuple[int, int, int]] | None[source]
Parse a factory descriptor into
tag -> (min, default, max).
- cremalink.ecam.parse_water_volume_liters(val: Any) float | None[source]
Convert a water counter (half-millilitres,
raw / 2000) to litres.Same unit as the app’s LAN statistics (
STAT_LABELSunitl); checked on an Eletta Explore: raw 1782545 = 891 l on its display.
- cremalink.ecam.parse_write_ack(frame: bytes | bytearray) tuple[int, bool][source]
0x90ack →(param_id, ok)— payload<param:2B> <ok:1B>.Ack byte
0x00means the write committed (b==0⇒ success per the APK dispatcher).
- cremalink.ecam.profile_from_map(map_data: dict[str, Any], *, logger_: Logger | None = None) MachineProfile[source]
Bind the device map’s
machine_profilefield to a preset.A missing field binds
NON_STRIKERwith a logged warning (the verified Soul behaviour). An unrecognized value raisesValueError— failing closed is required because command construction on the wrong dialect produces frames the machine ignores (FR-006).
- cremalink.ecam.resolve_cloud_breakdowns(properties: dict[str, Any]) dict[str, dict][source]
Per-counter JSON breakdowns, keyed by logical counter.
- cremalink.ecam.resolve_cloud_counters(properties: dict[str, Any]) dict[str, int | float | None][source]
Resolve logical counters against the property/dp cache.
propertiesmaps datapoint name → value (or a{"value": …}wrapper). First present candidate wins; absent candidates produce no key — an unresolved counter is “absent”, notNone(FR-016d).
- cremalink.ecam.trim_frame(blob: bytes | bytearray) bytes[source]
Cut a received blob to its declared frame, dropping any trailer.
data_response/republished datapoints append a 4-byte timestamp after the CRC — the trailing bytes are transport metadata, not frame.
- cremalink.ecam.verify_frame(frame: bytes | bytearray) bool[source]
Validate a wire frame’s length byte and CRC.
Bytes beyond the declared length (e.g. the datapoint timestamp trailer) are ignored. Returns
Falseon any structural violation — never raises.
Submodules
- cremalink.ecam.answers module
- cremalink.ecam.builder module
BREW_DROP_TAGSBrewActionDEFAULT_RECIPEPowerCommandREQUEST_NAMESbrew_param_included()build_bean_select()build_bean_system()build_brew()build_brew_params()build_factory_descriptor()build_handshake_blob()build_monitor_request()build_power()build_priority_list()build_profile_names()build_profile_select()build_read()build_read_block()build_read_param()build_read_params()build_recipe_names()build_recipe_values()build_statistics_page()build_striker_handshake()build_write_param()describe_request_frame()encode_for_transport()merge_recipe_params()trim_frame()verify_frame()
- cremalink.ecam.catalog module
- cremalink.ecam.machine_profiles module
- cremalink.ecam.monitor_bits module
- cremalink.ecam.params module
- cremalink.ecam.profiles module
- cremalink.ecam.session module
- cremalink.ecam.settings module
- cremalink.ecam.statistics module