Search in sources :

Example 56 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class DefaultTbContext method alarmActionMsg.

public TbMsg alarmActionMsg(Alarm alarm, RuleNodeId ruleNodeId, String action) {
    RuleChainId ruleChainId = null;
    String queueName = ServiceQueue.MAIN;
    if (EntityType.DEVICE.equals(alarm.getOriginator().getEntityType())) {
        DeviceId deviceId = new DeviceId(alarm.getOriginator().getId());
        DeviceProfile deviceProfile = mainCtx.getDeviceProfileCache().get(getTenantId(), deviceId);
        if (deviceProfile == null) {
            log.warn("[{}] Device profile is null!", deviceId);
            ruleChainId = null;
            queueName = ServiceQueue.MAIN;
        } else {
            ruleChainId = deviceProfile.getDefaultRuleChainId();
            String defaultQueueName = deviceProfile.getDefaultQueueName();
            queueName = defaultQueueName != null ? defaultQueueName : ServiceQueue.MAIN;
        }
    }
    return entityActionMsg(alarm, alarm.getId(), ruleNodeId, action, queueName, ruleChainId);
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceId(org.thingsboard.server.common.data.id.DeviceId) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId)

Example 57 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class DefaultTbContext method deviceCreatedMsg.

public TbMsg deviceCreatedMsg(Device device, RuleNodeId ruleNodeId) {
    RuleChainId ruleChainId = null;
    String queueName = ServiceQueue.MAIN;
    if (device.getDeviceProfileId() != null) {
        DeviceProfile deviceProfile = mainCtx.getDeviceProfileCache().find(device.getDeviceProfileId());
        if (deviceProfile == null) {
            log.warn("[{}] Device profile is null!", device.getDeviceProfileId());
            ruleChainId = null;
            queueName = ServiceQueue.MAIN;
        } else {
            ruleChainId = deviceProfile.getDefaultRuleChainId();
            String defaultQueueName = deviceProfile.getDefaultQueueName();
            queueName = defaultQueueName != null ? defaultQueueName : ServiceQueue.MAIN;
        }
    }
    return entityActionMsg(device, device.getId(), ruleNodeId, DataConstants.ENTITY_CREATED, queueName, ruleChainId);
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId)

Example 58 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class DefaultOtaPackageStateService method updateSoftware.

private void updateSoftware(Device device, Device oldDevice) {
    OtaPackageId newSoftwareId = device.getSoftwareId();
    if (newSoftwareId == null) {
        DeviceProfile newDeviceProfile = deviceProfileService.findDeviceProfileById(device.getTenantId(), device.getDeviceProfileId());
        newSoftwareId = newDeviceProfile.getSoftwareId();
    }
    if (oldDevice != null) {
        OtaPackageId oldSoftwareId = oldDevice.getSoftwareId();
        if (oldSoftwareId == null) {
            DeviceProfile oldDeviceProfile = deviceProfileService.findDeviceProfileById(oldDevice.getTenantId(), oldDevice.getDeviceProfileId());
            oldSoftwareId = oldDeviceProfile.getSoftwareId();
        }
        if (newSoftwareId != null) {
            if (!newSoftwareId.equals(oldSoftwareId)) {
                // Device was updated and new firmware is different from previous firmware.
                send(device.getTenantId(), device.getId(), newSoftwareId, System.currentTimeMillis(), SOFTWARE);
            }
        } else if (oldSoftwareId != null) {
            // Device was updated and new firmware is not set.
            remove(device, SOFTWARE);
        }
    } else if (newSoftwareId != null) {
        // Device was created and firmware is defined.
        send(device.getTenantId(), device.getId(), newSoftwareId, System.currentTimeMillis(), SOFTWARE);
    }
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) OtaPackageId(org.thingsboard.server.common.data.id.OtaPackageId)

Example 59 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class DefaultTbDeviceProfileCache method evict.

@Override
public void evict(TenantId tenantId, DeviceProfileId profileId) {
    DeviceProfile oldProfile = deviceProfilesMap.remove(profileId);
    log.debug("[{}] evict device profile from cache: {}", profileId, oldProfile);
    DeviceProfile newProfile = get(tenantId, profileId);
    if (newProfile != null) {
        notifyProfileListeners(newProfile);
    }
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile)

Example 60 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class DefaultEdgeRequestsService method processDeviceProfileDevicesRequestMsg.

@Override
public ListenableFuture<Void> processDeviceProfileDevicesRequestMsg(TenantId tenantId, Edge edge, DeviceProfileDevicesRequestMsg deviceProfileDevicesRequestMsg) {
    log.trace("[{}] processDeviceProfileDevicesRequestMsg [{}][{}]", tenantId, edge.getName(), deviceProfileDevicesRequestMsg);
    if (deviceProfileDevicesRequestMsg.getDeviceProfileIdMSB() != 0 && deviceProfileDevicesRequestMsg.getDeviceProfileIdLSB() != 0) {
        DeviceProfileId deviceProfileId = new DeviceProfileId(new UUID(deviceProfileDevicesRequestMsg.getDeviceProfileIdMSB(), deviceProfileDevicesRequestMsg.getDeviceProfileIdLSB()));
        DeviceProfile deviceProfileById = deviceProfileService.findDeviceProfileById(tenantId, deviceProfileId);
        if (deviceProfileById != null) {
            syncDevices(tenantId, edge, deviceProfileById.getName());
        }
    }
    return Futures.immediateFuture(null);
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) UUID(java.util.UUID)

Aggregations

DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)110 Test (org.junit.Test)48 Device (org.thingsboard.server.common.data.Device)30 DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)26 List (java.util.List)20 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)19 TbMsg (org.thingsboard.server.common.msg.TbMsg)19 DeviceProfileAlarm (org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm)18 TbMsgMetaData (org.thingsboard.server.common.msg.TbMsgMetaData)18 AlarmConditionFilterKey (org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)17 AlarmRule (org.thingsboard.server.common.data.device.profile.AlarmRule)17 AlarmCondition (org.thingsboard.server.common.data.device.profile.AlarmCondition)16 AlarmConditionFilter (org.thingsboard.server.common.data.device.profile.AlarmConditionFilter)16 NumericFilterPredicate (org.thingsboard.server.common.data.query.NumericFilterPredicate)16 DynamicValue (org.thingsboard.server.common.data.query.DynamicValue)14 DeviceProfileId (org.thingsboard.server.common.data.id.DeviceProfileId)13 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)13 AttributeKvCompositeKey (org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey)13 AttributeKvEntity (org.thingsboard.server.dao.model.sql.AttributeKvEntity)13 UUID (java.util.UUID)12