Skip to content

Commit

Permalink
Merge with upstream/master
Browse files Browse the repository at this point in the history
  • Loading branch information
ikulikov committed Aug 4, 2021
2 parents 3666a71 + d0ce260 commit 87df61c
Show file tree
Hide file tree
Showing 154 changed files with 3,910 additions and 2,915 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ThingsBoard PE API client library for Dart developers. It's compatible with TB PE 3.3.0.
ThingsBoard PE API client library for Dart developers. Provides model objects and services to communicate with ThingsBoard PE platform using RESTful APIs and WebSocket protocol.
Current client version is compatible with ThingsBoard PE starting from version 3.3.0PE.

## Usage

Expand Down
7 changes: 4 additions & 3 deletions example/callbacks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ Future<void> onUserLoaded() async {
print('authUser: ${tbClient.getAuthUser()}');
var currentUserDetails = await tbClient.getUserService().getUser();
print('currentUserDetails: $currentUserDetails');
await tbClient.logout(requestConfig: RequestConfig(ignoreLoading: true, ignoreErrors: true));
await tbClient.logout(
requestConfig:
RequestConfig(ignoreLoading: true, ignoreErrors: true));
exit(0);
} else {
await tbClient.login(LoginRequest('tenant@thingsboard.org', 'tenant'));
}
}
catch (e, s) {
} catch (e, s) {
print('Error: $e');
print('Stack: $s');
}
Expand Down
35 changes: 22 additions & 13 deletions example/device_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,46 @@ void main() async {

await deviceApiExample();

await tbClient.logout(requestConfig: RequestConfig(ignoreLoading: true, ignoreErrors: true));

await tbClient.logout(
requestConfig: RequestConfig(ignoreLoading: true, ignoreErrors: true));
} catch (e, s) {
print('Error: $e');
print('Stack: $s');
}
}

Future<void> deviceApiExample() async {
print('**********************************************************************');
print('* DEVICE API EXAMPLE *');
print('**********************************************************************');
print(
'**********************************************************************');
print(
'* DEVICE API EXAMPLE *');
print(
'**********************************************************************');

var deviceName = getRandomString(30);

var device = Device(deviceName, 'default');
device.additionalInfo = {'description': 'My test device!'};
var savedDevice = await tbClient.getDeviceService().saveDevice(device);
print('savedDevice: $savedDevice');
var foundDevice = await tbClient.getDeviceService().getDevice(savedDevice.id!.id!);
var foundDevice =
await tbClient.getDeviceService().getDevice(savedDevice.id!.id!);
print('foundDevice: $foundDevice');
var res = await tbClient.getAttributeService().saveEntityAttributesV2(foundDevice!.id!, AttributeScope.SHARED_SCOPE.toShortString(), {
'targetTemperature': 22.4,
'targetHumidity': 57.8
});
var res = await tbClient.getAttributeService().saveEntityAttributesV2(
foundDevice!.id!,
AttributeScope.SHARED_SCOPE.toShortString(),
{'targetTemperature': 22.4, 'targetHumidity': 57.8});
print('Save attributes result: $res');
var attributes = await tbClient.getAttributeService().getAttributesByScope(foundDevice.id!, AttributeScope.SHARED_SCOPE.toShortString(), ['targetTemperature', 'targetHumidity']);
var attributes = await tbClient.getAttributeService().getAttributesByScope(
foundDevice.id!,
AttributeScope.SHARED_SCOPE.toShortString(),
['targetTemperature', 'targetHumidity']);
print('Found device attributes: $attributes');

await tbClient.getDeviceService().deleteDevice(savedDevice.id!.id!);
foundDevice = await tbClient.getDeviceService().getDevice(savedDevice.id!.id!);
foundDevice =
await tbClient.getDeviceService().getDevice(savedDevice.id!.id!);
print('foundDevice: $foundDevice');
print('**********************************************************************');
print(
'**********************************************************************');
}
80 changes: 54 additions & 26 deletions example/entity_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,68 +16,96 @@ void main() async {
await fetchEntityGroupEntitiesExample();
await getOwnersExample();

await tbClient.logout(requestConfig: RequestConfig(ignoreLoading: true, ignoreErrors: true));

await tbClient.logout(
requestConfig: RequestConfig(ignoreLoading: true, ignoreErrors: true));
} catch (e, s) {
print('Error: $e');
print('Stack: $s');
}
}

Future<void> fetchEntityGroupsExample() async {
print('**********************************************************************');
print('* FETCH ENTITY GROUPS EXAMPLE *');
print('**********************************************************************');

for (var groupType in [EntityType.DEVICE, EntityType.ASSET, EntityType.ENTITY_VIEW,
EntityType.DASHBOARD, EntityType.CUSTOMER, EntityType.USER, EntityType.EDGE]) {
var entityGroups = await tbClient.getEntityGroupService().getEntityGroupsByType(groupType);
print(
'**********************************************************************');
print(
'* FETCH ENTITY GROUPS EXAMPLE *');
print(
'**********************************************************************');

for (var groupType in [
EntityType.DEVICE,
EntityType.ASSET,
EntityType.ENTITY_VIEW,
EntityType.DASHBOARD,
EntityType.CUSTOMER,
EntityType.USER,
EntityType.EDGE
]) {
var entityGroups =
await tbClient.getEntityGroupService().getEntityGroupsByType(groupType);
print('found ${groupType.toShortString()} groups: $entityGroups');
}

print('**********************************************************************');
print(
'**********************************************************************');
}

Future<void> fetchEntityGroupEntitiesExample() async {
print('**********************************************************************');
print('* FETCH ENTITY GROUP ENTITIES EXAMPLE *');
print('**********************************************************************');

var deviceGroupAll = await tbClient.getEntityGroupService().getEntityGroupAllByOwnerAndType(TenantId(tbClient.getAuthUser()!.tenantId), EntityType.DEVICE);
print(
'**********************************************************************');
print(
'* FETCH ENTITY GROUP ENTITIES EXAMPLE *');
print(
'**********************************************************************');

var deviceGroupAll = await tbClient
.getEntityGroupService()
.getEntityGroupAllByOwnerAndType(
TenantId(tbClient.getAuthUser()!.tenantId), EntityType.DEVICE);
print('found device group all: $deviceGroupAll');

var pageLink = PageLink(10);
PageData<ShortEntityView> deviceEntities;
do {
deviceEntities = await tbClient.getEntityGroupService().getEntities(deviceGroupAll!.id!.id!, pageLink);
deviceEntities = await tbClient
.getEntityGroupService()
.getEntities(deviceGroupAll!.id!.id!, pageLink);
print('Device group all short entity views: $deviceEntities');
pageLink = pageLink.nextPageLink();
} while(deviceEntities.hasNext);
} while (deviceEntities.hasNext);

pageLink = PageLink(10);
PageData<Device> devices;
do {
devices = await tbClient.getDeviceService().getDevicesByEntityGroupId(deviceGroupAll.id!.id!, pageLink);
devices = await tbClient
.getDeviceService()
.getDevicesByEntityGroupId(deviceGroupAll.id!.id!, pageLink);
print('Device group all devices: $devices');
pageLink = pageLink.nextPageLink();
} while(devices.hasNext);
} while (devices.hasNext);

print('**********************************************************************');
print(
'**********************************************************************');
}

Future<void> getOwnersExample() async {
print('**********************************************************************');
print('* GET OWNERS EXAMPLE *');
print('**********************************************************************');
print(
'**********************************************************************');
print(
'* GET OWNERS EXAMPLE *');
print(
'**********************************************************************');

var pageLink = PageLink(10);
PageData<ContactBased> owners;
do {
owners = await tbClient.getEntityGroupService().getOwners(pageLink);
print('owners: $owners');
pageLink = pageLink.nextPageLink();
} while(owners.hasNext);
print('**********************************************************************');
} while (owners.hasNext);
print(
'**********************************************************************');

print('**********************************************************************');
print(
'**********************************************************************');
}
Loading

0 comments on commit 87df61c

Please sign in to comment.