HeartbeatB

Python pydantic class corresponding to json type heartbeat.b, version 001.

class gwproto.types.HeartbeatB(*, FromGNodeAlias, FromGNodeInstanceId, MyHex='0', YourLastHex, LastReceivedTimeUnixMs, SendTimeUnixMs, StartingOver, TypeName='heartbeat.b', Version='001')

Heartbeat B.

This is the Heartbeat intended to be sent between the Scada and the AtomicTNode to allow for block-chain validation of the status of their communication.

[More info](https://gridworks.readthedocs.io/en/latest/dispatch-contract.html)

Parameters:
  • FromGNodeAlias (str)

  • FromGNodeInstanceId (str)

  • MyHex (str)

  • YourLastHex (str)

  • LastReceivedTimeUnixMs (int)

  • SendTimeUnixMs (int)

  • StartingOver (bool)

  • TypeName (Literal['heartbeat.b'])

  • Version (Literal['001'])

as_dict()

Translate the object into a dictionary representation that can be serialized into a heartbeat.b.001 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 heartbeat.b.001 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 heartbeat.b.001 representation.

Instances in the class are python-native representations of heartbeat.b.001 objects, while the actual heartbeat.b.001 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 HeartbeatB.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

FromGNodeAlias:
  • Description: My GNodeAlias.

  • Format: LeftRightDot

FromGNodeInstanceId:
  • Description: My GNodeInstanceId.

  • Format: UuidCanonicalTextual

MyHex:
  • Description: Hex character getting sent.

  • Format: HexChar

YourLastHex:
  • Description: Last hex character received from heartbeat partner..

  • Format: HexChar

LastReceivedTimeUnixMs:
  • Description: Time YourLastHex was received on my clock.

  • Format: ReasonableUnixTimeMs

SendTimeUnixMs:
  • Description: Time this message is made and sent on my clock.

  • Format: ReasonableUnixTimeMs

StartingOver:
  • Description: True if the heartbeat initiator wants to start the volley over. (typically the AtomicTNode in an AtomicTNode / SCADA pair) wants to start the heartbeating volley over. The result is that its partner will not expect the initiator to know its last Hex.

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.heartbeat_b.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.heartbeat_b.check_is_hex_char(v)

Checks HexChar format

HexChar format: single-char string in ‘0123456789abcdefABCDEF’

Parameters:

v (str) – the candidate

Raises:

ValueError – if v is not HexChar format

class gwproto.types.heartbeat_b.check_is_left_right_dot(v)

Checks LeftRightDot Format

LeftRightDot format: Lowercase alphanumeric words separated by periods, with the most significant word (on the left) starting with an alphabet character.

Parameters:

v (str) – the candidate

Raises:

ValueError – if v is not LeftRightDot format

class gwproto.types.heartbeat_b.check_is_reasonable_unix_time_ms(v)

Checks ReasonableUnixTimeMs format

ReasonableUnixTimeMs format: unix milliseconds between Jan 1 2000 and Jan 1 3000

Parameters:

v (int) – the candidate

Raises:

ValueError – if v is not ReasonableUnixTimeMs format

class gwproto.types.HeartbeatB_Maker(from_g_node_alias, from_g_node_instance_id, my_hex, your_last_hex, last_received_time_unix_ms, send_time_unix_ms, starting_over)
Parameters:
  • from_g_node_alias (str)

  • from_g_node_instance_id (str)

  • my_hex (str)

  • your_last_hex (str)

  • last_received_time_unix_ms (int)

  • send_time_unix_ms (int)

  • starting_over (bool)

classmethod dict_to_tuple(d)

Deserialize a dictionary representation of a heartbeat.b.001 message object into a HeartbeatB python object for internal use.

This is the near-inverse of the HeartbeatB.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 HeartbeatB object.

Returns:

HeartbeatB

Return type:

HeartbeatB

classmethod tuple_to_type(tpl)

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

Parameters:

tpl (HeartbeatB)

Return type:

bytes

classmethod type_to_tuple(t)

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

Parameters:

t (bytes)

Return type:

HeartbeatB