Commands Service Data Models
CommandTemplate
Stores saved command configurations for quick reuse. Maps to command_templates table.
| Field | Type | DB Column | Description |
|---|---|---|---|
id | Integer | id | Primary Key |
user_id | Integer | user_id | Owner user ID (FK → users) |
device_id | Integer | device_id | Target device ID (optional, FK → devices) |
name | String(128) | name | Template name |
type | String(64) | type | Command type (e.g., "engineStop") |
description | String(256) | description | Optional description |
attributes | Text | attributes | JSON command parameters |
created_at | DateTime | created_at | Creation timestamp (UTC) |
updated_at | DateTime | updated_at | Last update timestamp (UTC) |
Methods
| Method | Returns | Description |
|---|---|---|
get_attributes() | dict | Parses attributes JSON |
set_attributes(dict) | None | Serializes dict to JSON |
to_dict() | dict | Returns API-safe representation |
Device (Read-Only)
Reference to devices table for model lookup.
| Field | Type | Description |
|---|---|---|
id | Integer | Primary Key |
model | String | Device model (e.g., "S21L", "G11-SE") |
UserDevice (Read-Only)
Reference to user_devices for permission checks.
| Field | Type | Description |
|---|---|---|
user_id | Integer | User ID |
device_id | Integer | Device ID |
is_owner | Boolean | True if user owns device |
permission_commands | Boolean | True 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.