cremalink.ecam.statistics module

ECAM usage statistics — native 0xA2 pages and cloud counters.

Native path (statistics_source: "native" maps): the machine exposes a sparse <id:2B> <u32> table through 0xA2 paged reads on data_request / data_response. Paging rules (live-verified): start at id 0 with count = 10; a page shorter than count is the end of the table; a timeout is never end-of-table — retry the same start_id with count - 1 (floor 1).

Cloud path (statistics_source: "cloud_counters" maps — striker machines without LAN): logical counters resolve through CLOUD_COUNTER_CANDIDATES name lists against the Ayla datapoint cache, parsed per the reference rules: plain ints pass through, JSON per-recipe objects sum to a total and keep their breakdown, anything unparseable becomes None (unknown — never invented).

cremalink.ecam.statistics.CLOUD_COUNTER_CANDIDATES: dict[str, list[str]] = {'aborted_beverages': ['d734_tot_bev_usage#bev_abort_cnt'], 'americano': ['d709_id6_americano'], 'brew_over_ice': ['d730_tot_id27_brew_over_ice'], 'caffe_latte': ['d712_id9_cafflatt'], 'cappuccino': ['d710_tot_id7_capp'], 'cappuccino_doppio': ['d716_id13_cappdoppio_p'], 'cappuccino_reverse': ['d717_id15_caprev'], 'coffee': ['d706_tot_id2_coffee'], 'coffee_pot': ['d720_tot_id23_coffee_pot'], 'cold_brew_beverages': ['d738_cold_brew_bev'], 'cortado': ['d727_id24_cortado'], 'descale_percentage': ['d512_percentage_to_deca'], 'descale_status': ['d825_descale_status'], 'descales': ['d552_cnt_calc_tot'], 'doppio': ['d708_tot_id5_doppio_p'], 'espresso': ['d705_tot_id1_espr'], 'espresso_macchiato': ['d714_id11_esprmacc'], 'filter_percentage': ['d513_percentage_usage_fltr'], 'filters': ['d554_cnt_filter_tot'], 'flat_white': ['d713_id10_flatwhite'], 'grounds_container_percentage': ['d510_ground_cnt_percentage'], 'grounds_counter': ['d551_cnt_coffee_fondi'], 'hot_milk': ['d715_id12_hotmilk'], 'hot_water': ['d718_id16_hotwater'], 'iced_beverages': ['d733_tot_bev_counters#tot_bev_b_iced,tot_bev_bw_iced,tot_bev_other_iced,tot_bev_w_iced'], 'latte_macchiato': ['d711_id8_lattmacc'], 'long_black': ['d728_id25_long_black'], 'long_coffee': ['d707_tot_id3_long'], 'mug_to_go': ['d729_id26_travel_mug'], 'tea': ['d719_id22_tea'], 'total_beverages': ['d700_tot_bev_b', 'd701_tot_bev_b+d733_tot_bev_counters#tot_bev_b_iced'], 'total_espresso': ['d704_tot_bev_espressi'], 'total_iced_milk_drinks': ['d733_tot_bev_counters#tot_bev_bw_iced,tot_bev_w_iced'], 'total_milk_drinks': ['d701_tot_bev_bw', 'd702_tot_bev_other#tot_bev_bw,tot_bev_w'], 'total_milk_only': ['d703_tot_bev_w'], 'total_other_beverages': ['d702_tot_bev_other#tot_bev_other', 'd702_tot_bev_other'], 'water_filter_quantity': ['d555_water_filter_qty'], 'water_hardness': ['d556_water_hardness'], 'water_total_quantity': ['d553_water_tot_qty']}

Logical counter → candidate Ayla datapoint names; the first name present on the device wins (Soul d700_* vs Eletta d701_* are not the same counters — see the reference integration’s const.py).

cremalink.ecam.statistics.CLOUD_COUNTER_PERCENTAGES = frozenset({'descale_percentage', 'filter_percentage', 'grounds_container_percentage'})

Logical counters that are percentages as published by the machine (maintenance levels), not lifetime counts.

cremalink.ecam.statistics.CLOUD_COUNTER_USED_UP = frozenset({'descale_percentage', 'filter_percentage'})

0 right after descaling or a filter change, 100 when it is due. Checked on an ECAM452: the machine’s display counts both up with use and drops them to 0 after the maintenance, and d513_percentage_usage_fltr went from 100 to 0 when the “replace water filter” alarm cleared. Despite its name, d512_percentage_to_deca is the used part too. How to show them (used or left) is up to the caller. The grounds container percentage is a fill level and not part of this set.

Type:

Maintenance percentages that count used upward

cremalink.ecam.statistics.STAT_LABELS: dict[int, tuple[str, str]] = {105: ('descales', 'count'), 106: ('water_total', 'l'), 108: ('filters', 'count'), 115: ('milk_cleans', 'count'), 3000: ('total_black', 'count'), 3001: ('total_milk_coffee', 'count'), 3002: ('total_other', 'count'), 3003: ('total_milk_only', 'count'), 3004: ('total_espressos', 'count'), 3005: ('espresso', 'count'), 3006: ('coffee', 'count'), 3007: ('long_coffee', 'count'), 3008: ('doppio', 'count'), 3009: ('americano', 'count'), 3010: ('cappuccino', 'count'), 3011: ('latte_macchiato', 'count'), 3012: ('caffe_latte', 'count'), 3013: ('flat_white', 'count'), 3014: ('espresso_macchiato', 'count'), 3015: ('hot_milk', 'count'), 3016: ('cappuccino_doppio', 'count'), 3017: ('cappuccino_mix', 'count'), 3018: ('hot_water', 'count'), 3019: ('tea', 'count'), 3020: ('coffee_pot', 'count'), 3021: ('choco', 'count'), 3025: ('tea_iced', 'count'), 43010: ('total_beverages', 'count')}

Official labels for the A2 sparse ids, verified against the machine’s own statistics display (z7.w$a categories / display-match corpus). a2_id -> (label, unit); unit "l" means value = raw / 2000 (half-millilitres → litres per z7.u.a).

class cremalink.ecam.statistics.StatisticEntry(a2_id: int, raw: int, label: str | None, value: int | float, unit: str | None)[source]

Bases: object

One interpreted A2 statistic.

a2_id: int
label: str | None
raw: int
unit: str | None
value: int | float
class cremalink.ecam.statistics.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: object

Result of one statistics fetch.

breakdowns: dict[str, dict]

per-counter JSON breakdowns (Eletta aggregated counters)

cloud_counters: dict[str, int | float | None]

logical cloud counters when source == “cloud_counters”

complete: bool = False
data_updated_at: float | None = None

when the cloud last received a statistics datapoint from the machine (epoch); None where the transport has no per-datapoint times

entries: dict[int, StatisticEntry]
fetched_at: float
source: str
cremalink.ecam.statistics.candidate_datapoint(candidate: str) → str[source]

Datapoint name of a counter candidate.

A candidate is a datapoint name, optionally followed by #key,key to count only those keys of a JSON object datapoint, and optionally joined with + to further parts that are added to the counter (the first part names the candidate’s datapoint).

cremalink.ecam.statistics.counter_breakdown(val: Any) → dict | None[source]

Return the per-recipe JSON breakdown of a counter, else None.

cremalink.ecam.statistics.decode_a2_page(frame: bytes | bytearray) → list[tuple[int, int]][source]

0xA2/0xA1 statistics page → [(id, raw_u32), …].

Records are 6 bytes <id:2B> <u32:4B> starting at payload offset 2 (APK h.u parser); trailing partial records are ignored.

cremalink.ecam.statistics.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 labelled StatisticsReport.

Unlabeled ids pass through with label=None — they are real machine data, just not display-named.

cremalink.ecam.statistics.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.statistics.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_LABELS unit l); checked on an Eletta Explore: raw 1782545 = 891 l on its display.

cremalink.ecam.statistics.resolve_cloud_counters(properties: dict[str, Any]) → dict[str, int | float | None][source]

Resolve logical counters against the property/dp cache.

properties maps datapoint name → value (or a {"value": …} wrapper). First present candidate wins; absent candidates produce no key — an unresolved counter is “absent”, not None (FR-016d).