sgr_commhandler.device_builder

Provides a device builder to create device instances from external interface descriptions (EID).

Attributes

logger

SGrInterfaces

device_builders

Classes

SGrXmlSource

Defines an EID XML source.

SGrPropertiesSource

Defines an EID properties source.

SGrDeviceProtocol

Defines a communication interface type.

DeviceBuilder

Implements an SGr device builder with a fluent interface.

Functions

parse_device_frame(content)

Parses EID XML content into a device frame.

replace_variables(content, parameters)

Replaces parameter placeholders in EID XML content.

build_properties(config, properties)

Builds EID configuration properties.

validate_schema(content)

Validates EID XML content against the specification XML schema.

Module Contents

sgr_commhandler.device_builder.logger
class sgr_commhandler.device_builder.SGrXmlSource

Bases: enum.Enum

Defines an EID XML source.

UNKNOWN = 1
STRING = 2
FILE = 3
class sgr_commhandler.device_builder.SGrPropertiesSource

Bases: enum.Enum

Defines an EID properties source.

UNKNOWN = 1
DICT = 2
FILE = 3
class sgr_commhandler.device_builder.SGrDeviceProtocol

Bases: enum.Enum

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

SGrBaseInterface

_resolve_protocol(frame)
Parameters:

frame (sgr_specification.v0.product.DeviceFrame)

Return type:

SGrDeviceProtocol

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:

DeviceBuilder

eid(xml)

Sets the EID source to an XML string.

Parameters:

xml (str) – the EID XML content

Returns:

the same builder instance

Return type:

DeviceBuilder

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:

DeviceBuilder

properties(properties)

Sets the EID properties to a key-value map.

Parameters:

properties (dict) – the properties

Returns:

the same builder instance

Return type:

DeviceBuilder

_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