Skip to content

Commit

Permalink
[zigbee2mqtt-connector] Zigbee2MQTT integration (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jan 7, 2024
1 parent d1978cf commit 7596217
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
12 changes: 6 additions & 6 deletions src/Queue/Consumers/StoreDeviceConnectionState.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use FastyBird\Connector\Virtual;
use FastyBird\Connector\Virtual\Entities;
use FastyBird\Connector\Virtual\Queue;
use FastyBird\Library\Metadata;
use FastyBird\Library\Metadata\Documents as MetadataDocuments;
use FastyBird\Library\Metadata\Exceptions as MetadataExceptions;
use FastyBird\Library\Metadata\Types as MetadataTypes;
use FastyBird\Module\Devices\Exceptions as DevicesExceptions;
Expand Down Expand Up @@ -105,16 +105,16 @@ public function consume(Entities\Messages\Entity $entity): bool
);

if (
$entity->getState()->equalsValue(Metadata\Types\ConnectionState::STATE_DISCONNECTED)
|| $entity->getState()->equalsValue(Metadata\Types\ConnectionState::STATE_ALERT)
|| $entity->getState()->equalsValue(Metadata\Types\ConnectionState::STATE_UNKNOWN)
$entity->getState()->equalsValue(MetadataTypes\ConnectionState::STATE_DISCONNECTED)
|| $entity->getState()->equalsValue(MetadataTypes\ConnectionState::STATE_ALERT)
|| $entity->getState()->equalsValue(MetadataTypes\ConnectionState::STATE_UNKNOWN)
) {
$findDevicePropertiesQuery = new DevicesQueries\Configuration\FindDeviceDynamicProperties();
$findDevicePropertiesQuery->forDevice($device);

foreach ($this->devicesPropertiesConfigurationRepository->findAllBy(
$findDevicePropertiesQuery,
Metadata\Documents\DevicesModule\DeviceDynamicProperty::class,
MetadataDocuments\DevicesModule\DeviceDynamicProperty::class,
) as $property) {
$this->devicePropertiesStatesManager->setValidState($property, false);
}
Expand All @@ -130,7 +130,7 @@ public function consume(Entities\Messages\Entity $entity): bool

foreach ($this->channelsPropertiesConfigurationRepository->findAllBy(
$findChannelPropertiesQuery,
Metadata\Documents\DevicesModule\ChannelDynamicProperty::class,
MetadataDocuments\DevicesModule\ChannelDynamicProperty::class,
) as $property) {
$this->channelPropertiesStatesManager->setValidState($property, false);
}
Expand Down
14 changes: 6 additions & 8 deletions src/Writers/Periodic.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,14 @@ public function connect(): void

$findDevicePropertiesQuery = new DevicesQueries\Configuration\FindDeviceProperties();
$findDevicePropertiesQuery->forDevice($device);
$findDevicePropertiesQuery->settable(true);

$properties = $this->devicesPropertiesConfigurationRepository->findAllBy($findDevicePropertiesQuery);

foreach ($properties as $property) {
if (
(
$property instanceof MetadataDocuments\DevicesModule\DeviceDynamicProperty
|| $property instanceof MetadataDocuments\DevicesModule\DeviceMappedProperty
) && $property->isSettable()
$property instanceof MetadataDocuments\DevicesModule\DeviceDynamicProperty
|| $property instanceof MetadataDocuments\DevicesModule\DeviceMappedProperty
) {
$this->properties[$device->getId()->toString()][$property->getId()->toString()] = $property;
}
Expand All @@ -126,15 +125,14 @@ public function connect(): void
foreach ($channels as $channel) {
$findChannelPropertiesQuery = new DevicesQueries\Configuration\FindChannelProperties();
$findChannelPropertiesQuery->forChannel($channel);
$findChannelPropertiesQuery->settable(true);

$properties = $this->channelsPropertiesConfigurationRepository->findAllBy($findChannelPropertiesQuery);

foreach ($properties as $property) {
if (
(
$property instanceof MetadataDocuments\DevicesModule\ChannelDynamicProperty
|| $property instanceof MetadataDocuments\DevicesModule\ChannelMappedProperty
) && $property->isSettable()
$property instanceof MetadataDocuments\DevicesModule\ChannelDynamicProperty
|| $property instanceof MetadataDocuments\DevicesModule\ChannelMappedProperty
) {
$this->properties[$device->getId()->toString()][$property->getId()->toString()] = $property;
}
Expand Down
6 changes: 1 addition & 5 deletions tests/common.neon
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,14 @@ services:
factory: IPub\SlimRouter\Routing\Router
setup:
- addMiddleware(@fbJsonApi.middlewares.jsonapi)
- {
create: React\EventLoop\Factory::create()
type: React\EventLoop\LoopInterface
}

-
factory: FastyBird\Connector\Virtual\Tests\Fixtures\Dummy\DummyConnectorFactory
tags: [connector_type: dummy]
- {factory: FastyBird\Connector\Virtual\Tests\Fixtures\Dummy\DummyConnectorSchema}
- {factory: FastyBird\Connector\Virtual\Tests\Fixtures\Dummy\DummyDeviceSchema}

cache.storage: Nette\Caching\Storages\MemoryStorage
cache.storage: Nette\Caching\Storages\DevNullStorage

decorator:
Doctrine\Persistence\Mapping\Driver\MappingDriverChain:
Expand Down
2 changes: 1 addition & 1 deletion tests/tools/ConnectionWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(
)
{
$this->dbName = is_string(getenv('TEST_TOKEN'))
? 'fb_test_' . getmypid() . md5((string) time()) . getenv('TEST_TOKEN') ?? ''
? 'fb_test_' . getmypid() . md5((string) time()) . getenv('TEST_TOKEN')
: 'fb_test_' . getmypid() . md5((string) time());

unset($params['dbname']);
Expand Down
4 changes: 3 additions & 1 deletion tests/tools/JsonAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace FastyBird\Connector\Virtual\Tests\Tools;

use Closure;
use Nette;
use Nette\StaticClass;
use Nette\Utils;
use PHPUnit\Framework\ExpectationFailedException;
Expand All @@ -17,6 +18,7 @@ class JsonAssert

/**
* @throws ExpectationFailedException
* @throws Nette\IOException
*
* @throws Utils\JsonException
*/
Expand Down Expand Up @@ -76,7 +78,7 @@ public static function jsonDecode(string $input, string $nameForMessage): array
}

try {
return Utils\Json::decode($input, Utils\Json::FORCE_ARRAY);
return (array) Utils\Json::decode($input, Utils\Json::FORCE_ARRAY);
} catch (Utils\JsonException $e) {
throw new Utils\JsonException(
sprintf('%s is invalid: "%s"', $nameForMessage, $e->getMessage()),
Expand Down

0 comments on commit 7596217

Please sign in to comment.