Search in sources :

Example 1 with SingleEntityFilter

use of org.thingsboard.server.common.data.query.SingleEntityFilter in project thingsboard by thingsboard.

the class AbstractLwM2MIntegrationTest method basicTestConnectionObserveTelemetry.

public void basicTestConnectionObserveTelemetry(Security security, LwM2MDeviceCredentials deviceCredentials, Configuration coapConfig, String endpoint) throws Exception {
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS, getBootstrapServerCredentialsNoSec(NONE));
    createDeviceProfile(transportConfiguration);
    Device device = createDevice(deviceCredentials, endpoint);
    SingleEntityFilter sef = new SingleEntityFilter();
    sef.setSingleEntity(device.getId());
    LatestValueCmd latestCmd = new LatestValueCmd();
    latestCmd.setKeys(Collections.singletonList(new EntityKey(EntityKeyType.TIME_SERIES, "batteryLevel")));
    EntityDataQuery edq = new EntityDataQuery(sef, new EntityDataPageLink(1, 0, null, null), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    EntityDataCmd cmd = new EntityDataCmd(1, edq, null, latestCmd, null);
    TelemetryPluginCmdsWrapper wrapper = new TelemetryPluginCmdsWrapper();
    wrapper.setEntityDataCmds(Collections.singletonList(cmd));
    wsClient.send(mapper.writeValueAsString(wrapper));
    wsClient.waitForReply();
    wsClient.registerWaitForUpdate();
    createNewClient(security, coapConfig, false, endpoint, false, null);
    String msg = wsClient.waitForUpdate();
    EntityDataUpdate update = mapper.readValue(msg, EntityDataUpdate.class);
    Assert.assertEquals(1, update.getCmdId());
    List<EntityData> eData = update.getUpdate();
    Assert.assertNotNull(eData);
    Assert.assertEquals(1, eData.size());
    Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
    Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.TIME_SERIES));
    var tsValue = eData.get(0).getLatest().get(EntityKeyType.TIME_SERIES).get("batteryLevel");
    Assert.assertThat(Long.parseLong(tsValue.getValue()), instanceOf(Long.class));
    int expectedMax = 50;
    int expectedMin = 5;
    Assert.assertTrue(expectedMax >= Long.parseLong(tsValue.getValue()));
    Assert.assertTrue(expectedMin <= Long.parseLong(tsValue.getValue()));
}
Also used : Device(org.thingsboard.server.common.data.Device) EntityDataPageLink(org.thingsboard.server.common.data.query.EntityDataPageLink) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) EntityData(org.thingsboard.server.common.data.query.EntityData) EntityDataUpdate(org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate) EntityKey(org.thingsboard.server.common.data.query.EntityKey) LatestValueCmd(org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd) EntityDataQuery(org.thingsboard.server.common.data.query.EntityDataQuery) SingleEntityFilter(org.thingsboard.server.common.data.query.SingleEntityFilter) EntityDataCmd(org.thingsboard.server.service.telemetry.cmd.v2.EntityDataCmd) TelemetryPluginCmdsWrapper(org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper)

Aggregations

Device (org.thingsboard.server.common.data.Device)1 Lwm2mDeviceProfileTransportConfiguration (org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration)1 EntityData (org.thingsboard.server.common.data.query.EntityData)1 EntityDataPageLink (org.thingsboard.server.common.data.query.EntityDataPageLink)1 EntityDataQuery (org.thingsboard.server.common.data.query.EntityDataQuery)1 EntityKey (org.thingsboard.server.common.data.query.EntityKey)1 SingleEntityFilter (org.thingsboard.server.common.data.query.SingleEntityFilter)1 TelemetryPluginCmdsWrapper (org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper)1 EntityDataCmd (org.thingsboard.server.service.telemetry.cmd.v2.EntityDataCmd)1 EntityDataUpdate (org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate)1 LatestValueCmd (org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd)1