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 7b32be3 commit 053601a
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/WriteChannelPropertyState.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
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 FastyBird\Module\Devices\Types as DevicesTypes;
use Nette;
use Nette\Utils;
use RuntimeException;
use Throwable;
use TypeError;
Expand Down Expand Up @@ -349,7 +351,16 @@ public function consume(Queue\Messages\Message $message): bool
}

$result->then(
function () use ($connector, $device, $channel, $property, $message): void {
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/WriteDevicePropertyState.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
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 FastyBird\Module\Devices\Types as DevicesTypes;
use Nette;
use Nette\Utils;
use RuntimeException;
use Throwable;
use TypeError;
Expand Down Expand Up @@ -299,7 +301,16 @@ public function consume(Queue\Messages\Message $message): bool
}

$result->then(
function () use ($connector, $device, $property, $message): void {
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 053601a

Please sign in to comment.