Properties and Commands
Learn how to define properties and commands in your connector.
Identifier and Display Name
The identifiers are auto-generated based on the method name. The method name "get_server_name" is turned into the property identifier "ServerName". Several prefixes are auto-detected and infer certain aspects of the method:
- "get"-prefix is subtracted for unobservable properties
- "subscribe"-prefix is subtracted for observable properties
Acronyms and abbreviations that are part of the identifier and display name will be turned into lowercase words. A method named "get_server_UUID" is transformed into "ServerUuid" (identifier) and "Server Uuid" (display name) respectively. However, in some cases, like the SiLA Service feature, identifier and display name are defined as "ServerUUID" and "Server UUID". Therefore, the decorator attributes must be set accordingly.
@sila.UnobservableProperty(identifier="ServerUUID", display_name="Server UUID")
Description
The description is automatically extracted from the method docstring. The docstring description can be explicitly overwritten by passing the decorator description parameter.
@sila.UnobservableProperty(description="My description.")
Responses
Responses are inferred by the specified return type. While properties must only have one response, commands may have multiple responses. They can be added simply by adding multiple Response
decorators. In this case, the method should return a tuple of all responses and the return statement looks like this:
@sila.UnobservableCommand(description="My description.")
@sila.Response(name="Random number", description="Random description")
@sila.Response(name="Random fact", description="Random description")
async def generate_random_stuff() -> int, str:
return int(np.random.rand()), randfacts.get_fact()