Factory
This module provides functions to generate XML files for SiLA2 features based on Python classes. It includes functions to write feature headers, identifiers, display names, descriptions, properties, and commands. It also includes utility functions to convert naming conventions and handle data types. This is useful for creating SiLA2-compliant XML files that describe the features of a device or service.
It is designed to be used with Python classes that represent SiLA2 features, allowing for easy generation of XML files that can be used in SiLA2 applications.
ATTRIBUTE | DESCRIPTION |
---|---|
type_mapping |
A mapping of Python types to SiLA2 data types.
TYPE:
|
BASIC_TYPES |
A tuple of basic SiLA2 data types.
TYPE:
|
FUNCTION | DESCRIPTION |
---|---|
create_xml |
Generates an XML file for the given SiLA2 feature class. |
write_feature |
Writes the XML structure for a SiLA2 feature based on a Python class. |
write_header |
Writes the header information for the SiLA2 feature XML. |
split_by_words |
Splits a string into words based on common naming conventions. |
to_pascal_case |
Converts a string to PascalCase. |
to_title_case |
Converts a string to Title Case. |
write_identifier |
Writes the identifier element for a SiLA2 feature. |
write_display_name |
Writes the display name element for a SiLA2 feature. |
write_description |
Writes the description element for a SiLA2 feature. |
write_observable |
Writes the observable element for a SiLA2 feature. |
write_data_type |
Writes the data type element for a SiLA2 feature. |
write_property |
Writes a property element for a SiLA2 feature. |
write_command |
Writes a command element for a SiLA2 feature. |
write_parameter |
Writes a parameter element for a SiLA2 command. |
write_response |
Writes a response element for a SiLA2 command. |
Documentation last updated: 2025-06-11
create_xml
Write the XML data to a file.
PARAMETER | DESCRIPTION |
---|---|
prime
|
The SiLA2 feature class or instance to generate XML for.
TYPE:
|
split_by_words
Splits a string into words based on common naming conventions (camelCase, snake_case, PascalCase, kebab-case).
PARAMETER | DESCRIPTION |
---|---|
name_string
|
The input string in any common naming convention.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[str]
|
list[str]: A list of words extracted from the input string. |
to_pascal_case
Converts various naming conventions (camelCase, snake_case, PascalCase, kebab-case) to PascalCase (e.g., "MyClassName").
PARAMETER | DESCRIPTION |
---|---|
name_string
|
The input string in any common naming convention.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The converted string in PascalCase.
TYPE:
|
to_title_case
Converts various naming conventions (camelCase, snake_case, PascalCase, kebab-case) to Title Case (e.g., "My Awesome Variable").
PARAMETER | DESCRIPTION |
---|---|
name_string
|
The input string in any common naming convention.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The converted string in Title Case.
TYPE:
|
write_command
Write a command element for a SiLA2 feature.
PARAMETER | DESCRIPTION |
---|---|
attr
|
The command attribute, typically a method of the feature class.
TYPE:
|
parent
|
The parent XML element to append the command to.
TYPE:
|
observable
|
Whether the command is observable or not. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Element
|
ET.Element: The parent element with the command added. |
write_data_type
Write the data type element for a SiLA2 feature.
PARAMETER | DESCRIPTION |
---|---|
parent
|
The parent XML element to append the data type to.
TYPE:
|
data_type
|
The data type text, defaults to "Any".
TYPE:
|
is_list
|
Whether the data type is a list or not.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Element
|
ET.Element: The parent element with the data type added. |
write_description
Write the description element for a SiLA2 feature.
PARAMETER | DESCRIPTION |
---|---|
parent
|
The parent XML element to append the description to.
TYPE:
|
text
|
The description text.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Element
|
ET.Element: The parent element with the description added. |
write_display_name
Write the display name element for a SiLA2 feature.
PARAMETER | DESCRIPTION |
---|---|
parent
|
The parent XML element to append the display name to.
TYPE:
|
text
|
The display name text to be converted to Title Case.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Element
|
ET.Element: The parent element with the display name added. |
write_feature
Write the XML structure for a SiLA2 feature based on a Python class.
PARAMETER | DESCRIPTION |
---|---|
prime
|
The SiLA2 feature class or instance to generate XML for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Element
|
ET.Element: The root element of the XML structure for the SiLA2 feature. |
write_header
write_header(
parent: Element,
originator: str = "controllably",
category: str = "setup",
) -> Element
Write the header information for the SiLA2 feature XML.
PARAMETER | DESCRIPTION |
---|---|
parent
|
The parent XML element to append the header to.
TYPE:
|
originator
|
The originator of the SiLA2 feature.
TYPE:
|
category
|
The category of the SiLA2 feature.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Element
|
ET.Element: The parent element with the header information added. |
write_identifier
Write the identifier element for a SiLA2 feature.
PARAMETER | DESCRIPTION |
---|---|
parent
|
The parent XML element to append the identifier to.
TYPE:
|
text
|
The identifier text to be converted to PascalCase.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Element
|
ET.Element: The parent element with the identifier added. |
write_observable
Write the observable element for a SiLA2 feature.
PARAMETER | DESCRIPTION |
---|---|
parent
|
The parent XML element to append the observable to.
TYPE:
|
observable
|
Whether the feature is observable or not.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Element
|
ET.Element: The parent element with the observable added. |
write_parameter
write_parameter(
parent: Element,
identifier: str,
display_name: str,
data_type: str,
*,
description: str = "DESCRIPTION",
) -> Element
Write a parameter element for a SiLA2 command.
PARAMETER | DESCRIPTION |
---|---|
parent
|
The parent XML element to append the parameter to.
TYPE:
|
identifier
|
The identifier of the parameter.
TYPE:
|
display_name
|
The display name of the parameter.
TYPE:
|
data_type
|
The data type of the parameter.
TYPE:
|
description
|
The description of the parameter. Defaults to "DESCRIPTION".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Element
|
ET.Element: The parent element with the parameter added. |
write_property
write_property(
attr_name: str,
parent: Element,
*,
description: str = "DESCRIPTION",
observable: bool = False,
) -> Element
Write a property element for a SiLA2 feature.
PARAMETER | DESCRIPTION |
---|---|
attr_name
|
The name of the property attribute.
TYPE:
|
parent
|
The parent XML element to append the property to.
TYPE:
|
description
|
The description of the property. Defaults to "DESCRIPTION".
TYPE:
|
observable
|
Whether the property is observable or not. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Element
|
ET.Element: The parent element with the property added. |
write_response
write_response(
parent: Element,
identifier: str = "Response",
display_name: str = "Response",
data_type: str = "Any",
*,
description: str = "DESCRIPTION",
) -> Element
Write a response element for a SiLA2 command.
PARAMETER | DESCRIPTION |
---|---|
parent
|
The parent XML element to append the response to.
TYPE:
|
identifier
|
The identifier of the response. Defaults to "Response".
TYPE:
|
display_name
|
The display name of the response. Defaults to "Response".
TYPE:
|
data_type
|
The data type of the response. Defaults to "Any".
TYPE:
|
description
|
The description of the response. Defaults to "DESCRIPTION".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Element
|
ET.Element: The parent element with the response added. |