Skip to main content

Overview

The CatalogRepository interface manages global catalog data that is shared across all tenants. This includes device categories and types, measurement units, alert types and severities, periods, and actuator states. Catalog data is used in dropdowns and forms throughout the application.
Catalog data is global and not tenant-specific. Changes affect all tenants in the system.

Device Categories

getDeviceCategories()

Fetches all device categories from the catalog (e.g., Sensor, Actuator). Returns
Result<List<DeviceCatalogCategory>>
Result
Result containing list of device categories, or error on failure

createDeviceCategory()

Creates a new device category. Parameters
name
String
required
The category name (e.g., “Sensor”, “Actuator”)
Returns
Result<DeviceCatalogCategory>
Result
Result containing the created category with auto-generated ID, or error on failure

updateDeviceCategory()

Updates an existing device category. Parameters
id
Short
required
The category ID to update
name
String
required
The new category name
Returns
Result<DeviceCatalogCategory>
Result
Result containing the updated category, or error on failure

deleteDeviceCategory()

Deletes a device category. Parameters
id
Short
required
The category ID to delete
Returns
Result<Unit>
Result
Result indicating success or failure

Device Types

getDeviceTypes()

Fetches all device types from the catalog (e.g., Temperature Sensor, Humidity Sensor, Water Valve). Returns
Result<List<DeviceCatalogType>>
Result
Result containing list of device types with their properties, or error on failure

createDeviceType()

Creates a new device type with complete configuration. Parameters
name
String
required
The type name (e.g., “Temperature Sensor”)
description
String
Optional description of the device type
categoryId
Short
required
The category this type belongs to (1 = Sensor, 2 = Actuator)
defaultUnitId
Short
Optional default unit ID for this type (e.g., Celsius for temperature)
dataType
String
Optional data type (e.g., “numeric”, “boolean”)
minExpectedValue
Double
Optional minimum expected value for validation
maxExpectedValue
Double
Optional maximum expected value for validation
controlType
String
Optional control type for actuators (e.g., “on/off”, “variable”)
isActive
Boolean
default:"true"
Whether the type is active and available for use
Returns
Result<DeviceCatalogType>
Result
Result containing the created device type with auto-generated ID, or error on failure

updateDeviceType()

Updates an existing device type. All fields are optional for partial updates. Parameters
id
Short
required
The type ID to update
name
String
Optional new name
description
String
Optional new description
categoryId
Short
Optional new category ID
defaultUnitId
Short
Optional new default unit ID
dataType
String
Optional new data type
minExpectedValue
Double
Optional new minimum expected value
maxExpectedValue
Double
Optional new maximum expected value
controlType
String
Optional new control type
isActive
Boolean
Optional new active status
Returns
Result<DeviceCatalogType>
Result
Result containing the updated device type, or error on failure

deleteDeviceType()

Deletes a device type from the catalog. Parameters
id
Short
required
The type ID to delete
Returns
Result<Unit>
Result
Result indicating success or failure

activateDeviceType()

Activates a previously deactivated device type. Parameters
id
Short
required
The type ID to activate
Returns
Result<DeviceCatalogType>
Result
Result containing the activated device type, or error on failure

deactivateDeviceType()

Deactivates a device type without deleting it. Parameters
id
Short
required
The type ID to deactivate
Returns
Result<DeviceCatalogType>
Result
Result containing the deactivated device type, or error on failure

Device Units

getDeviceUnits()

Fetches all measurement units from the catalog (e.g., °C, %, kPa). Returns
Result<List<DeviceCatalogUnit>>
Result
Result containing list of device units, or error on failure

createDeviceUnit()

Creates a new measurement unit. Parameters
symbol
String
required
The unit symbol (e.g., “°C”, ”%”, “kPa”)
name
String
required
The unit name (e.g., “Celsius”, “Percent”, “Kilopascal”)
description
String
Optional description of the unit
isActive
Boolean
default:"true"
Whether the unit is active and available for use
Returns
Result<DeviceCatalogUnit>
Result
Result containing the created unit with auto-generated ID, or error on failure

updateDeviceUnit()

Updates an existing measurement unit. Parameters
id
Short
required
The unit ID to update
symbol
String
Optional new symbol
name
String
Optional new name
description
String
Optional new description
isActive
Boolean
Optional new active status
Returns
Result<DeviceCatalogUnit>
Result
Result containing the updated unit, or error on failure

deleteDeviceUnit()

Deletes a measurement unit from the catalog. Parameters
id
Short
required
The unit ID to delete
Returns
Result<Unit>
Result
Result indicating success or failure

activateDeviceUnit()

Activates a previously deactivated unit. Parameters
id
Short
required
The unit ID to activate
Returns
Result<DeviceCatalogUnit>
Result
Result containing the activated unit, or error on failure

deactivateDeviceUnit()

Deactivates a unit without deleting it. Parameters
id
Short
required
The unit ID to deactivate
Returns
Result<DeviceCatalogUnit>
Result
Result containing the deactivated unit, or error on failure

Alert Types

getAlertTypes()

Fetches all alert types from the catalog. Returns
Result<List<AlertType>>
Result
Result containing list of alert types, or error on failure

createAlertType()

Creates a new alert type. Parameters
name
String
required
The alert type name
description
String
Optional description of the alert type
Returns
Result<AlertType>
Result
Result containing the created alert type, or error on failure

updateAlertType()

Updates an existing alert type. Parameters
id
Short
required
The alert type ID to update
name
String
Optional new name
description
String
Optional new description
Returns
Result<AlertType>
Result
Result containing the updated alert type, or error on failure

deleteAlertType()

Deletes an alert type from the catalog. Parameters
id
Short
required
The alert type ID to delete
Returns
Result<Unit>
Result
Result indicating success or failure

Alert Severities

getAlertSeverities()

Fetches all alert severity levels from the catalog. Returns
Result<List<AlertSeverityCatalog>>
Result
Result containing list of alert severities with levels, colors, and notification settings, or error on failure

createAlertSeverity()

Creates a new alert severity level. Parameters
name
String
required
The severity name (e.g., “Critical”, “Warning”, “Info”)
level
Short
required
The severity level (lower numbers = less severe)
description
String
Optional description of the severity level
color
String
Optional color code in hex format (e.g., “#FF0000” for red)
requiresAction
Boolean
required
Whether this severity requires user action
notificationDelayMinutes
Int
required
Delay in minutes before sending notifications for this severity
Returns
Result<AlertSeverityCatalog>
Result
Result containing the created severity, or error on failure

updateAlertSeverity()

Updates an existing alert severity. Parameters
id
Short
required
The severity ID to update
name
String
Optional new name
level
Short
Optional new level
description
String
Optional new description
color
String
Optional new color
requiresAction
Boolean
Optional new requires action flag
notificationDelayMinutes
Int
Optional new notification delay
Returns
Result<AlertSeverityCatalog>
Result
Result containing the updated severity, or error on failure

deleteAlertSeverity()

Deletes an alert severity from the catalog. Parameters
id
Short
required
The severity ID to delete
Returns
Result<Unit>
Result
Result indicating success or failure

Periods

getPeriods()

Fetches all periods from the catalog (used for scheduling). Returns
Result<List<Period>>
Result
Result containing list of periods, or error on failure

createPeriod()

Creates a new period. Parameters
name
String
required
The period name
Returns
Result<Period>
Result
Result containing the created period, or error on failure

updatePeriod()

Updates an existing period. Parameters
id
Short
required
The period ID to update
name
String
required
The new period name
Returns
Result<Period>
Result
Result containing the updated period, or error on failure

deletePeriod()

Deletes a period from the catalog. Parameters
id
Short
required
The period ID to delete
Returns
Result<Unit>
Result
Result indicating success or failure

Actuator States

getActuatorStates()

Fetches all actuator states from the catalog (e.g., ON, OFF, STANDBY). Returns
Result<List<ActuatorState>>
Result
Result containing list of all actuator states, or error on failure

getOperationalActuatorStates()

Fetches only operational actuator states (excludes error/maintenance states). Returns
Result<List<ActuatorState>>
Result
Result containing list of operational actuator states, or error on failure

createActuatorState()

Creates a new actuator state. Parameters
name
String
required
The state name (e.g., “ON”, “OFF”, “STANDBY”)
description
String
Optional description of the state
isOperational
Boolean
required
Whether this state represents an operational mode
displayOrder
Short
required
The display order for sorting in UI
color
String
Optional color code in hex format for UI display
Returns
Result<ActuatorState>
Result
Result containing the created actuator state with auto-generated ID, or error on failure

updateActuatorState()

Updates an existing actuator state. Parameters
id
Short
required
The state ID to update
name
String
Optional new name
description
String
Optional new description
isOperational
Boolean
Optional new operational status
displayOrder
Short
Optional new display order
color
String
Optional new color
Returns
Result<ActuatorState>
Result
Result containing the updated actuator state, or error on failure

deleteActuatorState()

Deletes an actuator state from the catalog. Parameters
id
Short
required
The state ID to delete
Returns
Result<Unit>
Result
Result indicating success or failure

Usage Example

class DeviceFormViewModel(
    private val catalogRepository: CatalogRepository,
    private val devicesRepository: DevicesRepository
) : ViewModel() {
    private val _categories = MutableStateFlow<List<DeviceCatalogCategory>>(emptyList())
    val categories: StateFlow<List<DeviceCatalogCategory>> = _categories.asStateFlow()
    
    private val _types = MutableStateFlow<List<DeviceCatalogType>>(emptyList())
    val types: StateFlow<List<DeviceCatalogType>> = _types.asStateFlow()
    
    private val _units = MutableStateFlow<List<DeviceCatalogUnit>>(emptyList())
    val units: StateFlow<List<DeviceCatalogUnit>> = _units.asStateFlow()

    init {
        loadCatalogData()
    }

    private fun loadCatalogData() {
        viewModelScope.launch {
            // Load categories, types, and units in parallel
            val categoriesDeferred = async { catalogRepository.getDeviceCategories() }
            val typesDeferred = async { catalogRepository.getDeviceTypes() }
            val unitsDeferred = async { catalogRepository.getDeviceUnits() }
            
            catalogRepository.getDeviceCategories()
                .onSuccess { categories -> _categories.value = categories }
            
            catalogRepository.getDeviceTypes()
                .onSuccess { types -> _types.value = types }
            
            catalogRepository.getDeviceUnits()
                .onSuccess { units -> _units.value = units }
        }
    }
    
    fun onCategorySelected(categoryId: Short) {
        // Filter types by selected category
        val filteredTypes = _types.value.filter { it.categoryId == categoryId }
        // Update UI state with filtered types
    }
}

Device Models

Device catalog data models

Alert Models

Alert type and severity models

DevicesRepository

Device instance management

SettingsRepository

Settings using catalog data

Build docs developers (and LLMs) love