Skip to content

Commit

Permalink
Merge branch '5893-5897' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
JalalLinuX committed Oct 30, 2023
2 parents e13bdad + 8551641 commit 28efa7b
Show file tree
Hide file tree
Showing 21 changed files with 900 additions and 1 deletion.
81 changes: 81 additions & 0 deletions src/Entities/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,85 @@ public function getTenantAsset(string $name = null): static

return $this->fill($asset);
}

/**
* Creates assignment of an existing asset to an instance of The Edge.
* Assignment works in async way - first, notification event pushed to edge service queue on platform.
* Second, remote edge service will receive a copy of assignment asset
* (Edge will receive this instantly, if it's currently connected, or once it's going to be connected to platform).
* Third, once asset will be delivered to edge service, it's going to be available for usage on remote edge instance.
*
* @param string $edgeId
* @param string|null $id
* @return $this
*
* @author JalalLinuX
*
* @group TENANT_ADMIN
*/
public function assignAssetToEdge(string $edgeId, string $id = null): static
{
$id = $id ?? $this->forceAttribute('id')->id;

Thingsboard::validation(! Str::isUuid($id), 'uuid', ['attribute' => 'assetId']);
Thingsboard::validation(! Str::isUuid($edgeId), 'uuid', ['attribute' => 'edgeId']);

$asset = $this->api()->post("edge/{$edgeId}/asset/{$id}")->json();

return $this->fill($asset);
}

/**
* Clears assignment of the asset to the edge.
* Unassignment works in async way - first, 'unassign' notification event pushed to edge queue on platform.
* Second, remote edge service will receive an 'unassign' command to remove asset
* (Edge will receive this instantly, if it's currently connected, or once it's going to be connected to platform).
* Third, once 'unassign' command will be delivered to edge service, it's going to remove asset locally.
*
* @param string $edgeId
* @param string|null $id
* @return $this
*
* @author JalalLinuX
*
* @group TENANT_ADMIN
*/
public function unassignAssetFromEdge(string $edgeId, string $id = null): static
{
$id = $id ?? $this->forceAttribute('id')->id;

Thingsboard::validation(! Str::isUuid($id), 'uuid', ['attribute' => 'assetId']);
Thingsboard::validation(! Str::isUuid($edgeId), 'uuid', ['attribute' => 'edgeId']);

$asset = $this->api()->delete("edge/{$edgeId}/asset/{$id}")->json();

return $this->fill($asset);
}

/**
* Returns a page of assets assigned to edge.
* You can specify parameters to filter the results.
* The result is wrapped with PageData object that allows you to iterate over result set using pagination.
* See the 'Model' tab of the Response Class for more details.
*
* @param PaginationArguments $paginationArguments
* @param string|null $edgeId
* @param string|null $type
* @return LengthAwarePaginator
*
* @author JalalLinuX
*
* @group TENANT_ADMIN | CUSTOMER_USER
*/
public function getEdgeAssets(PaginationArguments $paginationArguments, string $edgeId = null, string $type = null): LengthAwarePaginator
{
$edgeId = $edgeId ?? $this->forceAttribute('id')->id;
$paginationArguments->validateSortProperty(EnumAssetSortProperty::class);

$response = $this->api()->get("edge/{$edgeId}/assets", $paginationArguments->queryParams([
'type' => $type ?? @$this->type,
]));

return $this->paginatedResponse($response, $paginationArguments);
}
}
79 changes: 79 additions & 0 deletions src/Entities/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,83 @@ public function removeDashboardCustomers(array $customerIds, string $id = null):

return $this->fill($dashboard);
}

/**
* Creates assignment of an existing dashboard to an instance of The Edge.
* Assignment works in async way - first, notification event pushed to edge service queue on platform.
* Second, remote edge service will receive a copy of assignment dashboard
* (Edge will receive this instantly, if it's currently connected, or once it's going to be connected to platform).
* Third, once dashboard will be delivered to edge service, it's going to be available for usage on remote edge instance.
*
* @param string $edgeId
* @param string|null $id
* @return $this
*
* @author JalalLinuX
*
* @group TENANT_ADMIN
*/
public function assignDashboardToEdge(string $edgeId, string $id = null): static
{
$id = $id ?? $this->forceAttribute('id')->id;

Thingsboard::validation(! Str::isUuid($id), 'uuid', ['attribute' => 'dashboardId']);
Thingsboard::validation(! Str::isUuid($edgeId), 'uuid', ['attribute' => 'edgeId']);

$dashboard = $this->api()->post("edge/{$edgeId}/dashboard/{$id}")->json();

return $this->fill($dashboard);
}

/**
* Clears assignment of the dashboard to the edge.
* Unassignment works in async way - first, 'unassign' notification event pushed to edge queue on platform.
* Second, remote edge service will receive an 'unassign' command to remove dashboard
* (Edge will receive this instantly, if it's currently connected, or once it's going to be connected to platform).
* Third, once 'unassign' command will be delivered to edge service, it's going to remove dashboard locally.
*
* @param string $edgeId
* @param string|null $id
* @return $this
*
* @author JalalLinuX
*
* @group TENANT_ADMIN
*/
public function unassignDashboardFromEdge(string $edgeId, string $id = null): static
{
$id = $id ?? $this->forceAttribute('id')->id;

Thingsboard::validation(! Str::isUuid($id), 'uuid', ['attribute' => 'dashboardId']);
Thingsboard::validation(! Str::isUuid($edgeId), 'uuid', ['attribute' => 'edgeId']);

$dashboard = $this->api()->delete("edge/{$edgeId}/dashboard/{$id}")->json();

return $this->fill($dashboard);
}

/**
* Returns a page of dashboard info objects assigned to the specified edge.
* The Dashboard Info object contains lightweight information about the dashboard (e.g. title, image, assigned customers) but does not contain the heavyweight configuration JSON.
* You can specify parameters to filter the results.
* The result is wrapped with PageData object that allows you to iterate over result set using pagination.
* See the 'Model' tab of the Response Class for more details.
*
* @param PaginationArguments $paginationArguments
* @param string|null $edgeId
* @return LengthAwarePaginator
*
* @author JalalLinuX
*
* @group TENANT_ADMIN | CUSTOMER_USER
*/
public function getEdgeDashboards(PaginationArguments $paginationArguments, string $edgeId = null): LengthAwarePaginator
{
$edgeId = $edgeId ?? $this->forceAttribute('id')->id;
$paginationArguments->validateSortProperty(EnumDashboardSortProperty::class);

$response = $this->api()->get("edge/{$edgeId}/dashboards", $paginationArguments->queryParams());

return $this->paginatedResponse($response, $paginationArguments);
}
}
84 changes: 84 additions & 0 deletions src/Entities/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,88 @@ public function assignDeviceToPublicCustomer(string $id = null): static

return $this->fill($device);
}

/**
* Creates assignment of an existing device to an instance of The Edge.
* Assignment works in async way - first, notification event pushed to edge service queue on platform.
* Second, remote edge service will receive a copy of assignment device.
* (Edge will receive this instantly, if it's currently connected, or once it's going to be connected to platform).
* Third, once device will be delivered to edge service, it's going to be available for usage on remote edge instance.
*
* @param string $edgeId
* @param string|null $id
* @return $this
*
* @author JalalLinuX
*
* @group TENANT_ADMIN
*/
public function assignDeviceToEdge(string $edgeId, string $id = null): static
{
$id = $id ?? $this->forceAttribute('id')->id;

Thingsboard::validation(! Str::isUuid($id), 'uuid', ['attribute' => 'deviceId']);
Thingsboard::validation(! Str::isUuid($edgeId), 'uuid', ['attribute' => 'edgeId']);

$device = $this->api()->post("edge/{$edgeId}/device/{$id}")->json();

return $this->fill($device);
}

/**
* Clears assignment of the device to the edge.
* Unassignment works in async way - first, 'unassign' notification event pushed to edge queue on platform.
* Second, remote edge service will receive an 'unassign' command to remove device
* (Edge will receive this instantly, if it's currently connected, or once it's going to be connected to platform).
* Third, once 'unassign' command will be delivered to edge service, it's going to remove device locally.
*
* @param string $edgeId
* @param string|null $id
* @return $this
*
* @author JalalLinuX
*
* @group TENANT_ADMIN
*/
public function unassignDeviceFromEdge(string $edgeId, string $id = null): static
{
$id = $id ?? $this->forceAttribute('id')->id;

Thingsboard::validation(! Str::isUuid($id), 'uuid', ['attribute' => 'deviceId']);
Thingsboard::validation(! Str::isUuid($edgeId), 'uuid', ['attribute' => 'edgeId']);

$device = $this->api()->delete("edge/{$edgeId}/device/{$id}")->json();

return $this->fill($device);
}

/**
* Returns a page of devices assigned to edge.
* You can specify parameters to filter the results.
* The result is wrapped with PageData object that allows you to iterate over result set using pagination.
* See the 'Model' tab of the Response Class for more details.
*
* @param PaginationArguments $paginationArguments
* @param string|null $edgeId
* @param string|null $deviceProfileId
* @param bool|null $active
* @param string|null $type
* @return LengthAwarePaginator
*
* @author JalalLinuX
*
* @group TENANT_ADMIN | CUSTOMER_USER
*/
public function getEdgeDevices(PaginationArguments $paginationArguments, string $edgeId = null, string $deviceProfileId = null, bool $active = null, string $type = null): LengthAwarePaginator
{
$edgeId = $edgeId ?? $this->forceAttribute('id')->id;
$paginationArguments->validateSortProperty(EnumDeviceSortProperty::class);

$response = $this->api()->get("edge/{$edgeId}/devices", $paginationArguments->queryParams([
'active' => $active ?? @$this->active, 'type' => $type ?? @$this->type,
'deviceProfileId' => $deviceProfileId ?? @$this->deviceProfileId->id,
]));

return $this->paginatedResponse($response, $paginationArguments);
}
}
2 changes: 1 addition & 1 deletion src/Entities/Edge.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function getCustomerEdges(string $customerId, PaginationArguments $pagina
*/
public function setEdgeRootRuleChain(string $ruleChainId, string $id = null): static
{
$id = $id ?? $this->forceAttribute('id');
$id = $id ?? $this->forceAttribute('id')->id;

Thingsboard::validation(! Str::isUuid($id), 'uuid', ['attribute' => 'edgeId']);
Thingsboard::validation(! Str::isUuid($ruleChainId), 'uuid', ['attribute' => 'ruleChainId']);
Expand Down
78 changes: 78 additions & 0 deletions src/Entities/EdgeEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace JalalLinuX\Thingsboard\Entities;

use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Str;
use JalalLinuX\Thingsboard\Casts\CastId;
use JalalLinuX\Thingsboard\Enums\EnumEdgeEventAction;
use JalalLinuX\Thingsboard\Enums\EnumEdgeEventType;
use JalalLinuX\Thingsboard\Enums\EnumEntityType;
use JalalLinuX\Thingsboard\Infrastructure\Id;
use JalalLinuX\Thingsboard\Infrastructure\PaginationArguments;
use JalalLinuX\Thingsboard\Thingsboard;
use JalalLinuX\Thingsboard\Tntity;

/**
* @property string $id
* @property \DateTime $createdTime
* @property Id $tenantId
* @property Id $edgeId
* @property EnumEdgeEventAction $action
* @property EnumEdgeEventType $type
* @property string $entityId
* @property string $uid
* @property string $body
*/
class EdgeEvent extends Tntity
{
protected $fillable = [
'id',
'createdTime',
'tenantId',
'edgeId',
'action',
'type',
'entityId',
'uid',
'body',
];

protected $casts = [
'id' => 'array',
'tenantId' => CastId::class,
'createdTime' => 'timestamp',
'edgeId' => CastId::class,
'action' => EnumEdgeEventAction::class,
'type' => EnumEdgeEventType::class,
'body' => 'array',
];

public function entityType(): ?EnumEntityType
{
return EnumEntityType::EDGE_EVENT();
}

/**
* Returns a page of edge events for the requested edge.
* You can specify parameters to filter the results.
* The result is wrapped with PageData object that allows you to iterate over result set using pagination.
* See the 'Model' tab of the Response Class for more details.
*
* @param PaginationArguments $paginationArguments
* @param string $edgeId
* @return LengthAwarePaginator
*
* @author JalalLinuX
*
* @group TENANT_ADMIN
*/
public function getEdgeEvents(PaginationArguments $paginationArguments, string $edgeId): LengthAwarePaginator
{
Thingsboard::validation(! Str::isUuid($edgeId), 'uuid', ['attribute' => 'edgeId']);

$response = $this->api()->get("edge/{$edgeId}/events", $paginationArguments->queryParams());

return $this->paginatedResponse($response, $paginationArguments);
}
}

0 comments on commit 28efa7b

Please sign in to comment.