OpenFactoryApp declarative attributes#
- class openfactory.apps.attributefield.AttributeField(*, value='UNAVAILABLE', type='Events', tag)[source]#
Bases:
objectBase class for declarative OpenFactory attributes.
Instances of this class (or its subclasses) are intended to be declared as class-level attributes inside an
OpenFactoryAppclass. They are automatically collected byOpenFactoryAppMetainto the_declared_attributesdictionary.Each attribute represents a typed data field (e.g.,
EventsorSamples) with an associated tag used by OpenFactory.- Parameters:
Notes
nameis assigned automatically when the class is created.This class is typically not used directly; prefer subclasses like
EventAttributeorSampleAttribute.
- class openfactory.apps.attributefield.EventAttribute(*, value='UNAVAILABLE', tag)[source]#
Bases:
AttributeFieldRepresents an
Events-type OpenFactory attribute.This is a convenience subclass of
AttributeFieldthat automatically setstype="Events".- Parameters:
value (Any, Optional) – Default value of the attribute. Defaults to
"UNAVAILABLE".tag (str) – Tag used by OpenFactory.
Example
class MyApp(OpenFactoryApp): status = EventAttribute(value="idle", tag="App.Status")
- class openfactory.apps.attributefield.OpenFactoryAppMeta(name: str, bases: tuple[type, ...], attrs: dict[str, object])[source]#
Bases:
typeMetaclass that collects declarative
AttributeFieldinstances.When a class is defined with this metaclass, all class-level attributes that are instances of
AttributeFieldare automatically collected into a_declared_attributesdictionary.This enables a declarative style for defining OpenFactory attributes.
- Behavior:
Attributes from base classes are inherited.
Attributes in subclasses override those from base classes.
Each attribute’s
nameis automatically set to the variable name used in the class definition.
- _declared_attributes#
Mapping of attribute names to their corresponding instances.
- Type:
Example
class BaseApp(metaclass=OpenFactoryAppMeta): status = EventAttribute(tag="STATUS") class MyApp(BaseApp): temperature = SampleAttribute(tag="TEMP") status = EventAttribute(tag="OVERRIDE_STATUS") # overrides base MyApp._declared_attributes # { # "status": <EventAttribute tag="OVERRIDE_STATUS">, # "temperature": <SampleAttribute tag="TEMP"> # } MyApp._declared_attributes["status"].name # "status"
Advanced note
The metaclass walks the MRO (via base classes) and merges attribute definitions before processing the current class body. This ensures predictable inheritance and override behavior.
- class openfactory.apps.attributefield.SampleAttribute(*, value='UNAVAILABLE', tag)[source]#
Bases:
AttributeFieldRepresents a
Samples-type OpenFactory attribute.This is a convenience subclass of
AttributeFieldthat automatically setstype="Samples".- Parameters:
value (Any, Optional) – Default value of the attribute. Defaults to
"UNAVAILABLE".tag (str) – External identifier used by OpenFactory.
Example
class MyApp(OpenFactoryApp): temperature = SampleAttribute(tag="TEMP_SENSOR")