Lines 50.00% 3 / 6
Functions and Methods 40.00% 2 / 5
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
WorkerExposedBinarySensor 50.00% 3 / 6 40.00% 2 / 5 10.50 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
 setOn 100.00% 1 / 1 100.00% 1 / 1 1
 setOff 0.00% 0 / 1 0.00% 0 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Worker\Exposure;
6
7use Stewart\Contracts\Exposure\BinarySensorConfig;
8use Stewart\Contracts\Exposure\ExposedBinarySensor;
9use Stewart\Contracts\Exposure\ExposedState;
10use Stewart\Contracts\Exposure\ExposedStateChange;
11
12/** @extends WorkerExposedEntity<BinarySensorConfig> */
13final class WorkerExposedBinarySensor extends WorkerExposedEntity implements ExposedBinarySensor
14{
15    public function getConfig(): BinarySensorConfig
16    {
17        return $this->findConfig();
18    }
19
20    public function updateConfig(BinarySensorConfig $config): void
21    {
22        $this->sendReconfiguration($config);
23    }
24
25    public function getValue(): ?bool
26    {
27        $value = $this->findStateValue();
28
29        return \is_bool($value) ? $value : null;
30    }
31
32    public function setOn(?array $attributes = null): void
33    {
34        $this->sendChange(new ExposedStateChange(new ExposedState(true), $attributes));
35    }
36
37    public function setOff(?array $attributes = null): void
38    {
39        $this->sendChange(new ExposedStateChange(new ExposedState(false), $attributes));
40    }
41}