Skip to content

Commit 4cce999

Browse files
committed
UPDATE light trait
1 parent cd22551 commit 4cce999

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Traits/Light.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use MiIO\MiIO;
66
use MiIO\Models\Device;
7+
use MiIO\Models\Response;
8+
use Socket\Raw\Factory;
79

810
trait Light
911
{
@@ -14,7 +16,7 @@ trait Light
1416

1517
public function __construct()
1618
{
17-
$this->miIO = new MiIO();
19+
$this->miIO = new MiIO(new Factory());
1820
}
1921

2022
/**
@@ -88,13 +90,15 @@ public function setBrightness(Device $device, $value)
8890
*/
8991
public function getBrightnessAndRgb(Device $device)
9092
{
91-
$response = $this->miIO->send($device, 'get_prop', ['rgb']);
93+
$this->miIO->send($device, 'get_prop', ['rgb']);
9294

93-
if (isset($response['result'][0])) {
94-
return dechex($response['result'][0]);
95-
}
95+
return $this->miIO->read($device)->done(function ($response) {
96+
if ($response instanceof Response) {
97+
return dechex($response->getResult()[0]);
98+
}
9699

97-
return null;
100+
return null;
101+
});
98102
}
99103

100104
/**

0 commit comments

Comments
 (0)