Skip to content

Commit

Permalink
Fixing using state entity data
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Aug 11, 2021
1 parent 5cb8305 commit cda8863
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
4 changes: 0 additions & 4 deletions ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
<!-- we want brace on same line for multi-line definitions, checked by Squiz.Functions.MultiLineFunctionDeclaration -->
<exclude name="Generic.Functions.OpeningFunctionBraceBsdAllman.BraceOnSameLine"/>

<exclude name="SlevomatCodingStandard.ControlStructures.RequireTernaryOperator"/>
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
<exclude name="SlevomatCodingStandard.ControlStructures.AssignmentInCondition.assignmentInCondition"/>

<exclude name="SlevomatCodingStandard.Commenting.ForbiddenAnnotations.AnnotationForbidden"/>
<exclude name="SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectLinesCountBetweenDifferentAnnotationsTypes"/>

Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/PropertyHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class PropertyHelper
*
* @return bool|float|int|string|null
*/
public function normalizeValue(
public static function normalizeValue(
Entities\IProperty $property,
$value
) {
Expand Down
5 changes: 3 additions & 2 deletions src/Schemas/Channels/Properties/PropertySchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use FastyBird\DevicesModule;
use FastyBird\DevicesModule\Entities;
use FastyBird\DevicesModule\Helpers;
use FastyBird\DevicesModule\Models;
use FastyBird\DevicesModule\Router;
use FastyBird\DevicesModule\Schemas;
Expand Down Expand Up @@ -99,8 +100,8 @@ public function getAttributes($property, JsonApi\Contracts\Schema\ContextInterfa
'data_type' => $property->getDataType() !== null ? $property->getDataType()->getValue() : null,
'unit' => $property->getUnit(),
'format' => is_array($property->getFormat()) ? implode(',', $property->getFormat()) : $property->getFormat(),
'actual_value' => $state !== null ? $state->getActualValue() : null,
'expected_value' => $state !== null ? $state->getExpectedValue() : null,
'actual_value' => $state !== null ? Helpers\PropertyHelper::normalizeValue($property, $state->getActualValue()) : null,
'expected_value' => $state !== null ? Helpers\PropertyHelper::normalizeValue($property, $state->getExpectedValue()) : null,
'pending' => $state !== null && $state->isPending(),
];
}
Expand Down
5 changes: 3 additions & 2 deletions src/Schemas/Devices/Properties/PropertySchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use FastyBird\DevicesModule;
use FastyBird\DevicesModule\Entities;
use FastyBird\DevicesModule\Helpers;
use FastyBird\DevicesModule\Models;
use FastyBird\DevicesModule\Router;
use FastyBird\DevicesModule\Schemas;
Expand Down Expand Up @@ -99,8 +100,8 @@ public function getAttributes($property, JsonApi\Contracts\Schema\ContextInterfa
'data_type' => $property->getDataType() !== null ? $property->getDataType()->getValue() : null,
'unit' => $property->getUnit(),
'format' => is_array($property->getFormat()) ? implode(',', $property->getFormat()) : $property->getFormat(),
'actual_value' => $state !== null ? $state->getActualValue() : null,
'expected_value' => $state !== null ? $state->getExpectedValue() : null,
'actual_value' => $state !== null ? Helpers\PropertyHelper::normalizeValue($property, $state->getActualValue()) : null,
'expected_value' => $state !== null ? Helpers\PropertyHelper::normalizeValue($property, $state->getExpectedValue()) : null,
'pending' => $state !== null && $state->isPending(),
];
}
Expand Down
9 changes: 7 additions & 2 deletions src/Subscribers/EntitiesSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function __construct(
ApplicationExchangePublisher\IPublisher $publisher,
ORM\EntityManagerInterface $entityManager,
?Models\States\IPropertyRepository $propertyStateRepository = null
) {
)
{
$this->numberHashHelper = $numberHashHelper;
$this->dateTimeFactory = $dateTimeFactory;
$this->propertyStateRepository = $propertyStateRepository;
Expand Down Expand Up @@ -192,7 +193,11 @@ private function processEntityAction(Entities\IEntity $entity, string $action):
$this->publisher->publish(
ModulesMetadata\Constants::MODULE_DEVICES_ORIGIN,
$publishRoutingKey,
array_merge($state !== null ? $state->toArray() : [], $this->toArray($entity))
array_merge($state !== null ? [
'actual_value' => Helpers\PropertyHelper::normalizeValue($entity, $state->getActualValue()),
'expected_value' => Helpers\PropertyHelper::normalizeValue($entity, $state->getExpectedValue()),
'pending' => $state->isPending(),
] : [], $this->toArray($entity))
);
} else {
$this->publisher->publish(
Expand Down

0 comments on commit cda8863

Please sign in to comment.