Skip to content

Commit

Permalink
[general] Fixing exchange consumer registration (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Mar 25, 2023
1 parent 2b783d9 commit 63c721e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 37 deletions.
10 changes: 2 additions & 8 deletions src/Commands/Discovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ protected function configure(): void
'Run devices module connector',
true,
),
new Input\InputOption(
'no-confirm',
null,
Input\InputOption::VALUE_NONE,
'Do not ask for any confirmation',
),
]),
);
}
Expand All @@ -129,7 +123,7 @@ protected function execute(Input\InputInterface $input, Output\OutputInterface $

$io->note('This action will run connector devices discovery.');

if ($input->getOption('no-confirm') === false) {
if ($input->getOption('no-interaction') === false) {
$question = new Console\Question\ConfirmationQuestion(
'Would you like to continue?',
false,
Expand Down Expand Up @@ -211,7 +205,7 @@ protected function execute(Input\InputInterface $input, Output\OutputInterface $
return Console\Command\Command::FAILURE;
}

if ($input->getOption('no-confirm') === false) {
if ($input->getOption('no-interaction') === false) {
$question = new Console\Question\ConfirmationQuestion(
sprintf(
'Would you like to discover devices with "%s" connector',
Expand Down
12 changes: 3 additions & 9 deletions src/Commands/Execute.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ protected function configure(): void
'Run devices module connector',
true,
),
new Input\InputOption(
'no-confirm',
null,
Input\InputOption::VALUE_NONE,
'Do not ask for any confirmation',
),
]),
);
}
Expand All @@ -111,7 +105,7 @@ protected function execute(Input\InputInterface $input, Output\OutputInterface $

$io->note('This action will run connector service.');

if ($input->getOption('no-confirm') === false) {
if ($input->getOption('no-interaction') === false) {
$question = new Console\Question\ConfirmationQuestion(
'Would you like to continue?',
false,
Expand Down Expand Up @@ -191,7 +185,7 @@ protected function execute(Input\InputInterface $input, Output\OutputInterface $
return Console\Command\Command::FAILURE;
}

if ($input->getOption('no-confirm') === false) {
if ($input->getOption('no-interaction') === false) {
$question = new Console\Question\ConfirmationQuestion(
sprintf(
'Would you like to execute "%s" connector',
Expand Down Expand Up @@ -264,7 +258,7 @@ protected function execute(Input\InputInterface $input, Output\OutputInterface $

$result = $serviceCmd->run(new Input\ArrayInput([
'--connector' => $connector->getPlainId(),
'--no-confirm' => true,
'--no-interaction' => true,
'--quiet' => true,
]), $output);

Expand Down
14 changes: 2 additions & 12 deletions src/Commands/Initialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,7 @@ protected function configure(): void
{
$this
->setName(self::NAME)
->setDescription('Tuya connector initialization')
->setDefinition(
new Input\InputDefinition([
new Input\InputOption(
'no-confirm',
null,
Input\InputOption::VALUE_NONE,
'Do not ask for any confirmation',
),
]),
);
->setDescription('Tuya connector initialization');
}

/**
Expand All @@ -131,7 +121,7 @@ protected function execute(Input\InputInterface $input, Output\OutputInterface $

$io->note('This action will create|update|delete connector configuration.');

if ($input->getOption('no-confirm') === false) {
if ($input->getOption('no-interaction') === false) {
$question = new Console\Question\ConfirmationQuestion(
'Would you like to continue?',
false,
Expand Down
29 changes: 21 additions & 8 deletions src/DI/TuyaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use FastyBird\Connector\Tuya\Subscribers;
use FastyBird\Connector\Tuya\Writers;
use FastyBird\Library\Bootstrap\Boot as BootstrapBoot;
use FastyBird\Library\Exchange\DI as ExchangeDI;
use FastyBird\Module\Devices\DI as DevicesDI;
use Nette;
use Nette\DI;
Expand Down Expand Up @@ -107,15 +108,21 @@ public function loadConfiguration(): void
'consumers' => $builder->findByType(Consumers\Consumer::class),
]);

$writer = null;

if ($configuration->writer === Writers\Event::NAME) {
$builder->addDefinition($this->prefix('writers.event'), new DI\Definitions\ServiceDefinition())
->setType(Writers\Event::class);
$writer = $builder->addDefinition($this->prefix('writers.event'), new DI\Definitions\ServiceDefinition())
->setType(Writers\Event::class)
->setAutowired(false);
} elseif ($configuration->writer === Writers\Exchange::NAME) {
$builder->addDefinition($this->prefix('writers.exchange'), new DI\Definitions\ServiceDefinition())
->setType(Writers\Exchange::class);
$writer = $builder->addDefinition($this->prefix('writers.exchange'), new DI\Definitions\ServiceDefinition())
->setType(Writers\Exchange::class)
->setAutowired(false)
->addTag(ExchangeDI\ExchangeExtension::CONSUMER_STATUS, false);
} elseif ($configuration->writer === Writers\Periodic::NAME) {
$builder->addDefinition($this->prefix('writers.periodic'), new DI\Definitions\ServiceDefinition())
->setType(Writers\Periodic::class);
$writer = $builder->addDefinition($this->prefix('writers.periodic'), new DI\Definitions\ServiceDefinition())
->setType(Writers\Periodic::class)
->setAutowired(false);
}

$builder->addDefinition($this->prefix('api.entityFactory'), new DI\Definitions\ServiceDefinition())
Expand All @@ -139,12 +146,18 @@ public function loadConfiguration(): void
$builder->addFactoryDefinition($this->prefix('clients.local'))
->setImplement(Clients\LocalFactory::class)
->getResultDefinition()
->setType(Clients\Local::class);
->setType(Clients\Local::class)
->setArguments([
'writer' => $writer,
]);

$builder->addFactoryDefinition($this->prefix('clients.cloud'))
->setImplement(Clients\CloudFactory::class)
->getResultDefinition()
->setType(Clients\Cloud::class);
->setType(Clients\Cloud::class)
->setArguments([
'writer' => $writer,
]);

$builder->addFactoryDefinition($this->prefix('clients.discover'))
->setImplement(Clients\DiscoveryFactory::class)
Expand Down
6 changes: 6 additions & 0 deletions src/Writers/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public function processClient(
{
$property = $event->getProperty();

$state = $event->getState();

if ($state->getExpectedValue() === null || $state->getPending() !== true) {
return;
}

if (!$property instanceof DevicesEntities\Channels\Properties\Dynamic) {
return;
}
Expand Down
7 changes: 7 additions & 0 deletions src/Writers/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace FastyBird\Connector\Tuya\Writers;

use DateTimeInterface;
use Exception;
use FastyBird\Connector\Tuya\Clients;
use FastyBird\Connector\Tuya\Entities;
use FastyBird\Connector\Tuya\Helpers;
Expand Down Expand Up @@ -90,6 +91,7 @@ public function disconnect(

/**
* @throws DevicesExceptions\InvalidState
* @throws Exception
*/
public function consume(
MetadataTypes\ModuleSource|MetadataTypes\PluginSource|MetadataTypes\ConnectorSource|MetadataTypes\AutomatorSource $source,
Expand All @@ -104,6 +106,7 @@ public function consume(

/**
* @throws DevicesExceptions\InvalidState
* @throws Exception
*/
public function processClient(
Uuid\UuidInterface $connectorId,
Expand All @@ -113,6 +116,10 @@ public function processClient(
): void
{
if ($entity instanceof MetadataEntities\DevicesModule\ChannelDynamicProperty) {
if ($entity->getExpectedValue() === null || $entity->getPending() !== true) {
return;
}

$findPropertyQuery = new DevicesQueries\FindChannelProperties();
$findPropertyQuery->byId($entity->getId());

Expand Down

0 comments on commit 63c721e

Please sign in to comment.