pybragerone.models.param

Runtime-light parameter store.

This module intentionally contains only the minimal structures and logic needed to store and update raw parameter values (e.g. P5.s0).

All asset-driven behavior (mappings, menu grouping, i18n, computed STATUS rule evaluation, and rich “describe” helpers) is implemented in pybragerone.models.param_resolver.ParamResolver.

Classes

ParamFamilyModel(**data)

One parameter "family" (e.g., P4 index 1) collecting channels: v/s/u/n/x...

ParamStore(**data)

Store of live parameter values.

class pybragerone.models.param.ParamFamilyModel(**data: Any)[source]

Bases: BaseModel

One parameter “family” (e.g., P4 index 1) collecting channels: v/s/u/n/x…

Parameters:
channels: dict[str, Any]
get(chan: str, default: Any = None)[source]

Get raw channel value, or default if not present.

Return type:

Any

Parameters:
idx: int
model_config: ClassVar[ConfigDict] = {'frozen': False, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

pool: str
set(chan: str, value: Any)[source]

Set raw channel value.

Return type:

None

Parameters:
snapshot()[source]

Return a deep copy safe to mutate without affecting the store.

Return type:

ParamFamilyModel

property status_raw: Any

Raw status channel, if any.

property unit_code: Any

Raw unit code channel, if any.

property value: Any

Raw value channel, if any.

class pybragerone.models.param.ParamStore(**data: Any)[source]

Bases: BaseModel

Store of live parameter values.

Notes

Keys use the BragerOne addressing format: P<n>.<chan><idx> (e.g. P5.s0, P4.v1, P4.u1).

When devid is supplied, values are scoped per module so multi-module setups with overlapping addresses do not bleed. flatten_for_devid() reads one module snapshot; flatten() merges all scoped modules (last write wins per address).

This class is designed to be safe and fast for HA runtime.

Parameters:

families (dict[str, ParamFamilyModel])

families: dict[str, ParamFamilyModel]
flatten()[source]

Flattened view of all parameters as { 'P4.v1': value, ... }.

Returns the most recently upserted value per address across all modules (true last-write-wins), regardless of devid bucket insertion order.

Return type:

dict[str, Any]

flatten_for_devid(devid: str)[source]

Flattened parameter snapshot for one module (prime + scoped deltas).

Return type:

dict[str, Any]

Parameters:

devid (str)

get_family(pool: str, idx: int, *, devid: str | None = None)[source]

Get ParamFamilyModel by (pool, idx) address, or None if not found.

Returns a snapshot copy; mutate the store via upsert.

Return type:

ParamFamilyModel | None

Parameters:
ingest_prime_payload(payload: Mapping[str, Any])[source]

Ingest REST prime payload (modules/parameters) into the store.

Return type:

None

Parameters:

payload (Mapping[str, Any])

model_config: ClassVar[ConfigDict] = {'frozen': False, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /)

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

Return type:

None

async run_with_bus(bus: EventBus)[source]

Consume ParamUpdate events from EventBus and upsert into ParamStore.

Return type:

None

Parameters:

bus (EventBus)

upsert(key: str, value: Any, *, devid: str | None = None)[source]

Upsert a single parameter value by full key, e.g. P4.v1.

Returns a snapshot copy; mutate the store via further upsert calls.

Return type:

ParamFamilyModel | None

Parameters:
async upsert_async(key: str, value: Any, *, devid: str | None = None)[source]

Async upsert wrapper for convenience in async code.

Return type:

ParamFamilyModel | None

Parameters: