GtTelemetry

Python pydantic class corresponding to json type gt.telemetry, version 110.

class gwproto.types.GtTelemetry(*, ScadaReadTimeUnixMs, Value, Name, Exponent, TypeName='gt.telemetry', Version='110')

Data sent from a SimpleSensor to a SCADA.

This type is meant to be used by a SimpleSensor, where _what_ is doing the reading can be conflated with _what_ is being read.

Parameters:
  • ScadaReadTimeUnixMs (int)

  • Value (int)

  • Name (TelemetryName)

  • Exponent (int)

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

  • Version (Literal['110'])

as_dict()

Translate the object into a dictionary representation that can be serialized into a gt.telemetry.110 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 gt.telemetry.110 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 gt.telemetry.110 representation.

Instances in the class are python-native representations of gt.telemetry.110 objects, while the actual gt.telemetry.110 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 GtTelemetry.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

ScadaReadTimeUnixMs:
  • Description: Scada Read Time in Unix Milliseconds.

  • Format: ReasonableUnixTimeMs

Value:
  • Description: Value. The value of the reading.

Name:
  • Description: Name. The name of the Simple Sensing Spaceheat Node. This is both the AboutNodeName and FromNodeName for a data channel. The TelemetryName (and thus Units) are expected to be inferred by the Spaceheat Node. For example this is done initially in SCADA code according to whether the component of the Node is a PipeFlowSensorComponent, SimpleTempSensorComponent etc.

Exponent:
  • Description: Exponent. Say the TelemetryName is WaterTempCTimes1000; this corresponds to units of Celsius. To match the implication in the name, the Exponent should be 3, and a Value of 65300 would indicate 65.3 deg C

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.gt_telemetry.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.GtTelemetry_Maker(scada_read_time_unix_ms, value, name, exponent)
Parameters:
  • scada_read_time_unix_ms (int)

  • value (int)

  • name (TelemetryName)

  • exponent (int)

classmethod dict_to_tuple(d)

Deserialize a dictionary representation of a gt.telemetry.110 message object into a GtTelemetry python object for internal use.

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

Returns:

GtTelemetry

Return type:

GtTelemetry

classmethod tuple_to_type(tpl)

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

Parameters:

tpl (GtTelemetry)

Return type:

bytes

classmethod type_to_tuple(t)

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

Parameters:

t (bytes)

Return type:

GtTelemetry