homeos/tests/Feature/ShellyNormalizerTest.php

54 lines
2.2 KiB
PHP

<?php
namespace Tests\Feature;
use App\Support\Mqtt\ShellyNormalizer;
use PHPUnit\Framework\TestCase;
class ShellyNormalizerTest extends TestCase
{
public function test_digital_input_becomes_a_contact(): void
{
$open = ShellyNormalizer::normalize('input:0', ['id' => 0, 'state' => true]);
$this->assertSame('input:0', $open[0]['key']);
$this->assertSame('contact', $open[0]['type']);
$this->assertSame(['open' => true, 'position' => 'open'], $open[0]['state']);
$closed = ShellyNormalizer::normalize('input:1', ['id' => 1, 'state' => false]);
$this->assertSame(['open' => false, 'position' => 'closed'], $closed[0]['state']);
}
public function test_analog_or_count_input_is_not_a_contact(): void
{
$this->assertSame([], ShellyNormalizer::normalize('input:0', ['id' => 0, 'percent' => 40]));
$this->assertSame([], ShellyNormalizer::normalize('input:0', ['id' => 0, 'state' => null]));
}
public function test_contact_component_supports_three_state_tilt(): void
{
$tilted = ShellyNormalizer::normalize('contact:0', ['position' => 'tilted']);
$this->assertSame('contact', $tilted[0]['type']);
$this->assertSame(['open' => true, 'position' => 'tilted'], $tilted[0]['state']);
$window = ShellyNormalizer::normalize('window:0', ['open' => true]);
$this->assertSame(['open' => true, 'position' => 'open'], $window[0]['state']);
$closed = ShellyNormalizer::normalize('contact:0', ['state' => false]);
$this->assertSame(['open' => false, 'position' => 'closed'], $closed[0]['state']);
}
public function test_switch_with_power_still_normalizes(): void
{
$updates = ShellyNormalizer::normalize('switch:0', ['output' => true, 'apower' => 12.7]);
$this->assertSame('switch', $updates[0]['type']);
$this->assertTrue($updates[0]['state']['on']);
$this->assertSame('power', $updates[1]['type']);
$this->assertSame(13, $updates[1]['state']['watts']);
}
public function test_contact_is_a_primary_onboarding_type(): void
{
$this->assertContains('contact', ShellyNormalizer::PRIMARY_TYPES);
}
}