70 lines
2.3 KiB
PHP
70 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Belevo\EnelixUtils\SymconTest\TestContext;
|
|
|
|
return static function (TestContext $test): void {
|
|
$instancesBefore = array_flip(IPS_GetInstanceList());
|
|
$mqttId = $test->createInstance(
|
|
'{C6D2AEB3-6E1F-4B2E-8E69-3A1A00246850}',
|
|
'MQTT-Testserver'
|
|
);
|
|
$ioId = (int) IPS_GetInstance($mqttId)['ConnectionID'];
|
|
if ($ioId > 0 && !isset($instancesBefore[$ioId])) {
|
|
IPS_SetParent($ioId, $test->rootId());
|
|
}
|
|
|
|
$moduleId = $test->createInstance(
|
|
'{21D82EDB-AC8E-4F3D-9FEE-D20BCAFC1C33}',
|
|
'Shelly Modul'
|
|
);
|
|
if ((int) IPS_GetInstance($moduleId)['ConnectionID'] !== $mqttId) {
|
|
IPS_DisconnectInstance($moduleId);
|
|
IPS_ConnectInstance($moduleId, $mqttId);
|
|
IPS_ApplyChanges($moduleId);
|
|
}
|
|
|
|
$test->runCase('Instanz wird mit eigener MQTT-Elterninstanz angelegt', static function (
|
|
TestContext $test
|
|
) use ($moduleId, $mqttId): void {
|
|
$connectionId = (int) IPS_GetInstance($moduleId)['ConnectionID'];
|
|
$test->assertSame($mqttId, $connectionId);
|
|
$test->assertTrue(IPS_InstanceExists($connectionId));
|
|
});
|
|
|
|
$test->runCase('Topicfilter wird angewendet und gespeichert', static function (
|
|
TestContext $test
|
|
) use ($moduleId): void {
|
|
$test->configureInstance($moduleId, [
|
|
'UseDeviceTopicFilter' => true,
|
|
'DeviceTopicPrefix' => 'shelly-test',
|
|
'CreateOther' => false,
|
|
]);
|
|
$test->assertSame(true, IPS_GetProperty($moduleId, 'UseDeviceTopicFilter'));
|
|
$test->assertSame('shelly-test', IPS_GetProperty($moduleId, 'DeviceTopicPrefix'));
|
|
});
|
|
|
|
$test->runCase('Öffentliche Schaltfunktion sendet an MQTT', static function (
|
|
TestContext $test
|
|
) use ($moduleId): void {
|
|
$test->assertTrue(
|
|
IPS_FunctionExists('SHELLY_SetOutput'),
|
|
'Die öffentliche Funktion SHELLY_SetOutput fehlt.'
|
|
);
|
|
SHELLY_SetOutput($moduleId, 'shelly-test-device', 0, true);
|
|
});
|
|
|
|
$test->runCase('Konfigurationsformular ist gültiges JSON', static function (
|
|
TestContext $test
|
|
) use ($moduleId): void {
|
|
$form = json_decode(
|
|
IPS_GetConfigurationForm($moduleId),
|
|
true,
|
|
512,
|
|
JSON_THROW_ON_ERROR
|
|
);
|
|
$test->assertTrue(is_array($form));
|
|
});
|
|
};
|