Skip to content

Commit

Permalink
Moving types to lib
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Apr 24, 2021
1 parent 9d31ae0 commit 2f3884d
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 570 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"fastybird/modules-metadata": "@dev",
"fastybird/simple-auth": "@dev",
"fastybird/web-server": "@dev",
"ipub/doctrine-consistence": "^0.3",
"ipub/doctrine-timestampable": "^1.4"
},

Expand Down
17 changes: 0 additions & 17 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,6 @@ final class Constants
public const ROUTE_NAME_CONNECTOR = 'connector';
public const ROUTE_NAME_CONNECTOR_RELATIONSHIP = 'connector.relationship';

/**
* Data types
*/
public const DATA_TYPE_BOOLEAN = 'boolean';
public const DATA_TYPE_NUMBER = 'number';
public const DATA_TYPE_SELECT = 'select';
public const DATA_TYPE_TEXT = 'text';

/**
* Control actions
*/
public const CONTROL_CONFIG = 'configure';
public const CONTROL_RESET = 'reset';
public const CONTROL_RECONNECT = 'reconnect';
public const CONTROL_FACTORY_RESET = 'factory-reset';
public const CONTROL_OTA = 'ota';

/**
* Message bus routing keys mapping
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Controllers/ChannelConfigurationV1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

namespace FastyBird\DevicesModule\Controllers;

use FastyBird\DevicesModule;
use FastyBird\DevicesModule\Controllers;
use FastyBird\DevicesModule\Models;
use FastyBird\DevicesModule\Queries;
use FastyBird\DevicesModule\Router;
use FastyBird\DevicesModule\Schemas;
use FastyBird\JsonApi\Exceptions as JsonApiExceptions;
use FastyBird\ModulesMetadata;
use FastyBird\WebServer\Http as WebServerHttp;
use Fig\Http\Message\StatusCodeInterface;
use Psr\Http\Message;
Expand Down Expand Up @@ -84,7 +84,7 @@ public function index(
// & channel
$channel = $this->findChannel($request->getAttribute(Router\Routes::URL_CHANNEL_ID), $device);

if (!$channel->hasControl(DevicesModule\Constants::CONTROL_CONFIG)) {
if (!$channel->hasControl(ModulesMetadata\Constants::CONTROL_CONFIG)) {
throw new JsonApiExceptions\JsonApiErrorException(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//devices-module.base.messages.notFound.heading'),
Expand Down Expand Up @@ -119,7 +119,7 @@ public function read(
// & channel
$channel = $this->findChannel($request->getAttribute(Router\Routes::URL_CHANNEL_ID), $device);

if (!$channel->hasControl(DevicesModule\Constants::CONTROL_CONFIG)) {
if (!$channel->hasControl(ModulesMetadata\Constants::CONTROL_CONFIG)) {
throw new JsonApiExceptions\JsonApiErrorException(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//devices-module.base.messages.notFound.heading'),
Expand Down Expand Up @@ -166,7 +166,7 @@ public function readRelationship(
// & channel
$channel = $this->findChannel($request->getAttribute(Router\Routes::URL_CHANNEL_ID), $device);

if (!$channel->hasControl(DevicesModule\Constants::CONTROL_CONFIG)) {
if (!$channel->hasControl(ModulesMetadata\Constants::CONTROL_CONFIG)) {
throw new JsonApiExceptions\JsonApiErrorException(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//devices-module.base.messages.notFound.heading'),
Expand Down
8 changes: 4 additions & 4 deletions src/Controllers/DeviceConfigurationV1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

namespace FastyBird\DevicesModule\Controllers;

use FastyBird\DevicesModule;
use FastyBird\DevicesModule\Controllers;
use FastyBird\DevicesModule\Models;
use FastyBird\DevicesModule\Queries;
use FastyBird\DevicesModule\Router;
use FastyBird\DevicesModule\Schemas;
use FastyBird\JsonApi\Exceptions as JsonApiExceptions;
use FastyBird\ModulesMetadata;
use FastyBird\WebServer\Http as WebServerHttp;
use Fig\Http\Message\StatusCodeInterface;
use Psr\Http\Message;
Expand Down Expand Up @@ -75,7 +75,7 @@ public function index(
// At first, try to load device
$device = $this->findDevice($request->getAttribute(Router\Routes::URL_DEVICE_ID));

if (!$device->hasControl(DevicesModule\Constants::CONTROL_CONFIG)) {
if (!$device->hasControl(ModulesMetadata\Constants::CONTROL_CONFIG)) {
throw new JsonApiExceptions\JsonApiErrorException(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//devices-module.base.messages.notFound.heading'),
Expand Down Expand Up @@ -107,7 +107,7 @@ public function read(
// At first, try to load device
$device = $this->findDevice($request->getAttribute(Router\Routes::URL_DEVICE_ID));

if (!$device->hasControl(DevicesModule\Constants::CONTROL_CONFIG)) {
if (!$device->hasControl(ModulesMetadata\Constants::CONTROL_CONFIG)) {
throw new JsonApiExceptions\JsonApiErrorException(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//devices-module.base.messages.notFound.heading'),
Expand Down Expand Up @@ -151,7 +151,7 @@ public function readRelationship(
// At first, try to load device
$device = $this->findDevice($request->getAttribute(Router\Routes::URL_DEVICE_ID));

if (!$device->hasControl(DevicesModule\Constants::CONTROL_CONFIG)) {
if (!$device->hasControl(ModulesMetadata\Constants::CONTROL_CONFIG)) {
throw new JsonApiExceptions\JsonApiErrorException(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//devices-module.base.messages.notFound.heading'),
Expand Down
56 changes: 28 additions & 28 deletions src/Entities/Devices/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use FastyBird\Database\Entities as DatabaseEntities;
use FastyBird\DevicesModule\Entities;
use FastyBird\DevicesModule\Exceptions;
use FastyBird\DevicesModule\Types;
use FastyBird\ModulesMetadata\Types as ModulesMetadataTypes;
use FastyBird\SimpleAuth\Entities as SimpleAuthEntities;
use IPub\DoctrineCrud\Mapping\Annotation as IPubDoctrine;
use IPub\DoctrineTimestampable;
Expand Down Expand Up @@ -116,9 +116,9 @@ class Device implements IDevice
private ?string $comment = null;

/**
* @var Types\DeviceConnectionStateType
* @var ModulesMetadataTypes\DeviceConnectionStateType
*
* @Enum(class=Types\DeviceConnectionStateType::class)
* @Enum(class=ModulesMetadataTypes\DeviceConnectionStateType::class)
* @IPubDoctrine\Crud(is="writable")
* @ORM\Column(type="string_enum", name="device_state", nullable=false, options={"default": "unknown"})
*/
Expand All @@ -133,18 +133,18 @@ class Device implements IDevice
private bool $enabled = true;

/**
* @var Types\HardwareManufacturerType
* @var ModulesMetadataTypes\HardwareManufacturerType
*
* @Enum(class=Types\HardwareManufacturerType::class)
* @Enum(class=ModulesMetadataTypes\HardwareManufacturerType::class)
* @IPubDoctrine\Crud(is="writable")
* @ORM\Column(type="string", name="device_hardware_manufacturer", length=150, nullable=false, options={"default": "generic"})
*/
private $hardwareManufacturer;

/**
* @var Types\ModelType
* @var ModulesMetadataTypes\DeviceModelType
*
* @Enum(class=Types\ModelType::class)
* @Enum(class=ModulesMetadataTypes\DeviceModelType::class)
* @IPubDoctrine\Crud(is="writable")
* @ORM\Column(type="string", name="device_hardware_model", length=150, nullable=false, options={"default": "custom"})
*/
Expand All @@ -167,9 +167,9 @@ class Device implements IDevice
private ?string $macAddress = null;

/**
* @var Types\FirmwareManufacturerType
* @var ModulesMetadataTypes\FirmwareManufacturerType
*
* @Enum(class=Types\FirmwareManufacturerType::class)
* @Enum(class=ModulesMetadataTypes\FirmwareManufacturerType::class)
* @IPubDoctrine\Crud(is="writable")
* @ORM\Column(type="string", name="device_firmware_manufacturer", length=150, nullable=false, options={"default": "generic"})
*/
Expand Down Expand Up @@ -240,12 +240,12 @@ public function __construct(
$this->identifier = $identifier;
$this->name = $name;

$this->state = Types\DeviceConnectionStateType::get(Types\DeviceConnectionStateType::STATE_UNKNOWN);
$this->state = ModulesMetadataTypes\DeviceConnectionStateType::get(ModulesMetadataTypes\DeviceConnectionStateType::STATE_UNKNOWN);

$this->hardwareManufacturer = Types\HardwareManufacturerType::get(Types\HardwareManufacturerType::MANUFACTURER_GENERIC);
$this->hardwareModel = Types\ModelType::get(Types\ModelType::MODEL_CUSTOM);
$this->hardwareManufacturer = ModulesMetadataTypes\HardwareManufacturerType::get(ModulesMetadataTypes\HardwareManufacturerType::MANUFACTURER_GENERIC);
$this->hardwareModel = ModulesMetadataTypes\DeviceModelType::get(ModulesMetadataTypes\DeviceModelType::MODEL_CUSTOM);

$this->firmwareManufacturer = Types\FirmwareManufacturerType::get(Types\FirmwareManufacturerType::MANUFACTURER_GENERIC);
$this->firmwareManufacturer = ModulesMetadataTypes\FirmwareManufacturerType::get(ModulesMetadataTypes\FirmwareManufacturerType::MANUFACTURER_GENERIC);

$this->children = new Common\Collections\ArrayCollection();
$this->channels = new Common\Collections\ArrayCollection();
Expand Down Expand Up @@ -685,7 +685,7 @@ public function setComment(?string $comment = null): void
/**
* {@inheritDoc}
*/
public function getState(): Types\DeviceConnectionStateType
public function getState(): ModulesMetadataTypes\DeviceConnectionStateType
{
return $this->state;
}
Expand All @@ -695,11 +695,11 @@ public function getState(): Types\DeviceConnectionStateType
*/
public function setState(string $state): void
{
if (!Types\DeviceConnectionStateType::isValidValue($state)) {
if (!ModulesMetadataTypes\DeviceConnectionStateType::isValidValue($state)) {
throw new Exceptions\InvalidArgumentException(sprintf('Provided device state "%s" is not valid', $state));
}

$this->state = Types\DeviceConnectionStateType::get($state);
$this->state = ModulesMetadataTypes\DeviceConnectionStateType::get($state);
}

/**
Expand Down Expand Up @@ -737,7 +737,7 @@ public function setHardwareVersion(?string $version): void
/**
* {@inheritDoc}
*/
public function getHardwareManufacturer(): Types\HardwareManufacturerType
public function getHardwareManufacturer(): ModulesMetadataTypes\HardwareManufacturerType
{
return $this->hardwareManufacturer;
}
Expand All @@ -747,18 +747,18 @@ public function getHardwareManufacturer(): Types\HardwareManufacturerType
*/
public function setHardwareManufacturer(?string $manufacturer): void
{
if ($manufacturer !== null && Types\HardwareManufacturerType::isValidValue(strtolower($manufacturer))) {
$this->hardwareManufacturer = Types\HardwareManufacturerType::get(strtolower($manufacturer));
if ($manufacturer !== null && ModulesMetadataTypes\HardwareManufacturerType::isValidValue(strtolower($manufacturer))) {
$this->hardwareManufacturer = ModulesMetadataTypes\HardwareManufacturerType::get(strtolower($manufacturer));

} else {
$this->hardwareManufacturer = Types\HardwareManufacturerType::get(Types\HardwareManufacturerType::MANUFACTURER_GENERIC);
$this->hardwareManufacturer = ModulesMetadataTypes\HardwareManufacturerType::get(ModulesMetadataTypes\HardwareManufacturerType::MANUFACTURER_GENERIC);
}
}

/**
* {@inheritDoc}
*/
public function getHardwareModel(): Types\ModelType
public function getHardwareModel(): ModulesMetadataTypes\DeviceModelType
{
return $this->hardwareModel;
}
Expand All @@ -768,11 +768,11 @@ public function getHardwareModel(): Types\ModelType
*/
public function setHardwareModel(?string $model): void
{
if ($model !== null && Types\ModelType::isValidValue(strtolower($model))) {
$this->hardwareModel = Types\ModelType::get(strtolower($model));
if ($model !== null && ModulesMetadataTypes\DeviceModelType::isValidValue(strtolower($model))) {
$this->hardwareModel = ModulesMetadataTypes\DeviceModelType::get(strtolower($model));

} else {
$this->hardwareModel = Types\ModelType::get(Types\ModelType::MODEL_CUSTOM);
$this->hardwareModel = ModulesMetadataTypes\DeviceModelType::get(ModulesMetadataTypes\DeviceModelType::MODEL_CUSTOM);
}
}

Expand Down Expand Up @@ -803,7 +803,7 @@ public function setMacAddress(?string $macAddress): void
/**
* {@inheritDoc}
*/
public function getFirmwareManufacturer(): Types\FirmwareManufacturerType
public function getFirmwareManufacturer(): ModulesMetadataTypes\FirmwareManufacturerType
{
return $this->firmwareManufacturer;
}
Expand All @@ -813,11 +813,11 @@ public function getFirmwareManufacturer(): Types\FirmwareManufacturerType
*/
public function setFirmwareManufacturer(?string $manufacturer): void
{
if ($manufacturer !== null && Types\FirmwareManufacturerType::isValidValue(strtolower($manufacturer))) {
$this->firmwareManufacturer = Types\FirmwareManufacturerType::get(strtolower($manufacturer));
if ($manufacturer !== null && ModulesMetadataTypes\FirmwareManufacturerType::isValidValue(strtolower($manufacturer))) {
$this->firmwareManufacturer = ModulesMetadataTypes\FirmwareManufacturerType::get(strtolower($manufacturer));

} else {
$this->firmwareManufacturer = Types\FirmwareManufacturerType::get(Types\FirmwareManufacturerType::MANUFACTURER_GENERIC);
$this->firmwareManufacturer = ModulesMetadataTypes\FirmwareManufacturerType::get(ModulesMetadataTypes\FirmwareManufacturerType::MANUFACTURER_GENERIC);
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/Entities/Devices/IDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use FastyBird\Database\Entities as DatabaseEntities;
use FastyBird\DevicesModule\Entities;
use FastyBird\DevicesModule\Types;
use FastyBird\ModulesMetadata\Types as ModulesMetadataTypes;
use FastyBird\SimpleAuth\Entities as SimpleAuthEntities;
use IPub\DoctrineTimestampable;

Expand Down Expand Up @@ -116,9 +116,9 @@ public function getComment(): ?string;
public function setState(string $state): void;

/**
* @return Types\DeviceConnectionStateType
* @return ModulesMetadataTypes\DeviceConnectionStateType
*/
public function getState(): Types\DeviceConnectionStateType;
public function getState(): ModulesMetadataTypes\DeviceConnectionStateType;

/**
* @param bool $enabled
Expand All @@ -135,9 +135,9 @@ public function setEnabled(bool $enabled): void;
public function setHardwareManufacturer(?string $manufacturer): void;

/**
* @return Types\HardwareManufacturerType
* @return ModulesMetadataTypes\HardwareManufacturerType
*/
public function getHardwareManufacturer(): Types\HardwareManufacturerType;
public function getHardwareManufacturer(): ModulesMetadataTypes\HardwareManufacturerType;

/**
* @param string|null $model
Expand All @@ -147,9 +147,9 @@ public function getHardwareManufacturer(): Types\HardwareManufacturerType;
public function setHardwareModel(?string $model): void;

/**
* @return Types\ModelType
* @return ModulesMetadataTypes\DeviceModelType
*/
public function getHardwareModel(): Types\ModelType;
public function getHardwareModel(): ModulesMetadataTypes\DeviceModelType;

/**
* @param string|null $version
Expand Down Expand Up @@ -185,9 +185,9 @@ public function getMacAddress(string $separator = ':'): ?string;
public function setFirmwareManufacturer(?string $manufacturer): void;

/**
* @return Types\FirmwareManufacturerType
* @return ModulesMetadataTypes\FirmwareManufacturerType
*/
public function getFirmwareManufacturer(): Types\FirmwareManufacturerType;
public function getFirmwareManufacturer(): ModulesMetadataTypes\FirmwareManufacturerType;

/**
* @param string|null $version
Expand Down
6 changes: 3 additions & 3 deletions src/Entities/IProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace FastyBird\DevicesModule\Entities;

use FastyBird\Database\Entities as DatabaseEntities;
use FastyBird\DevicesModule\Types;
use FastyBird\ModulesMetadata\Types as ModulesMetadataTypes;
use IPub\DoctrineTimestampable;

/**
Expand Down Expand Up @@ -74,9 +74,9 @@ public function isQueryable(): bool;
public function setQueryable(bool $queryable): void;

/**
* @return Types\DataTypeType|null
* @return ModulesMetadataTypes\DataTypeType|null
*/
public function getDataType(): ?Types\DataTypeType;
public function getDataType(): ?ModulesMetadataTypes\DataTypeType;

/**
* @param string|null $dataType
Expand Down
6 changes: 3 additions & 3 deletions src/Entities/IRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace FastyBird\DevicesModule\Entities;

use FastyBird\Database\Entities as DatabaseEntities;
use FastyBird\DevicesModule\Types;
use FastyBird\ModulesMetadata\Types as ModulesMetadataTypes;
use IPub\DoctrineTimestampable;

/**
Expand Down Expand Up @@ -63,9 +63,9 @@ public function getComment(): ?string;
public function setComment(?string $comment): void;

/**
* @return Types\DataTypeType
* @return ModulesMetadataTypes\DataTypeType
*/
public function getDataType(): Types\DataTypeType;
public function getDataType(): ModulesMetadataTypes\DataTypeType;

/**
* @param string $dataType
Expand Down
Loading

0 comments on commit 2f3884d

Please sign in to comment.