Skip to content

Commit

Permalink
Upgrading packages
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Oct 8, 2022
1 parent dfa9f27 commit 14ccda3
Show file tree
Hide file tree
Showing 154 changed files with 1,068 additions and 1,013 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
[![Black](https://img.shields.io/badge/black-enabled-brightgreen.svg?style=flat-square)](https://github.com/psf/black)
[![MyPy](https://img.shields.io/badge/mypy-enabled-brightgreen.svg?style=flat-square)](http://mypy-lang.org)

***

## What is FastyBird IoT devices module?

Devices module is a combined [Nette framework](https://nette.org) extension, [Vuex ORM](https://vuex-orm.org) plugin
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
"ext-pcntl" : "*",
"contributte/flysystem" : "^0.3.0",
"cweagans/composer-patches" : "^1.7",
"fastybird/exchange" : "^0.59",
"fastybird/json-api" : "^0.11",
"fastybird/metadata" : "^0.76",
"fastybird/simple-auth" : "^0.4",
"fastybird/exchange" : "^0.60",
"fastybird/json-api" : "^0.13",
"fastybird/metadata" : "^0.77",
"fastybird/simple-auth" : "^0.5",
"ipub/doctrine-dynamic-discriminator-map" : "^1.4",
"ipub/doctrine-timestampable" : "^1.5",
"ipub/slim-router" : "^0.2",
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<properties>
<property name="rootNamespaces" type="array">
<element key="src" value="FastyBird\DevicesModule"/>
<element key="tests/cases" value="Tests\Cases"/>
<element key="tests/cases/unit" value="Tests\Cases\Unit"/>
<element key="tests/tools" value="Tests\Tools"/>
</property>
</properties>
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fastnumbers>=3.2
fastybird-exchange>=0.59
fastybird-metadata>=0.76
fastybird-exchange>=0.60
fastybird-metadata>=0.77
inflection>=0.5
kink>=0.6
setuptools>=57.4
Expand Down
56 changes: 30 additions & 26 deletions src/Commands/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ class Connector extends Console\Command\Command
private Log\LoggerInterface $logger;

public function __construct(
private Models\DataStorage\ConnectorsRepository $connectorsRepository,
private Models\DataStorage\DevicesRepository $devicesRepository,
private Models\DataStorage\DevicePropertiesRepository $devicesPropertiesRepository,
private Models\DataStorage\ChannelsRepository $channelsRepository,
private Models\DataStorage\ChannelPropertiesRepository $channelsPropertiesRepository,
private Models\States\ConnectorConnectionStateManager $connectorConnectionStateManager,
private Models\States\DeviceConnectionStateManager $deviceConnectionStateManager,
private Models\States\DevicePropertyStateManager $devicePropertyStateManager,
private Models\States\ChannelPropertyStateManager $channelPropertyStateManager,
private Consumers\Connector $connectorConsumer,
private ExchangeConsumer\Consumer $consumer,
private DateTimeFactory\DateTimeFactory $dateTimeFactory,
private EventLoop\LoopInterface $eventLoop,
private PsrEventDispatcher\EventDispatcherInterface|null $dispatcher,
private readonly Models\DataStorage\ConnectorsRepository $connectorsRepository,
private readonly Models\DataStorage\DevicesRepository $devicesRepository,
private readonly Models\DataStorage\DevicePropertiesRepository $devicesPropertiesRepository,
private readonly Models\DataStorage\ChannelsRepository $channelsRepository,
private readonly Models\DataStorage\ChannelPropertiesRepository $channelsPropertiesRepository,
private readonly Models\States\ConnectorConnectionStateManager $connectorConnectionStateManager,
private readonly Models\States\DeviceConnectionStateManager $deviceConnectionStateManager,
private readonly Models\States\DevicePropertyStateManager $devicePropertyStateManager,
private readonly Models\States\ChannelPropertyStateManager $channelPropertyStateManager,
private readonly Consumers\Connector $connectorConsumer,
private readonly ExchangeConsumer\Container $consumer,
private readonly DateTimeFactory\Factory $dateTimeFactory,
private readonly EventLoop\LoopInterface $eventLoop,
private readonly PsrEventDispatcher\EventDispatcherInterface|null $dispatcher,
Log\LoggerInterface|null $logger = null,
string|null $name = null,
)
Expand Down Expand Up @@ -180,6 +180,7 @@ protected function execute(Input\InputInterface $input, Output\OutputInterface $

/**
* @throws Exceptions\Terminate
* @throws Metadata\Exceptions\FileNotFound
*/
private function executeConnector(Style\SymfonyStyle $io, Input\InputInterface $input): void
{
Expand Down Expand Up @@ -298,15 +299,15 @@ private function executeConnector(Style\SymfonyStyle $io, Input\InputInterface $
try {
$this->resetConnectorDevices(
$connector,
MetadataTypes\ConnectionStateType::get(MetadataTypes\ConnectionStateType::STATE_UNKNOWN),
MetadataTypes\ConnectionState::get(MetadataTypes\ConnectionState::STATE_UNKNOWN),
);

// Start connector service
$service->execute();

$this->connectorConnectionStateManager->setState(
$connector,
MetadataTypes\ConnectionStateType::get(MetadataTypes\ConnectionStateType::STATE_RUNNING),
MetadataTypes\ConnectionState::get(MetadataTypes\ConnectionState::STATE_RUNNING),
);
} catch (Throwable $ex) {
throw new Exceptions\Terminate('Connector can\'t be started', $ex->getCode(), $ex);
Expand All @@ -315,7 +316,7 @@ private function executeConnector(Style\SymfonyStyle $io, Input\InputInterface $
$this->dispatcher?->dispatch(new Events\AfterConnectorStart($connector));
});

$this->eventLoop->addSignal(SIGINT, function (int $signal) use ($connector, $service): void {
$this->eventLoop->addSignal(SIGINT, function () use ($connector, $service): void {
$this->logger->info('Stopping connector...', [
'source' => Metadata\Constants::MODULE_DEVICES_SOURCE,
'type' => 'service-cmd',
Expand All @@ -328,7 +329,7 @@ private function executeConnector(Style\SymfonyStyle $io, Input\InputInterface $

$this->resetConnectorDevices(
$connector,
MetadataTypes\ConnectionStateType::get(MetadataTypes\ConnectionStateType::STATE_DISCONNECTED),
MetadataTypes\ConnectionState::get(MetadataTypes\ConnectionState::STATE_DISCONNECTED),
);

$now = $this->dateTimeFactory->getNow();
Expand All @@ -351,12 +352,12 @@ private function executeConnector(Style\SymfonyStyle $io, Input\InputInterface $

$this->connectorConnectionStateManager->setState(
$connector,
MetadataTypes\ConnectionStateType::get(MetadataTypes\ConnectionStateType::STATE_STOPPED),
MetadataTypes\ConnectionState::get(MetadataTypes\ConnectionState::STATE_STOPPED),
);

$this->eventLoop->stop();
} catch (Throwable $ex) {
$this->logger->error('Connector couldn\'t be stopped. An unexpected error occurred', [
$this->logger->error('Connector could not be stopped. An unexpected error occurred', [
'source' => Metadata\Constants::MODULE_DEVICES_SOURCE,
'type' => 'service-cmd',
'exception' => [
Expand All @@ -374,27 +375,30 @@ private function executeConnector(Style\SymfonyStyle $io, Input\InputInterface $
});
}

/**
* @throws Metadata\Exceptions\FileNotFound
*/
private function resetConnectorDevices(
MetadataEntities\Modules\DevicesModule\IConnectorEntity $connector,
MetadataTypes\ConnectionStateType $state,
MetadataEntities\DevicesModule\Connector $connector,
MetadataTypes\ConnectionState $state,
): void
{
foreach ($this->devicesRepository->findAllByConnector($connector->getId()) as $device) {
$this->deviceConnectionStateManager->setState($device, $state);

/** @var Array<MetadataEntities\Modules\DevicesModule\IDeviceDynamicPropertyEntity> $properties */
/** @var Array<MetadataEntities\DevicesModule\DeviceDynamicProperty> $properties */
$properties = $this->devicesPropertiesRepository->findAllByDevice(
$device->getId(),
MetadataEntities\Modules\DevicesModule\DeviceDynamicPropertyEntity::class,
MetadataEntities\DevicesModule\DeviceDynamicProperty::class,
);

$this->devicePropertyStateManager->setValidState($properties, false);

foreach ($this->channelsRepository->findAllByDevice($device->getId()) as $channel) {
/** @var Array<MetadataEntities\Modules\DevicesModule\ChannelDynamicPropertyEntity> $properties */
/** @var Array<MetadataEntities\DevicesModule\ChannelDynamicProperty> $properties */
$properties = $this->channelsPropertiesRepository->findAllByChannel(
$channel->getId(),
MetadataEntities\Modules\DevicesModule\ChannelDynamicPropertyEntity::class,
MetadataEntities\DevicesModule\ChannelDynamicProperty::class,
);

$this->channelPropertyStateManager->setValidState($properties, false);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Initialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Initialize extends Console\Command\Command
private Log\LoggerInterface $logger;

public function __construct(
private DataStorage\Writer $writer,
private readonly DataStorage\Writer $writer,
Log\LoggerInterface|null $logger = null,
string|null $name = null,
)
Expand Down
2 changes: 1 addition & 1 deletion src/Connectors/ConnectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
interface ConnectorFactory
{

public function create(MetadataEntities\Modules\DevicesModule\IConnectorEntity $connector): Connector;
public function create(MetadataEntities\DevicesModule\Connector $connector): Connector;

}
12 changes: 5 additions & 7 deletions src/Consumers/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,23 @@
*
* @author Adam Kadlec <adam.kadlec@fastybird.com>
*/
final class Connector implements ExchangeConsumer\IConsumer
final class Connector implements ExchangeConsumer\Consumer
{

use Nette\SmartObject;

public function __construct(private DataStorage\Reader $reader)
public function __construct(private readonly DataStorage\Reader $reader)
{
}

/**
* {@inheritDoc}
*
* @throws Utils\JsonException
* @throws Flysystem\FilesystemException
*/
public function consume(
MetadataTypes\ModuleSourceType|MetadataTypes\PluginSourceType|MetadataTypes\ConnectorSourceType $source,
MetadataTypes\RoutingKeyType $routingKey,
MetadataEntities\IEntity|null $entity,
MetadataTypes\ModuleSource|MetadataTypes\PluginSource|MetadataTypes\ConnectorSource $source,
MetadataTypes\RoutingKey $routingKey,
MetadataEntities\Entity|null $entity,
): void
{
if (
Expand Down
22 changes: 11 additions & 11 deletions src/Controllers/BaseV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ abstract class BaseV1

protected Router\Validator $routesValidator;

protected JsonApiHydrators\HydratorsContainer $hydratorsContainer;
protected JsonApiHydrators\Container $hydratorsContainer;

protected Log\LoggerInterface $logger;

Expand Down Expand Up @@ -91,13 +91,13 @@ public function injectRoutesValidator(Router\Validator $validator): void
$this->routesValidator = $validator;
}

public function injectHydratorsContainer(JsonApiHydrators\HydratorsContainer $hydratorsContainer): void
public function injectHydratorsContainer(JsonApiHydrators\Container $hydratorsContainer): void
{
$this->hydratorsContainer = $hydratorsContainer;
}

/**
* @throws JsonApiExceptions\IJsonApiException
* @throws JsonApiExceptions\JsonApi
*/
public function readRelationship(
Message\ServerRequestInterface $request,
Expand All @@ -108,7 +108,7 @@ public function readRelationship(
$relationEntity = Utils\Strings::lower(strval($request->getAttribute(Router\Routes::RELATION_ENTITY)));

if ($relationEntity !== '') {
throw new JsonApiExceptions\JsonApiErrorException(
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//devices-module.base.messages.relationNotFound.heading'),
$this->translator->translate(
Expand All @@ -118,23 +118,23 @@ public function readRelationship(
);
}

throw new JsonApiExceptions\JsonApiErrorException(
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//devices-module.base.messages.unknownRelation.heading'),
$this->translator->translate('//devices-module.base.messages.unknownRelation.message'),
);
}

/**
* @throws JsonApiExceptions\IJsonApiException
* @throws JsonApiExceptions\JsonApi
*/
protected function createDocument(Message\ServerRequestInterface $request): JsonAPIDocument\IDocument
{
try {
$content = Utils\Json::decode($request->getBody()->getContents());

if (!$content instanceof stdClass) {
throw new JsonApiExceptions\JsonApiErrorException(
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_BAD_REQUEST,
$this->translator->translate('//devices-module.base.messages.notValidJsonApi.heading'),
$this->translator->translate('//devices-module.base.messages.notValidJsonApi.message'),
Expand All @@ -144,13 +144,13 @@ protected function createDocument(Message\ServerRequestInterface $request): Json
$document = new JsonAPIDocument\Document($content);

} catch (Utils\JsonException) {
throw new JsonApiExceptions\JsonApiErrorException(
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_BAD_REQUEST,
$this->translator->translate('//devices-module.base.messages.notValidJson.heading'),
$this->translator->translate('//devices-module.base.messages.notValidJson.message'),
);
} catch (JsonAPIDocument\Exceptions\RuntimeException) {
throw new JsonApiExceptions\JsonApiErrorException(
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_BAD_REQUEST,
$this->translator->translate('//devices-module.base.messages.notValidJsonApi.heading'),
$this->translator->translate('//devices-module.base.messages.notValidJsonApi.message'),
Expand All @@ -161,7 +161,7 @@ protected function createDocument(Message\ServerRequestInterface $request): Json
}

/**
* @throws JsonApiExceptions\JsonApiErrorException
* @throws JsonApiExceptions\JsonApiError
*/
protected function validateIdentifier(
Message\ServerRequestInterface $request,
Expand All @@ -176,7 +176,7 @@ protected function validateIdentifier(
&& $request->getAttribute(Router\Routes::URL_ITEM_ID) !== null
&& $request->getAttribute(Router\Routes::URL_ITEM_ID) !== $document->getResource()->getId()
) {
throw new JsonApiExceptions\JsonApiErrorException(
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_BAD_REQUEST,
$this->translator->translate('//devices-module.base.messages.invalidIdentifier.heading'),
$this->translator->translate('//devices-module.base.messages.invalidIdentifier.message'),
Expand Down
16 changes: 8 additions & 8 deletions src/Controllers/ChannelControlsV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ final class ChannelControlsV1 extends BaseV1
use Controllers\Finders\TChannel;

public function __construct(
protected Models\Devices\DevicesRepository $devicesRepository,
protected Models\Channels\ChannelsRepository $channelsRepository,
protected Models\Channels\Controls\ControlsRepository $channelControlsRepository,
protected readonly Models\Devices\DevicesRepository $devicesRepository,
protected readonly Models\Channels\ChannelsRepository $channelsRepository,
protected readonly Models\Channels\Controls\ControlsRepository $channelControlsRepository,
)
{
}

/**
* @throws Exception
* @throws JsonApiExceptions\IJsonApiException
* @throws JsonApiExceptions\JsonApi
*/
public function index(
Message\ServerRequestInterface $request,
Expand All @@ -79,7 +79,7 @@ public function index(

/**
* @throws Exception
* @throws JsonApiExceptions\IJsonApiException
* @throws JsonApiExceptions\JsonApi
*/
public function read(
Message\ServerRequestInterface $request,
Expand All @@ -105,7 +105,7 @@ public function read(
}
}

throw new JsonApiExceptions\JsonApiErrorException(
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//devices-module.base.messages.notFound.heading'),
$this->translator->translate('//devices-module.base.messages.notFound.message'),
Expand All @@ -114,7 +114,7 @@ public function read(

/**
* @throws Exception
* @throws JsonApiExceptions\IJsonApiException
* @throws JsonApiExceptions\JsonApi
*/
public function readRelationship(
Message\ServerRequestInterface $request,
Expand Down Expand Up @@ -143,7 +143,7 @@ public function readRelationship(
return $this->buildResponse($request, $response, $device);
}
} else {
throw new JsonApiExceptions\JsonApiErrorException(
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//devices-module.base.messages.notFound.heading'),
$this->translator->translate('//devices-module.base.messages.notFound.message'),
Expand Down
Loading

0 comments on commit 14ccda3

Please sign in to comment.