OpenFactoryApp declarative attributes#

class openfactory.apps.attributefield.AttributeField(*, value='UNAVAILABLE', type='Events', tag)[source]#

Bases: object

Base class for declarative OpenFactory attributes.

Instances of this class (or its subclasses) are intended to be declared as class-level attributes inside an OpenFactoryApp class. They are automatically collected by OpenFactoryAppMeta into the _declared_attributes dictionary.

Each attribute represents a typed data field (e.g., Events or Samples) with an associated tag used by OpenFactory.

Parameters:
  • value (Any, Optional) – Default value of the attribute. Defaults to "UNAVAILABLE".

  • type (str, Optional) – Attribute type (e.g., Events, Samples). Defaults to "Events".

  • tag (str) – Tag used by OpenFactory.

Notes

  • name is assigned automatically when the class is created.

  • This class is typically not used directly; prefer subclasses like EventAttribute or SampleAttribute.

__init__(*, value='UNAVAILABLE', type='Events', tag)[source]#
class openfactory.apps.attributefield.EventAttribute(*, value='UNAVAILABLE', tag)[source]#

Bases: AttributeField

Represents an Events-type OpenFactory attribute.

This is a convenience subclass of AttributeField that automatically sets type="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")
__init__(*, value='UNAVAILABLE', tag)[source]#
class openfactory.apps.attributefield.OpenFactoryAppMeta(name: str, bases: tuple[type, ...], attrs: dict[str, object])[source]#

Bases: type

Metaclass that collects declarative AttributeField instances.

When a class is defined with this metaclass, all class-level attributes that are instances of AttributeField are automatically collected into a _declared_attributes dictionary.

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 name is automatically set to the variable name used in the class definition.

_declared_attributes#

Mapping of attribute names to their corresponding instances.

Type:

dict[str, AttributeField]

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: AttributeField

Represents a Samples-type OpenFactory attribute.

This is a convenience subclass of AttributeField that automatically sets type="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")
__init__(*, value='UNAVAILABLE', tag)[source]#