Search in sources :

Example 1 with DeviceTransportConfiguration

use of org.thingsboard.server.common.data.device.data.DeviceTransportConfiguration 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)

Aggregations

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