Lines 60.00% 3 / 5
Functions and Methods 50.00% 2 / 4
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
RecordingExposedSensor 60.00% 3 / 5 50.00% 2 / 4 6.60 0.00% 0 / 1
 getConfig 0.00% 0 / 1 0.00% 0 / 1 2
 updateConfig 0.00% 0 / 1 0.00% 0 / 1 2
 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\Testing\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 RecordingExposedEntity<SensorConfig> */
14final class RecordingExposedSensor extends RecordingExposedEntity implements ExposedSensor
15{
16    public function getConfig(): SensorConfig
17    {
18        return $this->config;
19    }
20
21    public function updateConfig(SensorConfig $config): void
22    {
23        $this->recordConfig($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->recordChange(new ExposedStateChange(new ExposedState($this->config->formatState($value)), $attributes));
36    }
37}