Skip to content

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

BASIC_TYPES

A tuple of basic SiLA2 data types.

TYPE: tuple

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

create_xml(prime: Any)

Write the XML data to a file.

PARAMETER DESCRIPTION
prime

The SiLA2 feature class or instance to generate XML for.

TYPE: Any

split_by_words

split_by_words(name_string: str) -> list[str]

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

RETURNS DESCRIPTION
list[str]

list[str]: A list of words extracted from the input string.

to_pascal_case

to_pascal_case(name_string: str) -> str

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

RETURNS DESCRIPTION
str

The converted string in PascalCase.

TYPE: str

to_title_case

to_title_case(name_string: str) -> str

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

RETURNS DESCRIPTION
str

The converted string in Title Case.

TYPE: str

write_command

write_command(
    attr: Callable,
    parent: Element,
    *,
    observable: bool = False,
) -> Element

Write a command element for a SiLA2 feature.

PARAMETER DESCRIPTION
attr

The command attribute, typically a method of the feature class.

TYPE: Callable

parent

The parent XML element to append the command to.

TYPE: Element

observable

Whether the command is observable or not. Defaults to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Element

ET.Element: The parent element with the command added.

write_data_type

write_data_type(
    parent: Element,
    data_type: str = "Any",
    is_list: bool = False,
) -> Element

Write the data type element for a SiLA2 feature.

PARAMETER DESCRIPTION
parent

The parent XML element to append the data type to.

TYPE: Element

data_type

The data type text, defaults to "Any".

TYPE: str DEFAULT: 'Any'

is_list

Whether the data type is a list or not.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Element

ET.Element: The parent element with the data type added.

write_description

write_description(parent: Element, text: str) -> Element

Write the description element for a SiLA2 feature.

PARAMETER DESCRIPTION
parent

The parent XML element to append the description to.

TYPE: Element

text

The description text.

TYPE: str

RETURNS DESCRIPTION
Element

ET.Element: The parent element with the description added.

write_display_name

write_display_name(parent: Element, text: str) -> Element

Write the display name element for a SiLA2 feature.

PARAMETER DESCRIPTION
parent

The parent XML element to append the display name to.

TYPE: Element

text

The display name text to be converted to Title Case.

TYPE: str

RETURNS DESCRIPTION
Element

ET.Element: The parent element with the display name added.

write_feature

write_feature(prime: Any) -> Element

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

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

originator

The originator of the SiLA2 feature.

TYPE: str DEFAULT: 'controllably'

category

The category of the SiLA2 feature.

TYPE: str DEFAULT: 'setup'

RETURNS DESCRIPTION
Element

ET.Element: The parent element with the header information added.

write_identifier

write_identifier(parent: Element, text: str) -> Element

Write the identifier element for a SiLA2 feature.

PARAMETER DESCRIPTION
parent

The parent XML element to append the identifier to.

TYPE: Element

text

The identifier text to be converted to PascalCase.

TYPE: str

RETURNS DESCRIPTION
Element

ET.Element: The parent element with the identifier added.

write_observable

write_observable(
    parent: Element, observable: bool
) -> Element

Write the observable element for a SiLA2 feature.

PARAMETER DESCRIPTION
parent

The parent XML element to append the observable to.

TYPE: Element

observable

Whether the feature is observable or not.

TYPE: bool

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

identifier

The identifier of the parameter.

TYPE: str

display_name

The display name of the parameter.

TYPE: str

data_type

The data type of the parameter.

TYPE: str

description

The description of the parameter. Defaults to "DESCRIPTION".

TYPE: str DEFAULT: 'DESCRIPTION'

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

parent

The parent XML element to append the property to.

TYPE: Element

description

The description of the property. Defaults to "DESCRIPTION".

TYPE: str DEFAULT: 'DESCRIPTION'

observable

Whether the property is observable or not. Defaults to False.

TYPE: bool DEFAULT: False

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

identifier

The identifier of the response. Defaults to "Response".

TYPE: str DEFAULT: 'Response'

display_name

The display name of the response. Defaults to "Response".

TYPE: str DEFAULT: 'Response'

data_type

The data type of the response. Defaults to "Any".

TYPE: str DEFAULT: 'Any'

description

The description of the response. Defaults to "DESCRIPTION".

TYPE: str DEFAULT: 'DESCRIPTION'

RETURNS DESCRIPTION
Element

ET.Element: The parent element with the response added.