Skip to content

Commit

Permalink
Refactoring Shelly connector - support for Gen2 devices (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jan 15, 2023
1 parent 17deb44 commit bef5d47
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/Commands/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(
private readonly Utilities\ChannelPropertiesStates $channelPropertiesStateManager,
private readonly DateTimeFactory\Factory $dateTimeFactory,
private readonly EventLoop\LoopInterface $eventLoop,
private readonly PsrEventDispatcher\EventDispatcherInterface|null $dispatcher,
private readonly PsrEventDispatcher\EventDispatcherInterface|null $dispatcher = null,
Log\LoggerInterface|null $logger = null,
string|null $name = null,
)
Expand Down Expand Up @@ -200,7 +200,6 @@ private function executeConnector(Style\SymfonyStyle $io, Input\InputInterface $

$findConnectorQuery = new Queries\FindConnectors();

// @phpstan-ignore-next-line
if (Uuid\Uuid::isValid($connectorId)) {
$findConnectorQuery->byId(Uuid\Uuid::fromString($connectorId));
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/BaseV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function injectManagerRegistry(Persistence\ManagerRegistry $managerRegist
$this->managerRegistry = $managerRegistry;
}

public function injectLogger(Log\LoggerInterface|null $logger): void
public function injectLogger(Log\LoggerInterface|null $logger = null): void
{
$this->logger = $logger ?? new Log\NullLogger();
}
Expand Down
5 changes: 3 additions & 2 deletions src/DI/DevicesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ class DevicesExtension extends DI\CompilerExtension
public const CONNECTOR_TYPE_TAG = 'connector_type';

public static function register(
Nette\Configurator|BootstrapBoot\Configurator $config,
BootstrapBoot\Configurator $config,
string $extensionName = self::NAME,
): void
{
// @phpstan-ignore-next-line
$config->onCompile[] = static function (
Nette\Configurator|BootstrapBoot\Configurator $config,
BootstrapBoot\Configurator $config,
DI\Compiler $compiler,
) use ($extensionName): void {
$compiler->addExtension($extensionName, new DevicesExtension());
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Connectors/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ abstract class Connector implements Entities\Entity,
* @IPubDoctrine\Crud(is="writable")
* @ORM\OneToMany(targetEntity="FastyBird\Module\Devices\Entities\Connectors\Properties\Property", mappedBy="connector", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private Common\Collections\Collection $properties;
protected Common\Collections\Collection $properties;

/**
* @var Common\Collections\Collection<int, Entities\Connectors\Controls\Control>
Expand Down
4 changes: 2 additions & 2 deletions src/Models/States/ChannelPropertiesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ final class ChannelPropertiesManager

public function __construct(
protected readonly ExchangeEntities\EntityFactory $entityFactory,
protected readonly IChannelPropertiesManager|null $manager,
private readonly PsrEventDispatcher\EventDispatcherInterface|null $dispatcher,
protected readonly IChannelPropertiesManager|null $manager = null,
private readonly PsrEventDispatcher\EventDispatcherInterface|null $dispatcher = null,
)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/Models/States/ChannelPropertiesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class ChannelPropertiesRepository

use Nette\SmartObject;

public function __construct(private readonly IChannelPropertiesRepository|null $repository)
public function __construct(private readonly IChannelPropertiesRepository|null $repository = null)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Models/States/ConnectorPropertiesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ final class ConnectorPropertiesManager
use Nette\SmartObject;

public function __construct(
protected readonly IConnectorPropertiesManager|null $manager,
private readonly PsrEventDispatcher\EventDispatcherInterface|null $dispatcher,
protected readonly IConnectorPropertiesManager|null $manager = null,
private readonly PsrEventDispatcher\EventDispatcherInterface|null $dispatcher = null,
)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/Models/States/ConnectorPropertiesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class ConnectorPropertiesRepository

use Nette\SmartObject;

public function __construct(protected readonly IConnectorPropertiesRepository|null $repository)
public function __construct(protected readonly IConnectorPropertiesRepository|null $repository = null)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Models/States/DevicePropertiesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ final class DevicePropertiesManager
use Nette\SmartObject;

public function __construct(
protected readonly IDevicePropertiesManager|null $manager,
private readonly PsrEventDispatcher\EventDispatcherInterface|null $dispatcher,
protected readonly IDevicePropertiesManager|null $manager = null,
private readonly PsrEventDispatcher\EventDispatcherInterface|null $dispatcher = null,
)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/Models/States/DevicePropertiesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class DevicePropertiesRepository

use Nette\SmartObject;

public function __construct(protected readonly IDevicePropertiesRepository|null $repository)
public function __construct(protected readonly IDevicePropertiesRepository|null $repository = null)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/ChannelPropertiesStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(
private readonly Models\Channels\Properties\PropertiesRepository $channelPropertiesRepository,
private readonly Models\States\ChannelPropertiesRepository $channelPropertyStateRepository,
private readonly Models\States\ChannelPropertiesManager $channelPropertiesStatesManager,
Log\LoggerInterface|null $logger,
Log\LoggerInterface|null $logger = null,
)
{
$this->logger = $logger ?? new Log\NullLogger();
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/ConnectorPropertiesStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class ConnectorPropertiesStates
public function __construct(
private readonly Models\States\ConnectorPropertiesRepository $connectorPropertyStateRepository,
private readonly Models\States\ConnectorPropertiesManager $connectorPropertiesStatesManager,
Log\LoggerInterface|null $logger,
Log\LoggerInterface|null $logger = null,
)
{
$this->logger = $logger ?? new Log\NullLogger();
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/DevicePropertiesStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(
private readonly Models\Devices\Properties\PropertiesRepository $devicePropertiesRepository,
private readonly Models\States\DevicePropertiesRepository $devicePropertyStateRepository,
private readonly Models\States\DevicePropertiesManager $devicePropertiesStatesManager,
Log\LoggerInterface|null $logger,
Log\LoggerInterface|null $logger = null,
)
{
$this->logger = $logger ?? new Log\NullLogger();
Expand Down
9 changes: 6 additions & 3 deletions tests/cases/unit/DbTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use FastyBird\Library\Bootstrap\Exceptions as BootstrapExceptions;
use FastyBird\Module\Devices\DI;
use FastyBird\Module\Devices\Exceptions;
use IPub\DoctrineCrud;
use Nette;
use Nettrine\ORM as NettrineORM;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -140,15 +141,17 @@ private function createContainer(): Nette\DI\Container
$config->setForceReloadContainer();
$config->setTempDirectory(FB_TEMP_DIR);

$config->addParameters(['container' => ['class' => 'SystemContainer_' . md5((string) time())]]);
$config->addParameters(['appDir' => $rootDir, 'wwwDir' => $rootDir, 'vendorDir' => $vendorDir]);
$config->addStaticParameters(['container' => ['class' => 'SystemContainer_' . md5((string) time())]]);
$config->addStaticParameters(['appDir' => $rootDir, 'wwwDir' => $rootDir, 'vendorDir' => $vendorDir]);

$config->addConfig(__DIR__ . '/../../common.neon');

foreach ($this->neonFiles as $neonFile) {
$config->addConfig($neonFile);
}

$config->setTimeZone('Europe/Prague');

DI\DevicesExtension::register($config);

$this->container = $config->createContainer();
Expand All @@ -171,7 +174,7 @@ private function setupDatabase(): void
if (!$this->isDatabaseSetUp) {
$db = $this->getDb();

/** @var list<ORM\Mapping\ClassMetadata> $metadatas */
/** @var list<ORM\Mapping\ClassMetadata<DoctrineCrud\Entities\IEntity>> $metadatas */
$metadatas = $this->getEntityManager()->getMetadataFactory()->getAllMetadata();
$schemaTool = new ORM\Tools\SchemaTool($this->getEntityManager());

Expand Down

0 comments on commit bef5d47

Please sign in to comment.