Search in sources :

Example 1 with DeviceData

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

the class ProtoTransportEntityService method getDeviceById.

public Device getDeviceById(DeviceId id) {
    TransportProtos.GetDeviceResponseMsg deviceProto = transportService.getDevice(TransportProtos.GetDeviceRequestMsg.newBuilder().setDeviceIdMSB(id.getId().getMostSignificantBits()).setDeviceIdLSB(id.getId().getLeastSignificantBits()).build());
    if (deviceProto == null) {
        return null;
    }
    DeviceProfileId deviceProfileId = new DeviceProfileId(new UUID(deviceProto.getDeviceProfileIdMSB(), deviceProto.getDeviceProfileIdLSB()));
    Device device = new Device();
    device.setId(id);
    device.setDeviceProfileId(deviceProfileId);
    DeviceTransportConfiguration deviceTransportConfiguration = (DeviceTransportConfiguration) dataDecodingEncodingService.decode(deviceProto.getDeviceTransportConfiguration().toByteArray()).orElseThrow(() -> new IllegalStateException("Can't find device transport configuration"));
    DeviceData deviceData = new DeviceData();
    deviceData.setTransportConfiguration(deviceTransportConfiguration);
    device.setDeviceData(deviceData);
    return device;
}
Also used : DeviceTransportConfiguration(org.thingsboard.server.common.data.device.data.DeviceTransportConfiguration) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) Device(org.thingsboard.server.common.data.Device) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) DeviceData(org.thingsboard.server.common.data.device.data.DeviceData) UUID(java.util.UUID)

Example 2 with DeviceData

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

the class AbstractDeviceEntity method toDevice.

protected Device toDevice() {
    Device device = new Device(new DeviceId(getUuid()));
    device.setCreatedTime(createdTime);
    if (tenantId != null) {
        device.setTenantId(TenantId.fromUUID(tenantId));
    }
    if (customerId != null) {
        device.setCustomerId(new CustomerId(customerId));
    }
    if (deviceProfileId != null) {
        device.setDeviceProfileId(new DeviceProfileId(deviceProfileId));
    }
    if (firmwareId != null) {
        device.setFirmwareId(new OtaPackageId(firmwareId));
    }
    if (softwareId != null) {
        device.setSoftwareId(new OtaPackageId(softwareId));
    }
    device.setDeviceData(JacksonUtil.convertValue(deviceData, DeviceData.class));
    device.setName(name);
    device.setType(type);
    device.setLabel(label);
    device.setAdditionalInfo(additionalInfo);
    return device;
}
Also used : DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) Device(org.thingsboard.server.common.data.Device) DeviceId(org.thingsboard.server.common.data.id.DeviceId) OtaPackageId(org.thingsboard.server.common.data.id.OtaPackageId) DeviceData(org.thingsboard.server.common.data.device.data.DeviceData) CustomerId(org.thingsboard.server.common.data.id.CustomerId)

Aggregations

Device (org.thingsboard.server.common.data.Device)2 DeviceData (org.thingsboard.server.common.data.device.data.DeviceData)2 DeviceProfileId (org.thingsboard.server.common.data.id.DeviceProfileId)2 UUID (java.util.UUID)1 DeviceTransportConfiguration (org.thingsboard.server.common.data.device.data.DeviceTransportConfiguration)1 CustomerId (org.thingsboard.server.common.data.id.CustomerId)1 DeviceId (org.thingsboard.server.common.data.id.DeviceId)1 OtaPackageId (org.thingsboard.server.common.data.id.OtaPackageId)1 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)1