Commit 2290079c authored by Roman Ondráček's avatar Roman Ondráček

IQRF net: add error message for device info table if daemon is not correctly responding

Signed-off-by: Roman Ondráček's avatarRoman Ondráček <ondracek.roman@centrum.cz>
parent 850dba4c
Pipeline #2395 passed with stages
in 20 minutes and 46 seconds
......@@ -72,7 +72,11 @@ class DevicesManager {
$base = 10;
}
$this->createEmptyTable($base);
$this->fillTable($base, $ping);
try {
$this->fillTable($base, $ping);
} catch (UserErrorException | DpaErrorException | EmptyResponseException | JsonException $e) {
return null;
}
$this->table[0][0]->setType(DeviceTypes::COORDINATOR);
return $this->table;
}
......@@ -93,6 +97,10 @@ class DevicesManager {
* Fills table with devices
* @param int $base Base
* @param bool $ping Perform ping?
* @throws DpaErrorException
* @throws EmptyResponseException
* @throws JsonException
* @throws UserErrorException
*/
private function fillTable(int $base, bool $ping = false): void {
$devices = [];
......@@ -102,20 +110,16 @@ class DevicesManager {
}
foreach ($deviceTypes as $deviceType) {
try {
switch ($deviceType) {
case DeviceTypes::BONDED:
$devices = $this->getBonded();
break;
case DeviceTypes::DISCOVERED:
$devices = $this->getDiscovered();
break;
case DeviceTypes::ONLINE:
$devices = $this->ping();
break;
}
} catch (UserErrorException | DpaErrorException | EmptyResponseException | JsonException $e) {
$devices = [];
switch ($deviceType) {
case DeviceTypes::BONDED:
$devices = $this->getBonded();
break;
case DeviceTypes::DISCOVERED:
$devices = $this->getDiscovered();
break;
case DeviceTypes::ONLINE:
$devices = $this->ping();
break;
}
foreach ($devices as $node) {
if ($node > 239) {
......
......@@ -16,7 +16,7 @@
*}
{snippet showDevices}
<div n:ifset='$devices' class='box box-primary'>
<div class='box box-primary'>
<header class='box-header with-border'>
<h2 class='box-title'>{_iqrfnet.devices.title}</h2>
</header>
......@@ -48,20 +48,27 @@
</tr>
</table>
<a n:href='showNodes! true' class='ajax btn btn-primary center-block'>{_iqrfnet.devices.pingNodes}</a>
<table class='table table-striped'>
<tr>
<th>&nbsp;</th>
<th n:for='$i = 0; $i < $base; $i++'>{$i}</th>
</tr>
<tr n:foreach='$devices as $tens => $line'>
<th>{$tens}0</th>
<td n:foreach='$line as $units => $device'>
<a n:tag-if='$device->getType() !== 0' n:href='Enumeration:default address => $device->getAddress()'>
{$device->getIcon()|noescape}
</a>
</td>
</tr>
</table>
{ifset $devices}
<table class='table table-striped'>
<tr>
<th>&nbsp;</th>
<th n:for='$i = 0; $i < $base; $i++'>{$i}</th>
</tr>
<tr n:foreach='$devices as $tens => $line'>
<th>{$tens}0</th>
<td n:foreach='$line as $units => $device'>
<a n:tag-if='$device->getType() !== 0' n:href='Enumeration:default address => $device->getAddress()'>
{$device->getIcon()|noescape}
</a>
</td>
</tr>
</table>
{else}
<br>
<div class='alert alert-danger' role='alert'>
{_iqrfnet.webSocketClient.messages.emptyResponse}
</div>
{/ifset}
</section>
</div>
{/snippet}
......@@ -81,41 +81,7 @@ class DevicesManagerTest extends WebSocketTestCase {
->andThrow(DpaErrorException::class);
$this->manager->shouldReceive('getDiscovered')
->andThrow(DpaErrorException::class);
$table = [
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
];
$expected = [];
foreach ($table as $x => $row) {
foreach ($row as $y => $item) {
$status = new DeviceStatus($x * 10 + $y);
$status->setType($item);
$expected[$x][$y] = $status;
}
}
Assert::equal($expected, $this->manager->getTable(0));
Assert::null($this->manager->getTable(0));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment