Search in sources :

Example 1 with DeviceProfileData

use of org.thingsboard.server.common.data.device.profile.DeviceProfileData in project thingsboard by thingsboard.

the class AbstractWebTest method createDeviceProfile.

protected DeviceProfile createDeviceProfile(String name, DeviceProfileTransportConfiguration deviceProfileTransportConfiguration) {
    DeviceProfile deviceProfile = new DeviceProfile();
    deviceProfile.setName(name);
    deviceProfile.setType(DeviceProfileType.DEFAULT);
    deviceProfile.setTransportType(DeviceTransportType.DEFAULT);
    deviceProfile.setDescription(name + " Test");
    DeviceProfileData deviceProfileData = new DeviceProfileData();
    DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration();
    deviceProfileData.setConfiguration(configuration);
    if (deviceProfileTransportConfiguration != null) {
        deviceProfileData.setTransportConfiguration(deviceProfileTransportConfiguration);
    } else {
        deviceProfileData.setTransportConfiguration(new DefaultDeviceProfileTransportConfiguration());
    }
    deviceProfile.setProfileData(deviceProfileData);
    deviceProfile.setDefault(false);
    deviceProfile.setDefaultRuleChainId(null);
    return deviceProfile;
}
Also used : DefaultDeviceProfileConfiguration(org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DefaultDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileTransportConfiguration) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData)

Example 2 with DeviceProfileData

use of org.thingsboard.server.common.data.device.profile.DeviceProfileData in project thingsboard by thingsboard.

the class DeviceBulkImportService method setUpLwM2mDeviceProfile.

private DeviceProfile setUpLwM2mDeviceProfile(TenantId tenantId, Device device) {
    DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileByName(tenantId, device.getType());
    if (deviceProfile != null) {
        if (deviceProfile.getTransportType() != DeviceTransportType.LWM2M) {
            deviceProfile.setTransportType(DeviceTransportType.LWM2M);
            deviceProfile.getProfileData().setTransportConfiguration(new Lwm2mDeviceProfileTransportConfiguration());
            deviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
        }
    } else {
        findOrCreateDeviceProfileLock.lock();
        try {
            deviceProfile = deviceProfileService.findDeviceProfileByName(tenantId, device.getType());
            if (deviceProfile == null) {
                deviceProfile = new DeviceProfile();
                deviceProfile.setTenantId(tenantId);
                deviceProfile.setType(DeviceProfileType.DEFAULT);
                deviceProfile.setName(device.getType());
                deviceProfile.setTransportType(DeviceTransportType.LWM2M);
                deviceProfile.setProvisionType(DeviceProfileProvisionType.DISABLED);
                DeviceProfileData deviceProfileData = new DeviceProfileData();
                DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration();
                DeviceProfileTransportConfiguration transportConfiguration = new Lwm2mDeviceProfileTransportConfiguration();
                DisabledDeviceProfileProvisionConfiguration provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(null);
                deviceProfileData.setConfiguration(configuration);
                deviceProfileData.setTransportConfiguration(transportConfiguration);
                deviceProfileData.setProvisionConfiguration(provisionConfiguration);
                deviceProfile.setProfileData(deviceProfileData);
                deviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
            }
        } finally {
            findOrCreateDeviceProfileLock.unlock();
        }
    }
    return deviceProfile;
}
Also used : DefaultDeviceProfileConfiguration(org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) DeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData) DisabledDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration)

Example 3 with DeviceProfileData

use of org.thingsboard.server.common.data.device.profile.DeviceProfileData in project thingsboard by thingsboard.

the class AbstractMqttIntegrationTest method createMqttDeviceProfile.

protected DeviceProfile createMqttDeviceProfile(TransportPayloadType transportPayloadType, String telemetryTopic, String attributesTopic, String telemetryProtoSchema, String attributesProtoSchema, String rpcResponseProtoSchema, String rpcRequestProtoSchema, String provisionKey, String provisionSecret, DeviceProfileProvisionType provisionType, boolean enableCompatibilityWithJsonPayloadFormat, boolean useJsonPayloadFormatForDefaultDownlinkTopics) {
    DeviceProfile deviceProfile = new DeviceProfile();
    deviceProfile.setName(transportPayloadType.name());
    deviceProfile.setType(DeviceProfileType.DEFAULT);
    deviceProfile.setTransportType(DeviceTransportType.MQTT);
    deviceProfile.setProvisionType(provisionType);
    deviceProfile.setProvisionDeviceKey(provisionKey);
    deviceProfile.setDescription(transportPayloadType.name() + " Test");
    DeviceProfileData deviceProfileData = new DeviceProfileData();
    DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration();
    MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = new MqttDeviceProfileTransportConfiguration();
    if (!StringUtils.isEmpty(telemetryTopic)) {
        mqttDeviceProfileTransportConfiguration.setDeviceTelemetryTopic(telemetryTopic);
    }
    if (!StringUtils.isEmpty(attributesTopic)) {
        mqttDeviceProfileTransportConfiguration.setDeviceAttributesTopic(attributesTopic);
    }
    TransportPayloadTypeConfiguration transportPayloadTypeConfiguration;
    if (TransportPayloadType.JSON.equals(transportPayloadType)) {
        transportPayloadTypeConfiguration = new JsonTransportPayloadConfiguration();
    } else {
        ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = new ProtoTransportPayloadConfiguration();
        if (StringUtils.isEmpty(telemetryProtoSchema)) {
            telemetryProtoSchema = DEVICE_TELEMETRY_PROTO_SCHEMA;
        }
        if (StringUtils.isEmpty(attributesProtoSchema)) {
            attributesProtoSchema = DEVICE_ATTRIBUTES_PROTO_SCHEMA;
        }
        if (StringUtils.isEmpty(rpcResponseProtoSchema)) {
            rpcResponseProtoSchema = DEVICE_RPC_RESPONSE_PROTO_SCHEMA;
        }
        if (StringUtils.isEmpty(rpcRequestProtoSchema)) {
            rpcRequestProtoSchema = DEVICE_RPC_REQUEST_PROTO_SCHEMA;
        }
        protoTransportPayloadConfiguration.setDeviceTelemetryProtoSchema(telemetryProtoSchema);
        protoTransportPayloadConfiguration.setDeviceAttributesProtoSchema(attributesProtoSchema);
        protoTransportPayloadConfiguration.setDeviceRpcResponseProtoSchema(rpcResponseProtoSchema);
        protoTransportPayloadConfiguration.setDeviceRpcRequestProtoSchema(rpcRequestProtoSchema);
        protoTransportPayloadConfiguration.setEnableCompatibilityWithJsonPayloadFormat(enableCompatibilityWithJsonPayloadFormat);
        protoTransportPayloadConfiguration.setUseJsonPayloadFormatForDefaultDownlinkTopics(enableCompatibilityWithJsonPayloadFormat && useJsonPayloadFormatForDefaultDownlinkTopics);
        transportPayloadTypeConfiguration = protoTransportPayloadConfiguration;
    }
    mqttDeviceProfileTransportConfiguration.setTransportPayloadTypeConfiguration(transportPayloadTypeConfiguration);
    deviceProfileData.setTransportConfiguration(mqttDeviceProfileTransportConfiguration);
    DeviceProfileProvisionConfiguration provisionConfiguration;
    switch(provisionType) {
        case ALLOW_CREATE_NEW_DEVICES:
            provisionConfiguration = new AllowCreateNewDevicesDeviceProfileProvisionConfiguration(provisionSecret);
            break;
        case CHECK_PRE_PROVISIONED_DEVICES:
            provisionConfiguration = new CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(provisionSecret);
            break;
        case DISABLED:
        default:
            provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(provisionSecret);
            break;
    }
    deviceProfileData.setProvisionConfiguration(provisionConfiguration);
    deviceProfileData.setConfiguration(configuration);
    deviceProfile.setProfileData(deviceProfileData);
    deviceProfile.setDefault(false);
    deviceProfile.setDefaultRuleChainId(null);
    return deviceProfile;
}
Also used : DefaultDeviceProfileConfiguration(org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration) AllowCreateNewDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration) DisabledDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration) DeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.DeviceProfileProvisionConfiguration) MqttDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration) ProtoTransportPayloadConfiguration(org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration) TransportPayloadTypeConfiguration(org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration) AllowCreateNewDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration) CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData) JsonTransportPayloadConfiguration(org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration) DisabledDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration)

Example 4 with DeviceProfileData

use of org.thingsboard.server.common.data.device.profile.DeviceProfileData in project thingsboard by thingsboard.

the class BaseEdgeTest method extendDeviceProfileData.

private void extendDeviceProfileData(DeviceProfile deviceProfile) {
    DeviceProfileData profileData = deviceProfile.getProfileData();
    List<DeviceProfileAlarm> alarms = new ArrayList<>();
    DeviceProfileAlarm deviceProfileAlarm = new DeviceProfileAlarm();
    deviceProfileAlarm.setAlarmType("High Temperature");
    AlarmRule alarmRule = new AlarmRule();
    alarmRule.setAlarmDetails("Alarm Details");
    AlarmCondition alarmCondition = new AlarmCondition();
    alarmCondition.setSpec(new SimpleAlarmConditionSpec());
    List<AlarmConditionFilter> condition = new ArrayList<>();
    AlarmConditionFilter alarmConditionFilter = new AlarmConditionFilter();
    alarmConditionFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.ATTRIBUTE, "temperature"));
    NumericFilterPredicate predicate = new NumericFilterPredicate();
    predicate.setOperation(NumericFilterPredicate.NumericOperation.GREATER);
    predicate.setValue(new FilterPredicateValue<>(55.0));
    alarmConditionFilter.setPredicate(predicate);
    alarmConditionFilter.setValueType(EntityKeyValueType.NUMERIC);
    condition.add(alarmConditionFilter);
    alarmCondition.setCondition(condition);
    alarmRule.setCondition(alarmCondition);
    deviceProfileAlarm.setClearRule(alarmRule);
    TreeMap<AlarmSeverity, AlarmRule> createRules = new TreeMap<>();
    createRules.put(AlarmSeverity.CRITICAL, alarmRule);
    deviceProfileAlarm.setCreateRules(createRules);
    alarms.add(deviceProfileAlarm);
    profileData.setAlarms(alarms);
    profileData.setProvisionConfiguration(new AllowCreateNewDevicesDeviceProfileProvisionConfiguration("123"));
}
Also used : AlarmSeverity(org.thingsboard.server.common.data.alarm.AlarmSeverity) NumericFilterPredicate(org.thingsboard.server.common.data.query.NumericFilterPredicate) AlarmRule(org.thingsboard.server.common.data.device.profile.AlarmRule) ArrayList(java.util.ArrayList) SimpleAlarmConditionSpec(org.thingsboard.server.common.data.device.profile.SimpleAlarmConditionSpec) TreeMap(java.util.TreeMap) AlarmConditionFilter(org.thingsboard.server.common.data.device.profile.AlarmConditionFilter) AlarmCondition(org.thingsboard.server.common.data.device.profile.AlarmCondition) DeviceProfileAlarm(org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm) AllowCreateNewDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData) AlarmConditionFilterKey(org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)

Example 5 with DeviceProfileData

use of org.thingsboard.server.common.data.device.profile.DeviceProfileData in project thingsboard by thingsboard.

the class AbstractServiceTest method createDeviceProfile.

protected DeviceProfile createDeviceProfile(TenantId tenantId, String name) {
    DeviceProfile deviceProfile = new DeviceProfile();
    deviceProfile.setTenantId(tenantId);
    deviceProfile.setName(name);
    deviceProfile.setType(DeviceProfileType.DEFAULT);
    deviceProfile.setTransportType(DeviceTransportType.DEFAULT);
    deviceProfile.setDescription(name + " Test");
    DeviceProfileData deviceProfileData = new DeviceProfileData();
    DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration();
    DefaultDeviceProfileTransportConfiguration transportConfiguration = new DefaultDeviceProfileTransportConfiguration();
    deviceProfileData.setConfiguration(configuration);
    deviceProfileData.setTransportConfiguration(transportConfiguration);
    deviceProfile.setProfileData(deviceProfileData);
    deviceProfile.setDefault(false);
    deviceProfile.setDefaultRuleChainId(null);
    return deviceProfile;
}
Also used : DefaultDeviceProfileConfiguration(org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DefaultDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileTransportConfiguration) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData)

Aggregations

DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)25 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)24 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)16 Test (org.junit.Test)16 AlarmCondition (org.thingsboard.server.common.data.device.profile.AlarmCondition)16 AlarmConditionFilter (org.thingsboard.server.common.data.device.profile.AlarmConditionFilter)16 AlarmConditionFilterKey (org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)16 AlarmRule (org.thingsboard.server.common.data.device.profile.AlarmRule)16 DeviceProfileAlarm (org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm)16 NumericFilterPredicate (org.thingsboard.server.common.data.query.NumericFilterPredicate)16 TbMsg (org.thingsboard.server.common.msg.TbMsg)16 TbMsgMetaData (org.thingsboard.server.common.msg.TbMsgMetaData)16 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)13 DynamicValue (org.thingsboard.server.common.data.query.DynamicValue)13 AttributeKvCompositeKey (org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey)13 AttributeKvEntity (org.thingsboard.server.dao.model.sql.AttributeKvEntity)13 List (java.util.List)12 Device (org.thingsboard.server.common.data.Device)9 DefaultDeviceProfileConfiguration (org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration)8 Optional (java.util.Optional)7