Skip to content

Commit

Permalink
[homekit-connector] Refactoring commands (#216)
Browse files Browse the repository at this point in the history
* Use types

* Clearing loggers

* Created install cmd

* Updating translations

* qa fixes

* Added missing translations

* Fixing translations

* Refactoring displays

* Updating docs

* Refactoring lists
  • Loading branch information
akadlec committed Dec 16, 2023
1 parent 1f69f04 commit 892be38
Show file tree
Hide file tree
Showing 47 changed files with 1,679 additions and 1,825 deletions.
39 changes: 16 additions & 23 deletions src/FastyBird/Connector/FbMqtt/src/Commands/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ private function createConnector(Style\SymfonyStyle $io): void
true,
);

$createRegisters = (bool) $io->askQuestion($question);
$createDevices = (bool) $io->askQuestion($question);

if ($createRegisters) {
if ($createDevices) {
$this->createDevice($io, $connector);
}
}
Expand Down Expand Up @@ -659,13 +659,9 @@ private function listConnectors(Style\SymfonyStyle $io): void
$connectors = $this->connectorsRepository->findAllBy($findConnectorsQuery, Entities\FbMqttConnector::class);
usort(
$connectors,
static function (Entities\FbMqttConnector $a, Entities\FbMqttConnector $b): int {
if ($a->getIdentifier() === $b->getIdentifier()) {
return $a->getName() <=> $b->getName();
}

return $a->getIdentifier() <=> $b->getIdentifier();
},
static fn (Entities\FbMqttConnector $a, Entities\FbMqttConnector $b): int => (
($a->getName() ?? $a->getIdentifier()) <=> ($b->getName() ?? $b->getIdentifier())
),
);

$table = new Console\Helper\Table($io);
Expand Down Expand Up @@ -947,13 +943,9 @@ private function listDevices(Style\SymfonyStyle $io, Entities\FbMqttConnector $c
$devices = $this->devicesRepository->findAllBy($findDevicesQuery, Entities\FbMqttDevice::class);
usort(
$devices,
static function (Entities\FbMqttDevice $a, Entities\FbMqttDevice $b): int {
if ($a->getIdentifier() === $b->getIdentifier()) {
return $a->getName() <=> $b->getName();
}

return $a->getIdentifier() <=> $b->getIdentifier();
},
static fn (Entities\FbMqttDevice $a, Entities\FbMqttDevice $b): int => (
($a->getName() ?? $a->getIdentifier()) <=> ($b->getName() ?? $b->getIdentifier())
),
);

$table = new Console\Helper\Table($io);
Expand Down Expand Up @@ -1341,13 +1333,13 @@ private function askWhichConnector(Style\SymfonyStyle $io): Entities\FbMqttConne
);
usort(
$systemConnectors,
// phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
static fn (Entities\FbMqttConnector $a, Entities\FbMqttConnector $b): int => $a->getIdentifier() <=> $b->getIdentifier()
static fn (Entities\FbMqttConnector $a, Entities\FbMqttConnector $b): int => (
($a->getName() ?? $a->getIdentifier()) <=> ($b->getName() ?? $b->getIdentifier())
),
);

foreach ($systemConnectors as $connector) {
$connectors[$connector->getIdentifier()] = $connector->getIdentifier()
. ($connector->getName() !== null ? ' [' . $connector->getName() . ']' : '');
$connectors[$connector->getIdentifier()] = $connector->getName() ?? $connector->getIdentifier();
}

if (count($connectors) === 0) {
Expand Down Expand Up @@ -1426,12 +1418,13 @@ private function askWhichDevice(
);
usort(
$connectorDevices,
static fn (Entities\FbMqttDevice $a, Entities\FbMqttDevice $b): int => $a->getIdentifier() <=> $b->getIdentifier()
static fn (Entities\FbMqttDevice $a, Entities\FbMqttDevice $b): int => (
($a->getName() ?? $a->getIdentifier()) <=> ($b->getName() ?? $b->getIdentifier())
),
);

foreach ($connectorDevices as $device) {
$devices[$device->getIdentifier()] = $device->getIdentifier()
. ($device->getName() !== null ? ' [' . $device->getName() . ']' : '');
$devices[$device->getIdentifier()] = $device->getName() ?? $device->getIdentifier();
}

if (count($devices) === 0) {
Expand Down
91 changes: 30 additions & 61 deletions src/FastyBird/Connector/HomeKit/docs/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ A device is an entity that represents a virtual [Apple HomeKit](https://en.wikip
A service is an entity that refers to a specific functionality or feature that a device provides. For example,
a thermostat device might provide a "temperature control" service and a "humidity control" service.

## Device Service Characteristic
## Service Characteristic

A characteristic is an entity that refers to the individual attribute of a service that can be queried or manipulated.
Characteristic represent specific data point that describe the state of a device or allow control over it.
Expand All @@ -39,37 +39,35 @@ with [Apple HomeKit](https://en.wikipedia.org/wiki/HomeKit), you will need to co
The connector can be configured using the [FastyBird](https://www.fastybird.com) [IoT](https://en.wikipedia.org/wiki/Internet_of_things)
user interface or through the console.

## Configuring the Connector through the Console
## Configuring the Connectors, Devices, Services and Characteristic through the Console

To configure the connector through the console, run the following command:

```shell
php bin/fb-console fb:homekit-connector:initialize
php bin/fb-console fb:homekit-connector:install
```

> **NOTE:**
The path to the console command may vary depending on your FastyBird application distribution. For more information, refer to the FastyBird documentation.

```shell
HomeKit connector - initialization
==================================
HomeKit connector - installer
=============================

! [NOTE] This action will create|update|delete connector configuration

Would you like to continue? (yes/no) [no]:
> y
```

You will then be prompted to choose an action:

```shell
What would you like to do?:
[0] Create new connector configuration
[1] Edit existing connector configuration
[2] Delete existing connector configuration
What would you like to do? [Nothing]:
[0] Create connector
[1] Edit connector
[2] Delete connector
[3] Manage connector
[4] List connectors
[5] Nothing
> 0
```

### Create connector

If you choose to create a new connector, you will be asked to provide basic connector configuration:

```shell
Expand All @@ -96,56 +94,16 @@ After providing the necessary information, your new [Apple HomeKit](https://en.w
[OK] Connector "My HomeKit server" was successfully created.
```

## Configuring the Connector with the FastyBird User Interface

You can also configure the [Apple HomeKit](https://en.wikipedia.org/wiki/HomeKit) connector using the [FastyBird](https://www.fastybird.com) [IoT](https://en.wikipedia.org/wiki/Internet_of_things) user interface. For more information on how to do this,
please refer to the [FastyBird](https://www.fastybird.com) [IoT](https://en.wikipedia.org/wiki/Internet_of_things) documentation.

# Devices Configuration
### Create device

With your new connector set up, you must now configure the devices with which the connector will communicate.
This can be accomplished either through a console command or through the user interface of the [FastyBird](https://www.fastybird.com) [IoT](https://en.wikipedia.org/wiki/Internet_of_things).

## Manual Console Command

To manually trigger device configuration, use the following command:

```shell
php bin/fb-console fb:homekit-connector:devices
```

> **NOTE:**
The path to the console command may vary depending on your FastyBird application distribution. For more information, refer to the FastyBird documentation.

The console will prompt for confirmation before proceeding with the devices configuration process.
After new connector is created you will be asked if you want to create new device:

```shell
HomeKit connector - devices management
======================================

! [NOTE] This action will create|update|delete connector device

Would you like to continue? (yes/no) [no]:
> y
```

You will then be prompted to select connector to manage devices.

```shell
Please select connector under which you want to manage devices:
[0] my-homekit-server [My HomeKit server]
> 0
Would you like to configure connector device(s)? (yes/no) [yes]:
>
```

You will then be prompted to select device management action.
```shell
What would you like to do?:
[0] Create new connector device
[1] Edit existing connector device
[2] Delete existing connector device
> 0
```
Or you could choose to manage connector devices from the main menu.

Now you will be asked to provide some device details:

Expand Down Expand Up @@ -319,6 +277,17 @@ If you want to configure more device services you could repeat whole process:
>
```
You could configure as many devices as you want.
### Connectors, Devices, Services and Characteristics management
With this console command you could manage all your connectors, their devices and services and characteristics. Just use the main menu to navigate to proper action.
## Configuring the Connector with the FastyBird User Interface
You can also configure the [Apple HomeKit](https://en.wikipedia.org/wiki/HomeKit) connector using the [FastyBird](https://www.fastybird.com) [IoT](https://en.wikipedia.org/wiki/Internet_of_things) user interface. For more information on how to do this,
please refer to the [FastyBird](https://www.fastybird.com) [IoT](https://en.wikipedia.org/wiki/Internet_of_things) documentation.
# Known Issues and Limitations
## Supported devices count
Expand Down
2 changes: 1 addition & 1 deletion src/FastyBird/Connector/HomeKit/src/Commands/Execute.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected function execute(Input\InputInterface $input, Output\OutputInterface $
}

if (count($connectors) === 0) {
$io->warning($this->translator->translate('//homekit-connector.cmd.execute.messages.noConnectors'));
$io->warning($this->translator->translate('//homekit-connector.cmd.base.messages.noConnectors'));

return Console\Command\Command::SUCCESS;
}
Expand Down
Loading

0 comments on commit 892be38

Please sign in to comment.