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:
objectOne configured BeanAdapt slot (
d25X_beansystem_Nba f0blob).slotis the bean-system index (1–6; slot 0 is the BeanAdapt ON/OFF feature flag, not a bean).nameis the user-assigned bean name (UTF-16BE at[5..44], zero-stripped — DECODEDG0/loadBeanSystems);selectedmarks the machine’s currently selected bean (flag byte, research.md R10 / protocol.md §11).
- 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:
objectRepresents 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.
- monitor_profile
Configuration for parsing monitor data.
- 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 answers0x95but does NOT track0xA9selections — 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_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_Nblobs — the sameba f0frames the app’sU(index)/0xBAslot reads produce (protocol.md §11 — on LAN the answers republish thed25xproperties rather than answeringdata_response). Frame layout per DECODEDG0/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-mapname→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=Noneresolves to the last 0xA9-acked profile (current_profile);recipe=Nonefetches the profile-scoped recipe bytes from the republisheda6f0property — 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 (the0x83PREPARE_BEVERAGEpath — noSAVE_BEVERAGEwrite; research.md R1–R2). Overrides are validated againstrecipe_params()bounds; management tags and params absent from the recipe are rejected (ValueError). Passingparams(a priorrecipe_params()result) skips the second machine read and builds the frame straight from itsvaluesmap. Bean-system beverages (0xC8–0xCD) sendaction | 0x80and read the selected bean’sbs_recipedatapoint (research.md R10).
- 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(anappModelIdwhose table entry stands in for this model) or elsemodel_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 viabuild_power.beverage_identries build viabuild_brew. With arecipe_datapointthe 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 storedrecipehex (models with no recipe catalogue), and a recipe-less stop frame uses the default recipe.Entries holding only a raw
commandhex 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.
- 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>, family0xAC) together with the catalogue seed — no machine request.Nonemeans unknown (no such datapoint, or no snapshot yet); an empty list means the profile has no favourites.
- firmware_info() dict[str, str][source]
Firmware versions — machine datapoint plus cloud module data.
machine: the machine’s own firmware (software_versiondatapoint, e.g.Striker_cb_demo 1.1.0 Oct 18 2022);wifi_moduleandwifi_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_propertyround-trip — verified: the Soul answers asoftware_versionGET 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 (
a4f0blobs, profile-scoped).The blobs are republished as
dNNN_profiles_*(Soul) ordNNN_profile_name*(striker/ECAM452 over the cloud, which has no response mailbox for the0xA4fallback).
- 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}(param0x003F).Same read strategy as
get_settings(): republisheddNNN95-blobs first,0x95mailbox read for params without one. Capability-gated settings the map marks unsupported are omitted; unreadable params yieldNone— never a fabricatedFalse.refresh=Falseharvests only what is already in the property store — norequest_propertyGETs and no0x95fallback. Used by the HA coordinator’s tracking poll:get_settingsrefreshes the store first, then this reads param0x003Foff it without queuing a second GET round (protocol.md §14.11 — republisheddNNNis 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
dNNN95-blobs are read first; settings without a stored blob fall back to a0x95mailbox read. Capability- gated settings the map marks unsupported are omitted.hintsnarrows the re-requested datapoints to names containing one of the hint substrings (datapoint_hintsemantics) — 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).keysnarrows 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-long0x95fallback.
- get_statistics() StatisticsReport[source]
Fetch the machine’s usage statistics.
statistics_source == "native"maps page the0xA2table via the response mailbox;"cloud_counters"maps resolve logical counters against the transport’s property snapshot.
- machine_profile: MachineProfile | None = None
- model_name: str | None = None
Display name from the device map (
model_namekey) — e.g. “PrimaDonna Soul”.Nonefor maps that do not name the model.
- monitor_bits: dict[str, list[str]]
exclude(bits the model does not have) anddisabled_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
- 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.
- 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_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
0xB0bounds (one GET, cached for the process) and the profile’s live0xA6/bs_recipevalues. A fullcatalog(fromread_catalog()) may be supplied; itsa6f0profile records then serve as the values source. BeanAdapt beverages always live-readbs_recipe— the 6 bean slots share bev id0xC8. Falls back to0xB0defaults (or the command-map stored recipe) withsource="default"— never raises on a failed machine read.ValueErroronly 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 reads0x03EE, 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 —
0xA9is told-never-asked and0x03EEdoes not follow panel/app selects, so the read only seeds the initial state (whencurrent_profileis still 0/unknown) and can never overwrite a selection this process asserted or confirmed. Throttled toprofile_poll_seconds; the read runs under the session gate (§14.8).
- 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.
- seed_catalog_from_properties(properties: Mapping[str, Any]) int[source]
Fill the descriptor + menu-order caches from a bulk snapshot.
propertiesis{datapoint name: base64 value}— the cloudproperties.jsonfetch (the app’s one-shot store sync, research.md R11). Only this map’scatalog_datapointsare considered and only the slow-changing families are taken:0xB0factory descriptors and0xA8menu orders. Per-profile0xA6recipe 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).0xB9is on protocol.md §13’s untested write list — it goes through the same gated path as the verified0xA9profile select:device_connectedannounce (_send_gated) →0D 06 B9 F0 <slot>→ optional<ok>ack (h.m(ok=(b5==0)), DECODED dispatcher). Like0xA9on non-striker the app has no read-back for the select — a nack-free send counts as applied; an explicit nack returnsFalse.
- 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
a9ack path updatesEcamMachine.B). On non-striker the app treats0xA9as 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’sUserData.USER_PROFILE_SELECTEDmodel.
- selected_bean_slot() int | None[source]
The machine’s currently selected BeanAdapt slot (1–6).
Bean-name blobs (
d25X_beansystem_N,ba f0family) end with two flag bytes: captured values mark the configured+selected bean01 01(byte 49 = configured, byte 50 = selected) vs00 00empty slots (research.md R10). Returns the flagged slot, else the first configured one, else None.
- 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.
- session_refresh() Any[source]
Refresh the write-gate session.
Non-striker machines re-announce
device_connected; striker machines send the84 0f 03 02refresh 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_connectedannounce (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 processesdata_requestwhilein_standby(§14.8 —0xA2reads 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 republisheddNNNbacking 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
Truewhen the write is confirmed andFalsewhen the machine nacked it or reports a different value. RaisesValueErrorfor unknown keys/options andTimeoutErrorwhen 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 (
0x90write).Reads the param’s current u32 first — the flag is merged so unrelated bits survive (the app’s
f0write does exactly this; protocol.md §14.8). Standby does not block configuration writes: the machine processesdata_requestwhilein_standbyand the app exposes these toggles there. An unreadable base value aborts withTimeoutError— a blind write could clobber other settings. ReturnsTrueon confirmed state,Falsewhen 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 theirdefault_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_levelscaps 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).
- transport: DeviceTransport
- write_confirm_seconds: float = 45.0
Post-write confirmation window — longer than
response_timeoutbecause the machine can commit0x90writes 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:
RuntimeErrorThe 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:
objectEffective brew parameters for one
(profile_slot, beverage_id).valuesare raw machine units per param id — parsed from the live0xA6recipe blob (source="profile") or the0xB0descriptor defaults when the read fails (source="default"; a stored command-maprecipehex also counts as a non-live default).boundsare the0xB0(min, def, max)triples.bean_slotnames the detected BeanAdapt slot whosebs_recipedatapoint fed the values for bean-system beverages (research.md R10).