module documentation

The Keyed Binding: one ROS2 path, many OPC UA objects, membership taken from the messages.

A Keyed Binding's message carries a repeated field, and a key inside each element names the object it belongs to: /diagnostics keyed by status[] on hardware_id and name. Membership is the content-driven case. Each member is a variable group in the Binding's Monitoring that carries the variables the element type's Projection shapes (a nested message is a complex Variable), browses under its key with the characters of a RelativePath replaced (member_browse_name), shows the raw key as its DisplayName and holds it as a String[] variable. The Binding's name is the group above the members. Members are created through the mutation chokepoint, so the caps and one model-change event per batch apply, and they are never removed. Two keys that sanitise to one browse name are reported once as a BindingEvent and the second gets no member.

An optional declared state field adds two things: a BindingEvent when a member's state changes (at the severity the declaration maps it to), and one variable holding the highest state any member holds. Nothing reads the aggregate back, so a foreign publisher cannot halt a Machine . The mechanism is generic and has no diagnostics-specific code.

Class ROS2KeyedMirrorMixin Keeps a machinery item's Keyed Bindings' members in sync with what arrives on their topics.
Function member_browse_name Return the browse name a member is filed under: each reserved character of its key becomes _.
Function member_key Return the key one element of a repeated field carries, field by field.
Function severity_of Return the house band a transition into one state is reported at.
Function state_changed Return whether writing current over previous is a transition worth an event.
Function worst_state Return the highest state any member holds, or initial when no member holds one.
Constant KEY The browse name of the raw-key variable on every member (DisplayName key).
Constant KEY_COLLISION The BindingEvent code a second key that sanitises onto an existing member carries.
Constant MEMBER_STATE_CHANGED The BindingEvent code a member's declared state field changing value carries.
Constant WORST What the aggregate variable's name is built from: Worst<State>, such as WorstLevel.
Class _Keyed One Keyed Binding, live: its subscription, the plan each member is built from, its members.
Class _Member One member of a Keyed Binding: its key, the nodes it became, and what they read.
Function _is_a_number Return whether a state value is a number to order and look labels or bands up by.
Function _keyed_plan Return one member's plan, with its raw key as the initial value of the key variable.
Function _labelled Return a state value as an event's text should read it: the label, and the number.
Function _member_plan Return the plan one member is built from: the raw key, then whatever the Projection shaped.
Function _repeated_element Return the message type one Binding's repeated field carries.
Function _require_scalar_key_fields Refuse a key field that cannot name a member.
Function _state_entry Return the variable a Binding's declared state field renders as, with its labels named.
Function _with_state Return the member plan with the state field's variable as the state entry describes it.
Constant _KEY_DISPLAY The DisplayName of the raw-key variable.
Constant _RESERVED The characters the OPC UA RelativePath text form reserves. Each in a member's key becomes one underscore, so a generic client never has to escape a key.
Constant _UNNAMED What a key with nothing usable in it browses as, because refusing would drop the member.
def member_browse_name(key: Sequence[str]) -> str:

Return the browse name a member is filed under: each reserved character of its key becomes _.

The parts of a multi-field key are joined with _. "robot 1: left motor" browses as "robot 1_ left motor" and the raw key is the DisplayName. The mapping is not injective, and the caller refuses a collision.

def member_key(element: Message, key_fields: Sequence[str]) -> tuple[str, ...]:

Return the key one element of a repeated field carries, field by field.

The fields are read in declaration order and rendered as text. Key fields are validated as scalar leaves when the Binding is built.

Parameters
element:MessageOne element of the Binding's repeated field, as it crossed the seam.
key_fields:Sequence[str]The ROS2 field names the declaration keys on.
Returns
tuple[str, ...]Undocumented
def severity_of(state: object, severities: Mapping[int, Severity]) -> Severity:

Return the house band a transition into one state is reported at.

The map comes from the declaration (see ~opensmi.ros2.server.events.Severity). With no map every transition is INFO; with a map, a value outside it is a WARNING.

def state_changed(previous: object, current: object) -> bool:

Return whether writing current over previous is a transition worth an event.

A member is created holding the plan's initial (for a level, the first declared constant), so a healthy unit announces nothing when it first appears and a broken one does.

def worst_state(states: Iterable[object], *, initial: object) -> object:

Return the highest state any member holds, or initial when no member holds one.

Highest by the ROS2 constants' numbering, which for DiagnosticStatus is the worst level. Non-numeric states have no order, so the aggregate stays at initial.

Parameters
states:Iterable[object]What each member's state variable currently reads.
initial:objectWhat the aggregate was created holding, which is what an empty set reads.
Returns
objectUndocumented
KEY: str =

The browse name of the raw-key variable on every member (DisplayName key).

A Binding whose element type already has a field that browses as this is refused at init.

Value
'Key'
KEY_COLLISION: str =

The BindingEvent code a second key that sanitises onto an existing member carries.

Value
'KEY_COLLISION'
MEMBER_STATE_CHANGED: str =

The BindingEvent code a member's declared state field changing value carries.

Value
'MEMBER_STATE_CHANGED'
WORST: str =

What the aggregate variable's name is built from: Worst<State>, such as WorstLevel.

Value
'Worst'
def _is_a_number(value: object) -> TypeGuard[int]:

Return whether a state value is a number to order and look labels or bands up by.

bool is excluded: a state field is not a flag.

def _keyed_plan(plan: tuple[PlanEntry, ...], key: tuple[str, ...]) -> tuple[PlanEntry, ...]:

Return one member's plan, with its raw key as the initial value of the key variable.

The node is created holding the key, so a client never reads it empty.

def _labelled(state: object, states: Mapping[int, str]) -> str:

Return a state value as an event's text should read it: the label, and the number.

def _member_plan(shaped: tuple[PlanEntry, ...], binding: KeyedBinding) -> tuple[PlanEntry, ...]:

Return the plan one member is built from: the raw key, then whatever the Projection shaped.

Raises
DeclarationErrorWhen the element type already renders something called KEY.
def _repeated_element(message_type: type[Message], binding: KeyedBinding) -> type[Message]:

Return the message type one Binding's repeated field carries.

Raises
UnprojectableFieldErrorWhen the named field does not exist or does not repeat a message.
def _require_scalar_key_fields(element_type: type[Message], binding: KeyedBinding):

Refuse a key field that cannot name a member.

Raises
DeclarationErrorWhen a key field is absent from the element type, or is not a scalar leaf of it.
def _state_entry(plan: tuple[PlanEntry, ...], binding: KeyedBinding, element_type: type[Message], qualifier: str) -> PlanVariable | None:

Return the variable a Binding's declared state field renders as, with its labels named.

The labels come from the declaration, not the Projection, so the member's state variable and the aggregate share one enumeration.

Raises
DeclarationErrorWhen the element's Projection renders no variable of that name (the field was excluded or renamed).
def _with_state(plan: tuple[PlanEntry, ...], state: PlanVariable | None) -> tuple[PlanEntry, ...]:

Return the member plan with the state field's variable as the state entry describes it.

_KEY_DISPLAY: str =

The DisplayName of the raw-key variable.

Value
'key'
_RESERVED =

The characters the OPC UA RelativePath text form reserves. Each in a member's key becomes one underscore, so a generic client never has to escape a key.

Value
re.compile(r'[/\.<>:#!&]')
_UNNAMED: str =

What a key with nothing usable in it browses as, because refusing would drop the member.

Value
'unnamed'