Lines 75.00% 3 / 4
Functions and Methods 75.00% 3 / 4
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
UpdateExposedEntityState 75.00% 3 / 4 75.00% 3 / 4 4.25 0.00% 0 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 type 0.00% 0 / 1 0.00% 0 / 1 2
 describe 100.00% 1 / 1 100.00% 1 / 1 1
 toMessage 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Client\Connection\Command\Component;
6
7use Stewart\Client\Component\ExposedEntityAddress;
8use Stewart\Client\Component\ExposedStateFields;
9use Stewart\Client\Connection\Command\HaCommand;
10use Stewart\Contracts\Exposure\ExposedStateChange;
11
12final readonly class UpdateExposedEntityState implements HaCommand
13{
14    public function __construct(
15        public ExposedEntityAddress $address,
16        public ExposedStateChange $change,
17    ) {}
18
19    public function type(): string
20    {
21        return 'stewart/entity/state';
22    }
23
24    public function describe(): string
25    {
26        return \sprintf('%s %s', $this->type(), $this->address->describe());
27    }
28
29    public function toMessage(): array
30    {
31        return ['type' => $this->type(), ...$this->address->toMessageFields(), ...ExposedStateFields::formatStateChange($this->change)];
32    }
33}