Skip to content

Commit 19e53d9

Browse files
committed
Use optimistics state update (#314)
1 parent 46f918e commit 19e53d9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Queue/Consumers/WriteChannelPropertyState.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
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 Fig\Http\Message\StatusCodeInterface;
3940
use Nette;
41+
use Nette\Utils;
4042
use RuntimeException;
4143
use Throwable;
4244
use TypeError;
@@ -419,7 +421,17 @@ public function consume(Queue\Messages\Message $message): bool
419421
}
420422

421423
$result->then(
422-
function () use ($message, $connector, $device, $channel, $property): void {
424+
function () use ($message, $connector, $device, $channel, $property, $state): void {
425+
await($this->channelPropertiesStatesManager->set(
426+
$property,
427+
Utils\ArrayHash::from([
428+
DevicesStates\Property::ACTUAL_VALUE_FIELD => $state->getExpectedValue(),
429+
DevicesStates\Property::EXPECTED_VALUE_FIELD => null,
430+
DevicesStates\Property::PENDING_FIELD => false,
431+
]),
432+
MetadataTypes\Sources\Connector::SHELLY,
433+
));
434+
423435
$this->logger->debug(
424436
'Channel state was successfully sent to device',
425437
[

0 commit comments

Comments
 (0)