Skip to content

Commit

Permalink
[homekit-connector] Create device cmd (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Mar 24, 2023
1 parent 73942df commit b8f5948
Show file tree
Hide file tree
Showing 25 changed files with 250 additions and 105 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"ext-bcmath": "*",
"ext-pcntl": "*",
"cweagans/composer-patches": "^1.7",
"evenement/evenement": "^3.0",
"fastybird/bootstrap-library": "dev-main",
"fastybird/exchange-library": "dev-main",
"fastybird/json-api": "^0.13",
Expand Down
6 changes: 6 additions & 0 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,10 @@ final class Constants

public const DATA_STORAGE_CHANNELS_KEY = 'channels';

public const EVENT_ENTITY_CREATED = 'entity_created';

public const EVENT_ENTITY_UPDATED = 'entity_updated';

public const EVENT_ENTITY_DELETED = 'entity_deleted';

}
1 change: 1 addition & 0 deletions src/Consumers/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public function consume(
}

/**
* @throws Exceptions\InvalidState
* @throws MetadataExceptions\InvalidArgument
* @throws MetadataExceptions\InvalidState
*/
Expand Down
47 changes: 16 additions & 31 deletions src/Entities/Channels/Properties/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ public function getChannel(): Entities\Channels\Channel
public function isSettable(): bool
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->isSettable();
}
Expand All @@ -171,8 +170,7 @@ public function isSettable(): bool
public function setSettable(bool $settable): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Settable setter is allowed only for parent');
}
Expand All @@ -183,8 +181,7 @@ public function setSettable(bool $settable): void
public function isQueryable(): bool
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->isQueryable();
}
Expand All @@ -199,8 +196,7 @@ public function isQueryable(): bool
public function setQueryable(bool $queryable): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Queryable setter is allowed only for parent');
}
Expand All @@ -211,8 +207,7 @@ public function setQueryable(bool $queryable): void
public function getDataType(): MetadataTypes\DataType
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->getDataType();
}
Expand All @@ -226,8 +221,7 @@ public function getDataType(): MetadataTypes\DataType
public function setDataType(MetadataTypes\DataType $dataType): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Data type setter is allowed only for parent');
}
Expand All @@ -238,8 +232,7 @@ public function setDataType(MetadataTypes\DataType $dataType): void
public function getUnit(): string|null
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->getUnit();
}
Expand All @@ -253,8 +246,7 @@ public function getUnit(): string|null
public function setUnit(string|null $unit): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Value unit setter is allowed only for parent');
}
Expand All @@ -281,8 +273,7 @@ public function getFormat(): MetadataValueObjects\StringEnumFormat|MetadataValue
public function setFormat(array|string|null $format): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Value format setter is allowed only for parent');
}
Expand All @@ -293,8 +284,7 @@ public function setFormat(array|string|null $format): void
public function getInvalid(): float|int|string|null
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->getInvalid();
}
Expand All @@ -308,8 +298,7 @@ public function getInvalid(): float|int|string|null
public function setInvalid(string|null $invalid): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Invalid value setter is allowed only for parent');
}
Expand All @@ -320,8 +309,7 @@ public function setInvalid(string|null $invalid): void
public function getNumberOfDecimals(): int|null
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->getNumberOfDecimals();
}
Expand All @@ -335,20 +323,18 @@ public function getNumberOfDecimals(): int|null
public function setNumberOfDecimals(int|null $numberOfDecimals): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Number of decimals setter is allowed only for parent');
}

parent::setNumberOfDecimals($numberOfDecimals);
}

public function getDefault(): bool|float|int|string|DateTimeInterface|MetadataTypes\ButtonPayload|MetadataTypes\SwitchPayload|null
public function getDefault(): bool|float|int|string|DateTimeInterface|MetadataTypes\ButtonPayload|MetadataTypes\SwitchPayload|MetadataTypes\CoverPayload|null
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->getDefault();
}
Expand All @@ -362,8 +348,7 @@ public function getDefault(): bool|float|int|string|DateTimeInterface|MetadataTy
public function setDefault(string|null $default): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Default value setter is allowed only for parent');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Entities/Channels/Properties/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function getType(): MetadataTypes\PropertyType
{
return MetadataTypes\PropertyType::get(MetadataTypes\PropertyType::TYPE_VARIABLE);
}

public function getValue(): bool|float|int|string|DateTimeInterface|MetadataTypes\ButtonPayload|MetadataTypes\SwitchPayload|null
// phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
public function getValue(): bool|float|int|string|DateTimeInterface|MetadataTypes\ButtonPayload|MetadataTypes\SwitchPayload|MetadataTypes\CoverPayload|null
{
if ($this->getParent() !== null) {
return $this->getParent()->getValue();
Expand Down
47 changes: 16 additions & 31 deletions src/Entities/Devices/Properties/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ public function getDevice(): Entities\Devices\Device
public function isSettable(): bool
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->isSettable();
}
Expand All @@ -183,8 +182,7 @@ public function setSettable(bool $settable): void
public function isQueryable(): bool
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->isQueryable();
}
Expand All @@ -199,8 +197,7 @@ public function isQueryable(): bool
public function setQueryable(bool $queryable): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Queryable setter is allowed only for parent');
}
Expand All @@ -211,8 +208,7 @@ public function setQueryable(bool $queryable): void
public function getDataType(): MetadataTypes\DataType
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->getDataType();
}
Expand All @@ -226,8 +222,7 @@ public function getDataType(): MetadataTypes\DataType
public function setDataType(MetadataTypes\DataType $dataType): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Data type setter is allowed only for parent');
}
Expand All @@ -238,8 +233,7 @@ public function setDataType(MetadataTypes\DataType $dataType): void
public function getUnit(): string|null
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->getUnit();
}
Expand All @@ -253,8 +247,7 @@ public function getUnit(): string|null
public function setUnit(string|null $unit): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Value unit setter is allowed only for parent');
}
Expand All @@ -265,8 +258,7 @@ public function setUnit(string|null $unit): void
public function getFormat(): MetadataValueObjects\StringEnumFormat|MetadataValueObjects\NumberRangeFormat|MetadataValueObjects\CombinedEnumFormat|null
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->getFormat();
}
Expand All @@ -282,8 +274,7 @@ public function getFormat(): MetadataValueObjects\StringEnumFormat|MetadataValue
public function setFormat(array|string|null $format): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Value format setter is allowed only for parent');
}
Expand All @@ -294,8 +285,7 @@ public function setFormat(array|string|null $format): void
public function getInvalid(): float|int|string|null
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->getInvalid();
}
Expand All @@ -309,8 +299,7 @@ public function getInvalid(): float|int|string|null
public function setInvalid(string|null $invalid): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Invalid value setter is allowed only for parent');
}
Expand All @@ -321,8 +310,7 @@ public function setInvalid(string|null $invalid): void
public function getNumberOfDecimals(): int|null
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->getNumberOfDecimals();
}
Expand All @@ -336,20 +324,18 @@ public function getNumberOfDecimals(): int|null
public function setNumberOfDecimals(int|null $numberOfDecimals): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Number of decimals setter is allowed only for parent');
}

parent::setNumberOfDecimals($numberOfDecimals);
}

public function getDefault(): bool|float|int|string|DateTimeInterface|MetadataTypes\ButtonPayload|MetadataTypes\SwitchPayload|null
public function getDefault(): bool|float|int|string|DateTimeInterface|MetadataTypes\ButtonPayload|MetadataTypes\SwitchPayload|MetadataTypes\CoverPayload|null
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
return $this->getParent()->getDefault();
}
Expand All @@ -360,8 +346,7 @@ public function getDefault(): bool|float|int|string|DateTimeInterface|MetadataTy
public function setDefault(string|null $default): void
{
if (
$this->getParent() !== null && !$this->getType()
->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
$this->getParent() !== null && !$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_MAPPED)
) {
throw new Exceptions\InvalidState('Default value setter is allowed only for parent');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Entities/Devices/Properties/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function getType(): MetadataTypes\PropertyType
{
return MetadataTypes\PropertyType::get(MetadataTypes\PropertyType::TYPE_VARIABLE);
}

public function getValue(): bool|float|int|string|DateTimeInterface|MetadataTypes\ButtonPayload|MetadataTypes\SwitchPayload|null
// phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
public function getValue(): bool|float|int|string|DateTimeInterface|MetadataTypes\ButtonPayload|MetadataTypes\SwitchPayload|MetadataTypes\CoverPayload|null
{
if ($this->getParent() !== null) {
return $this->getParent()->getValue();
Expand Down
4 changes: 2 additions & 2 deletions src/Entities/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public function setNumberOfDecimals(int|null $numberOfDecimals): void
* @throws MetadataExceptions\InvalidArgument
* @throws MetadataExceptions\InvalidState
*/
public function getValue(): bool|float|int|string|DateTimeInterface|MetadataTypes\ButtonPayload|MetadataTypes\SwitchPayload|null
public function getValue(): bool|float|int|string|DateTimeInterface|MetadataTypes\ButtonPayload|MetadataTypes\SwitchPayload|MetadataTypes\CoverPayload|null
{
if (!$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_VARIABLE)) {
throw new Exceptions\InvalidState(
Expand Down Expand Up @@ -416,7 +416,7 @@ public function setValue(string|int|float|bool|null $value): void
* @throws MetadataExceptions\InvalidArgument
* @throws MetadataExceptions\InvalidState
*/
public function getDefault(): bool|float|int|string|DateTimeInterface|MetadataTypes\ButtonPayload|MetadataTypes\SwitchPayload|null
public function getDefault(): bool|float|int|string|DateTimeInterface|MetadataTypes\ButtonPayload|MetadataTypes\SwitchPayload|MetadataTypes\CoverPayload|null
{
if (!$this->getType()->equalsValue(MetadataTypes\PropertyType::TYPE_VARIABLE)) {
throw new Exceptions\InvalidState(
Expand Down
Loading

0 comments on commit b8f5948

Please sign in to comment.