Skip to content

Commit 4bbeb49

Browse files
committed
Use optimistic state update (#315)
1 parent 2727abf commit 4bbeb49

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Queue/Consumers/WriteChannelPropertyState.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
use FastyBird\Module\Devices\Exceptions as DevicesExceptions;
3535
use FastyBird\Module\Devices\Models as DevicesModels;
3636
use FastyBird\Module\Devices\Queries as DevicesQueries;
37+
use FastyBird\Module\Devices\States as DevicesStates;
3738
use FastyBird\Module\Devices\Types as DevicesTypes;
3839
use Nette;
40+
use Nette\Utils;
3941
use RuntimeException;
4042
use Throwable;
4143
use TypeError;
@@ -501,7 +503,16 @@ public function consume(Queue\Messages\Message $message): bool
501503
}
502504

503505
$result->then(
504-
function () use ($connector, $device, $channel, $property, $message): void {
506+
function () use ($connector, $device, $channel, $property, $state, $message): void {
507+
await($this->channelPropertiesStatesManager->set(
508+
$property,
509+
Utils\ArrayHash::from([
510+
DevicesStates\Property::ACTUAL_VALUE_FIELD => $state->getExpectedValue(),
511+
DevicesStates\Property::EXPECTED_VALUE_FIELD => null,
512+
]),
513+
MetadataTypes\Sources\Connector::SHELLY,
514+
));
515+
505516
$this->logger->debug(
506517
'Channel state was successfully sent to device',
507518
[

0 commit comments

Comments
 (0)