Define an Asset model #
To define an Asset model, we need to register it on the framework.
A model is declared with the following information:
- tenant group allowed to use the model
- model name
- accepted measures
- metadata
We will define an Asset model of name Room
which accept a temperature
measure and a metadata indicating in which building the room is located.
An example of the complete implementation can be found in the apps/api/lib/modules/assets/
directory
For this, we will use the Device Manager plugin:
import { DeviceManagerPlugin } from 'kuzzle-device-manager';
const deviceManager = app.plugin.get<DeviceManagerPlugin>('device-manager');
deviceManager.models.registerAsset('smartcity', 'Room', {
measures: [
{
name: 'temperature',
type: 'temperature',
},
],
metadataMapping: {
building: { type: 'keyword' },
},
});
[!NOTE] After 3.1.0-beta.58, a
AssetModel
interface is provided by iot-platform to simplify the models definition
import { AssetModel } from '@kuzzleio/iot-platform-backend';
const modelName = 'Room';
export Room: AssetModel = {
modelName,
definition: {
measures: [
{
name: 'temperature',
type: 'temperature',
},
],
metadataMapping: {
building: { type: 'keyword' },
},
}
};
Then you can provide the asset model in your tenant class that extends the new abstract class TenantGroup
to register it's.
import { AssetModel, TenantGroup } from '@kuzzleio/iot-platform-backend';
import { Room } from './Room';
export class TenantSmartCity extends TenantGroup {
readonly tenantGroup = 'smartcity';
protected readonly assetModels: AssetModel[] = [Room];
}
Edit this page on Github(opens new window)