Lines 100.00% 5 / 5
Functions and Methods 100.00% 4 / 4
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
WorkerExposedSensor 100.00% 5 / 5 100.00% 4 / 4 5 100.00% 1 / 1
 getConfig 100.00% 1 / 1 100.00% 1 / 1 1
 updateConfig 100.00% 1 / 1 100.00% 1 / 1 1
 getValue 100.00% 2 / 2 100.00% 1 / 1 2
 setValue 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Worker\Exposure;
6
7use DateTimeInterface;
8use Stewart\Contracts\Exposure\ExposedSensor;
9use Stewart\Contracts\Exposure\ExposedState;
10use Stewart\Contracts\Exposure\ExposedStateChange;
11use Stewart\Contracts\Exposure\SensorConfig;
12
13/** @extends WorkerExposedEntity<SensorConfig> */
14final class WorkerExposedSensor extends WorkerExposedEntity implements ExposedSensor
15{
16    public function getConfig(): SensorConfig
17    {
18        return $this->findConfig();
19    }
20
21    public function updateConfig(SensorConfig $config): void
22    {
23        $this->sendReconfiguration($config);
24    }
25
26    public function getValue(): int|float|string|null
27    {
28        $value = $this->findStateValue();
29
30        return \is_bool($value) ? null : $value;
31    }
32
33    public function setValue(int|float|string|DateTimeInterface|null $value, ?array $attributes = null): void
34    {
35        $this->sendChange(new ExposedStateChange(new ExposedState($this->getConfig()->formatState($value)), $attributes));
36    }
37}