Skip to content

Commit

Permalink
Use optimistic state update (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Sep 30, 2024
1 parent d4f7c74 commit b6331fe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/Queue/Consumers/WriteV1ChannelPropertyState.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
use FastyBird\Module\Devices\Exceptions as DevicesExceptions;
use FastyBird\Module\Devices\Models as DevicesModels;
use FastyBird\Module\Devices\Queries as DevicesQueries;
use FastyBird\Module\Devices\States as DevicesStates;
use Nette;
use Nette\Utils;
use RuntimeException;
use Throwable;
use TypeError;
Expand Down Expand Up @@ -297,7 +299,16 @@ public function consume(Queue\Messages\Message $message): bool
$topic,
strval($expectedValue),
)
->then(function () use ($connector, $device, $channel, $property, $message): void {
->then(function () use ($connector, $device, $channel, $property, $state, $message): void {
await($this->channelPropertiesStatesManager->set(
$property,
Utils\ArrayHash::from([
DevicesStates\Property::ACTUAL_VALUE_FIELD => $state->getExpectedValue(),
DevicesStates\Property::EXPECTED_VALUE_FIELD => null,
]),
MetadataTypes\Sources\Connector::SHELLY,
));

$this->logger->debug(
'Channel state was successfully sent to device',
[
Expand Down
13 changes: 12 additions & 1 deletion src/Queue/Consumers/WriteV1DevicePropertyState.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
use FastyBird\Module\Devices\Exceptions as DevicesExceptions;
use FastyBird\Module\Devices\Models as DevicesModels;
use FastyBird\Module\Devices\Queries as DevicesQueries;
use FastyBird\Module\Devices\States as DevicesStates;
use Nette;
use Nette\Utils;
use RuntimeException;
use Throwable;
use TypeError;
Expand Down Expand Up @@ -250,7 +252,16 @@ public function consume(Queue\Messages\Message $message): bool
$topic,
strval($expectedValue),
)
->then(function () use ($connector, $device, $property, $message): void {
->then(function () use ($connector, $device, $property, $state, $message): void {
await($this->devicePropertiesStatesManager->set(
$property,
Utils\ArrayHash::from([
DevicesStates\Property::ACTUAL_VALUE_FIELD => $state->getExpectedValue(),
DevicesStates\Property::EXPECTED_VALUE_FIELD => null,
]),
MetadataTypes\Sources\Connector::SHELLY,
));

$this->logger->debug(
'Channel state was successfully sent to device',
[
Expand Down

0 comments on commit b6331fe

Please sign in to comment.