Skip to content

Commit

Permalink
fix composers to accept 0 address
Browse files Browse the repository at this point in the history
  • Loading branch information
aldas committed Apr 4, 2019
1 parent 1111df2 commit 1f6620b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Composer/Read/ReadRegistersBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function fromArray(array $register): ReadRegistersBuilder
}

$address = $register['address'] ?? null;
if (empty($address)) {
if ($address === null) {
throw new InvalidArgumentException('empty address given');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Write/WriteRegistersBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function fromArray(array $register): WriteRegistersBuilder
}

$address = $register['address'] ?? null;
if (empty($address)) {
if ($address === null) {
throw new InvalidArgumentException('empty address given');
}

Expand Down Expand Up @@ -184,4 +184,4 @@ public function isNotEmpty()
{
return !empty($this->addresses);
}
}
}
10 changes: 5 additions & 5 deletions tests/unit/Composer/Read/ReadRegistersBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function testBuildAllFromArray()
['uri' => 'tcp://127.0.0.1:5022', 'type' => 'byte', 'address' => 256, 'firstByte' => true, 'name' => 'username_first_char'],
['uri' => 'tcp://127.0.0.1:5022', 'type' => 'string', 'address' => 256, 'length' => 10, 'name' => 'username'],
// will be split into 2 requests as 1 request can return only range of 124 registers max
['uri' => 'tcp://127.0.0.1:5022', 'type' => 'uint16', 'address' => 453, 'name' => 'gen1_fuel_rate_wo'],
['uri' => 'tcp://127.0.0.1:5022', 'type' => 'uint16', 'address' => 454, 'name' => 'gen2_fuel_rate_wo'],
['uri' => 'tcp://127.0.0.1:5022', 'type' => 'uint16', 'address' => 0, 'name' => 'gen1_fuel_rate_wo'],
['uri' => 'tcp://127.0.0.1:5022', 'type' => 'uint16', 'address' => 1, 'name' => 'gen2_fuel_rate_wo'],
// will be another request as uri is different for subsequent string register
['uri' => 'tcp://127.0.0.1:5023', 'type' => 'uint16', 'address' => 270, 'name' => 'room7_temp_wo'],
['uri' => 'tcp://127.0.0.1:5023', 'type' => 'int16', 'address' => 270, 'name' => 'room8_temp_wo'],
Expand All @@ -70,8 +70,8 @@ public function testBuildAllFromArray()

$this->assertCount(3, $requests);

$this->assertCount(4, $requests[0]->getAddresses());
$this->assertCount(2, $requests[1]->getAddresses());
$this->assertCount(2, $requests[0]->getAddresses());
$this->assertCount(4, $requests[1]->getAddresses());
$this->assertCount(7, $requests[2]->getAddresses());
}

Expand Down Expand Up @@ -318,4 +318,4 @@ public function testIsNotEmptyFalse() {

$this->assertFalse($builder->isNotEmpty());
}
}
}
4 changes: 2 additions & 2 deletions tests/unit/Composer/Write/WriteRegistersBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testBuildAllFromArray()
{
$requests = WriteRegistersBuilder::newWriteMultipleRegisters('tcp://127.0.0.1:5022')
->allFromArray([
['uri' => 'tcp://127.0.0.1:5022', 'type' => 'string', 'value' => 'Søren', 'address' => 256, 'length' => 10],
['uri' => 'tcp://127.0.0.1:5022', 'type' => 'string', 'value' => 'Søren', 'address' => 0, 'length' => 10],
// will be split into 2 requests as 1 request can return only range of 124 registers max
['uri' => 'tcp://127.0.0.1:5022', 'type' => 'uint16', 'value' => 1, 'address' => 453],
['uri' => 'tcp://127.0.0.1:5022', 'type' => 'uint16', 'value' => 1, 'address' => 454],
Expand Down Expand Up @@ -246,4 +246,4 @@ public function testIsNotEmptyFalse() {
$this->assertFalse($builder->isNotEmpty());
}

}
}

0 comments on commit 1f6620b

Please sign in to comment.