Skip to main content

Commands Service Data Models

CommandTemplate

Stores saved command configurations for quick reuse. Maps to command_templates table.

FieldTypeDB ColumnDescription
idIntegeridPrimary Key
user_idIntegeruser_idOwner user ID (FK → users)
device_idIntegerdevice_idTarget device ID (optional, FK → devices)
nameString(128)nameTemplate name
typeString(64)typeCommand type (e.g., "engineStop")
descriptionString(256)descriptionOptional description
attributesTextattributesJSON command parameters
created_atDateTimecreated_atCreation timestamp (UTC)
updated_atDateTimeupdated_atLast update timestamp (UTC)

Methods

MethodReturnsDescription
get_attributes()dictParses attributes JSON
set_attributes(dict)NoneSerializes dict to JSON
to_dict()dictReturns API-safe representation

Device (Read-Only)

Reference to devices table for model lookup.

FieldTypeDescription
idIntegerPrimary Key
modelStringDevice model (e.g., "S21L", "G11-SE")

UserDevice (Read-Only)

Reference to user_devices for permission checks.

FieldTypeDescription
user_idIntegerUser ID
device_idIntegerDevice ID
is_ownerBooleanTrue if user owns device
permission_commandsBooleanTrue if user can send commands

Command Types Mapping

Loaded from command_types.json:

{
"S21L": ["s21lFreq", "s21lAPN", "s21lSOSNumbers"],
"G11-SE": ["engineStop", "doorUnlock", "doorLock", "trackingInterval", "positionSingle"],
"TK319": ["engineStop", "doorUnlock", "trackingInterval", "positionSingle"],
"GT06N": ["engineStop", "positionSingle"]
}

Note: Add new device models/commands by editing command_types.json.