127 lines
3.5 KiB
PHP
127 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Services\HomeAssistant;
|
|
|
|
use App\Core\Services\Home\HomeEntityInterface;
|
|
use App\Core\Services\Home\HomeEntityType;
|
|
use App\Services\HomeAssistant\EntityState;
|
|
use App\Services\HomeAssistant\HomeAssistantEntity;
|
|
use DateTimeImmutable;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class HomeAssistantEntityTest extends TestCase
|
|
{
|
|
public function testImplementsHomeEntityInterface(): void
|
|
{
|
|
$entityState = new EntityState(
|
|
'light.living_room',
|
|
'on',
|
|
['friendly_name' => 'Living Room Light'],
|
|
'2023-03-14T12:00:00+00:00',
|
|
'2023-03-14T12:00:00+00:00',
|
|
);
|
|
|
|
$entity = new HomeAssistantEntity($entityState);
|
|
|
|
$this->assertInstanceOf(HomeEntityInterface::class, $entity);
|
|
}
|
|
|
|
public function testGetId(): void
|
|
{
|
|
$entityState = new EntityState(
|
|
'light.living_room',
|
|
'on',
|
|
['friendly_name' => 'Living Room Light'],
|
|
'2023-03-14T12:00:00+00:00',
|
|
'2023-03-14T12:00:00+00:00',
|
|
);
|
|
|
|
$entity = new HomeAssistantEntity($entityState);
|
|
|
|
$this->assertEquals('light.living_room', $entity->getId());
|
|
}
|
|
|
|
public function testGetState(): void
|
|
{
|
|
$entityState = new EntityState(
|
|
'light.living_room',
|
|
'on',
|
|
['friendly_name' => 'Living Room Light'],
|
|
'2023-03-14T12:00:00+00:00',
|
|
'2023-03-14T12:00:00+00:00',
|
|
);
|
|
|
|
$entity = new HomeAssistantEntity($entityState);
|
|
|
|
$this->assertEquals('on', $entity->getState());
|
|
}
|
|
|
|
public function testGetName(): void
|
|
{
|
|
$entityState = new EntityState(
|
|
'light.living_room',
|
|
'on',
|
|
['friendly_name' => 'Living Room Light'],
|
|
'2023-03-14T12:00:00+00:00',
|
|
'2023-03-14T12:00:00+00:00',
|
|
);
|
|
|
|
$entity = new HomeAssistantEntity($entityState);
|
|
|
|
$this->assertEquals('Living Room Light', $entity->getName());
|
|
}
|
|
|
|
public function testGetType(): void
|
|
{
|
|
$entityState = new EntityState(
|
|
'light.living_room',
|
|
'on',
|
|
['friendly_name' => 'Living Room Light'],
|
|
'2023-03-14T12:00:00+00:00',
|
|
'2023-03-14T12:00:00+00:00',
|
|
);
|
|
|
|
$entity = new HomeAssistantEntity($entityState);
|
|
|
|
$this->assertEquals(HomeEntityType::LIGHT, $entity->getType());
|
|
}
|
|
|
|
public function testGetLastChanged(): void
|
|
{
|
|
$timestamp = '2023-03-14T12:00:00+00:00';
|
|
$expectedDateTime = new DateTimeImmutable($timestamp);
|
|
|
|
$entityState = new EntityState(
|
|
'light.living_room',
|
|
'on',
|
|
['friendly_name' => 'Living Room Light'],
|
|
$timestamp,
|
|
'2023-03-14T12:30:00+00:00',
|
|
);
|
|
|
|
$entity = new HomeAssistantEntity($entityState);
|
|
|
|
$this->assertEquals($expectedDateTime, $entity->getLastChanged());
|
|
}
|
|
|
|
public function testGetLastUpdated(): void
|
|
{
|
|
$timestamp = '2023-03-14T12:30:00+00:00';
|
|
$expectedDateTime = new DateTimeImmutable($timestamp);
|
|
|
|
$entityState = new EntityState(
|
|
'light.living_room',
|
|
'on',
|
|
['friendly_name' => 'Living Room Light'],
|
|
'2023-03-14T12:00:00+00:00',
|
|
$timestamp,
|
|
);
|
|
|
|
$entity = new HomeAssistantEntity($entityState);
|
|
|
|
$this->assertEquals($expectedDateTime, $entity->getLastUpdated());
|
|
}
|
|
}
|