ComponentGt

Python pydantic class corresponding to json type component.gt, version 000.

class gwproto.types.ComponentGt(*, ComponentId, ComponentAttributeClassId, DisplayName=None, HwUid=None, TypeName='component.gt', Version='000')

Component Gt.

Authority for the attributes of the component.gt.000 (ComponentId, ComponentAttributeClassId, DisplayName, HwUid) belongs to the WorldRegistry. The WorldRegistry is part of the GridWorks ‘BackOffice’ structure for managing relational device data . Notably, ComponentId and ComponentAttributeClass are both required and immutable. HwUid is optional but once it is set to a non-null value that is also immutable - it is meant to be an immutable identifier associated to a specific physical device, ideally one that can be read remotely by the SCADA and also by the naked eye. The DisplayName is mutable, with its current value in time governed by the WorldRegistry.

[More info](https://g-node-registry.readthedocs.io/en/latest/component.html)

Parameters:
  • ComponentId (str)

  • ComponentAttributeClassId (str)

  • DisplayName (str | None)

  • HwUid (str | None)

  • TypeName (Literal['component.gt'])

  • Version (Literal['000'])

as_dict()

Translate the object into a dictionary representation that can be serialized into a component.gt.000 object.

This method prepares the object for serialization by the as_type method, creating a dictionary with key-value pairs that follow the requirements for an instance of the component.gt.000 type. Unlike the standard python dict method, it makes the following substantive changes: - Enum Values: Translates between the values used locally by the actor to the symbol sent in messages. - Removes any key-value pairs where the value is None for a clearer message, especially in cases with many optional attributes.

It also applies these changes recursively to sub-types.

Return type:

Dict[str, Any]

as_type()

Serialize to the component.gt.000 representation.

Instances in the class are python-native representations of component.gt.000 objects, while the actual component.gt.000 object is the serialized UTF-8 byte string designed for sending in a message.

This method calls the as_dict() method, which differs from the native python dict() in the following key ways: - Enum Values: Translates between the values used locally by the actor to the symbol sent in messages. - - Removes any key-value pairs where the value is None for a clearer message, especially in cases with many optional attributes.

It also applies these changes recursively to sub-types.

Its near-inverse is ComponentGt.type_to_tuple(). If the type (or any sub-types) includes an enum, then the type_to_tuple will map an unrecognized symbol to the default enum value. This is why these two methods are only ‘near’ inverses.

Return type:

bytes

ComponentId:
  • Description: Component Id. Primary identifier for components in all GridWorks registries.

  • Format: UuidCanonicalTextual

ComponentAttributeClassId:
  • Description: ComponentAttributeClassId. Unique identifier for the device class. Authority for these, as well as the relationship between Components and ComponentAttributeClasses (Cacs) is maintained by the World Registry.

  • Format: UuidCanonicalTextual

DisplayName:
  • Description: This is an optional, mutable field whose use is strongly encouraged. It may include information about HOW the component is used in a hardware layout. It may also include the HwUid for the component.

HwUid:
  • Description: Usually this is determined by the inheriting class.

TypeName:
  • Description: All GridWorks Versioned Types have a fixed TypeName, which is a string of lowercase alphanumeric words separated by periods, most significant word (on the left) starting with an alphabet character, and final word NOT all Hindu-Arabic numerals.

Version:
  • Description: All GridWorks Versioned Types have a fixed version, which is a string of three Hindu-Arabic numerals.

class gwproto.types.component_gt.check_is_uuid_canonical_textual(v)

Checks UuidCanonicalTextual format

UuidCanonicalTextual format: A string of hex words separated by hyphens of length 8-4-4-4-12.

Parameters:

v (str) – the candidate

Raises:

ValueError – if v is not UuidCanonicalTextual format

class gwproto.types.ComponentGt_Maker(component_id, component_attribute_class_id, display_name, hw_uid)
Parameters:
  • component_id (str)

  • component_attribute_class_id (str)

  • display_name (str | None)

  • hw_uid (str | None)

classmethod dict_to_tuple(d)

Deserialize a dictionary representation of a component.gt.000 message object into a ComponentGt python object for internal use.

This is the near-inverse of the ComponentGt.as_dict() method:
  • Enums: translates between the symbols sent in messages between actors and

the values used by the actors internally once they’ve deserialized the messages.
  • Types: recursively validates and deserializes sub-types.

Note that if a required attribute with a default value is missing in a dict, this method will raise a SchemaError. This differs from the pydantic BaseModel practice of auto-completing missing attributes with default values when they exist.

Parameters:

d (dict) – the dictionary resulting from json.loads(t) for a serialized JSON type object t.

Raises:

SchemaError – if the dict cannot be turned into a ComponentGt object.

Returns:

ComponentGt

Return type:

ComponentGt

classmethod tuple_to_type(tuple_)

Given a Python class object, returns the serialized JSON type object.

Parameters:

tuple_ (ComponentGt)

Return type:

bytes

classmethod type_to_tuple(t)

Given a serialized JSON type object, returns the Python class object.

Parameters:

t (bytes)

Return type:

ComponentGt