Lines 88.88% 8 / 9
Functions and Methods 75.00% 3 / 4
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
UpsertExposedEntity 88.88% 8 / 9 75.00% 3 / 4 4.02 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% 6 / 6 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\ExposedEntityDefinition;
9use Stewart\Client\Component\ExposedStateFields;
10use Stewart\Client\Connection\Command\HaCommand;
11use Stewart\Contracts\Exposure\ExposedStateChange;
12
13final readonly class UpsertExposedEntity implements HaCommand
14{
15    public function __construct(
16        public ExposedEntityAddress $address,
17        public ExposedEntityDefinition $definition,
18        public ExposedStateChange $change,
19    ) {}
20
21    public function type(): string
22    {
23        return 'stewart/entity/upsert';
24    }
25
26    public function describe(): string
27    {
28        return \sprintf('%s %s', $this->type(), $this->address->describe());
29    }
30
31    public function toMessage(): array
32    {
33        return [
34            'type' => $this->type(),
35            ...$this->address->toMessageFields(),
36            ...$this->definition->toMessageFields(),
37            ...ExposedStateFields::formatStateChange($this->change),
38        ];
39    }
40}