sgr_commhandler.device_builder
Provides a device builder to create device instances from external interface descriptions (EID).
Attributes
Classes
Defines an EID XML source. |
|
Defines an EID properties source. |
|
Defines a communication interface type. |
|
Implements an SGr device builder with a fluent interface. |
Functions
|
Parses EID XML content into a device frame. |
|
Replaces parameter placeholders in EID XML content. |
|
Builds EID configuration properties. |
|
Validates EID XML content against the specification XML schema. |
Module Contents
- sgr_commhandler.device_builder.logger
- class sgr_commhandler.device_builder.SGrXmlSource
Bases:
enum.EnumDefines an EID XML source.
- UNKNOWN = 1
- STRING = 2
- FILE = 3
- class sgr_commhandler.device_builder.SGrPropertiesSource
Bases:
enum.EnumDefines an EID properties source.
- UNKNOWN = 1
- DICT = 2
- FILE = 3
- class sgr_commhandler.device_builder.SGrDeviceProtocol
Bases:
enum.EnumDefines a communication interface type.
- MODBUS = 0
- RESTAPI = 1
- MESSAGING = 2
- CONTACT = 3
- GENERIC = 4
- UNKNOWN = 5
- sgr_commhandler.device_builder.SGrInterfaces
- sgr_commhandler.device_builder.device_builders: dict[SGrDeviceProtocol, collections.abc.Callable[[sgr_specification.v0.product.DeviceFrame], SGrInterfaces]]
- class sgr_commhandler.device_builder.DeviceBuilder
Implements an SGr device builder with a fluent interface.
- _eid_source: str | None = None
- _properties_source: str | dict | None = None
- _eid_type: SGrXmlSource
- _properties_type: SGrPropertiesSource
- build()
Constructs an SGr device instance from the builder.
- Returns:
an instance of an SGr device
- Return type:
- _resolve_protocol(frame)
- Parameters:
frame (sgr_specification.v0.product.DeviceFrame)
- Return type:
- eid_path(file_path)
Sets the EID source to a file path.
- Parameters:
file_path (str) – the path to the EID XML file
- Returns:
the same builder instance
- Return type:
- eid(xml)
Sets the EID source to an XML string.
- Parameters:
xml (str) – the EID XML content
- Returns:
the same builder instance
- Return type:
- properties_path(file_path)
Sets the EID properties to a file path.
- Parameters:
file_path (str) – the path to the property file
- Returns:
the same builder instance
- Return type:
- properties(properties)
Sets the EID properties to a key-value map.
- Parameters:
properties (dict) – the properties
- Returns:
the same builder instance
- Return type:
- _load_eid_content()
- Return type:
str
- _load_properties()
- Return type:
dict
- sgr_commhandler.device_builder.parse_device_frame(content)
Parses EID XML content into a device frame.
- Parameters:
content (str) – the EID XML content
- Returns:
a device frame of the SGr specification
- Return type:
DeviceFrame
- sgr_commhandler.device_builder.replace_variables(content, parameters)
Replaces parameter placeholders in EID XML content.
- Parameters:
content (str) – the EID XML content
parameters (dict) – the configuration parameters
- Returns:
the updated EID XML content
- Return type:
str
- sgr_commhandler.device_builder.build_properties(config, properties)
Builds EID configuration properties. Only parameters defined in the EID configuration list are kept. Parameters not defined in the properties are set to the default value.
- Parameters:
config (list[ConfigurationParameter]) – the EID configuration parameters
properties (dict) – the properties to configure
- Returns:
the final properties
- Return type:
dict
- sgr_commhandler.device_builder.validate_schema(content)
Validates EID XML content against the specification XML schema.
- Parameters:
content (str) – the EID XML content