Commands¶
Python API reference for the tolomeo.commands package and the command errors in tolomeo.exceptions.
A command is a class whose execute coroutine receives a context and returns the response payload. Plugin commands are
listed in the plugin's Meta.commands. For the OTA commands and their payloads, see
OTA Commands.
Payload Models¶
tolomeo.commands.CommandPayload
¶
Bases: BaseModel
Base class for the payload models of commands.
Unknown fields are ignored, so callers can keep sending extra keys without breaking a command.
Source code in tolomeo/commands/base.py
CommandStr¶
tolomeo.commands.CommandStr is a str field type for payload models that also accepts JSON numbers and booleans,
stringified with str (123 becomes "123"). None, lists and objects are still rejected, and the field's JSON
schema stays {"type": "string"}.
PluginCmd¶
tolomeo.commands.PluginCmd
¶
tolomeo.commands.PluginCmdContext
dataclass
¶
Bases: BaseCmdContext, Generic[P]
Context for a command acting on a plugin.
Attributes:
| Name | Type | Description |
|---|---|---|
plugin |
P
|
The plugin the command acts on. |
Source code in tolomeo/commands/plugin/base.py
ServiceCmd¶
tolomeo.commands.ServiceCmd
¶
tolomeo.commands.ServiceCmdContext
dataclass
¶
Bases: BaseCmdContext, Generic[S]
Context for a command acting on a service.
Attributes:
| Name | Type | Description |
|---|---|---|
service |
S
|
The service the command acts on. |
Source code in tolomeo/commands/service/base.py
Errors¶
tolomeo.exceptions.CommandError
¶
Bases: Exception
Base for expected, client-caused command-handling failures.
These represent bad input from a caller (unknown command, bad payload), not internal bugs. Callers may catch this family to log without a stack trace and return a structured error response.
Source code in tolomeo/exceptions.py
tolomeo.exceptions.MessageFormatError
¶
Bases: CommandError, KeyError
Raised when a required key is missing from a message dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The offending key. |
required |
detail
|
str | None
|
What is wrong with the message, when it is not simply a missing key. Replaces the default "missing key" text. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
key |
The offending key. |
Source code in tolomeo/exceptions.py
tolomeo.exceptions.UnknownCommandError
¶
Bases: CommandError, ValueError
Raised when a command name is not registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The unknown command name. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
command |
The unknown command name. |
Source code in tolomeo/exceptions.py
tolomeo.exceptions.MissingPluginIdError
¶
Bases: CommandError, ValueError
Raised when a command payload has no plugin 'id'.
Source code in tolomeo/exceptions.py
tolomeo.exceptions.PluginNotFoundError
¶
Bases: CommandError, KeyError
Raised when no plugin is registered for the given id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plugin_id
|
str
|
The id used for lookup. |
required |
Source code in tolomeo/exceptions.py
tolomeo.exceptions.InvalidPayloadError
¶
Bases: CommandError, ValueError
Raised when a command payload does not match what the command expects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The name of the command that rejected the payload. |
required |
details
|
str
|
What is wrong with the payload. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
command |
The name of the command that rejected the payload. |
|
details |
What is wrong with the payload. |
Source code in tolomeo/exceptions.py
from_validation_error(command, error)
classmethod
¶
Build the error from a Pydantic validation failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The name of the command that rejected the payload. |
required |
error
|
ValidationError
|
The validation failure, one |
required |
Returns:
| Type | Description |
|---|---|
InvalidPayloadError
|
The error, with every issue listed in |