Skip to content

Commit 051560b

Browse files
committed
no message
1 parent 6133468 commit 051560b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/Gateway.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public function getRgb(Device $device)
2424
{
2525
$hexValue = $this->getRgbAndBrightness($device);
2626

27-
if (strlen($hexValue) == 8) {
28-
return substr($hexValue, 2);
27+
if (strlen($hexValue) >= 7) {
28+
return strrev(substr(strrev($hexValue), 0, 6));
2929
}
3030

3131
return null;
@@ -41,7 +41,7 @@ public function setRgb(Device $device, $value)
4141
$value = dechex($value);
4242
}
4343

44-
$bright = $this->getBrightness($device);
44+
$bright = $this->getBrightness($device) ?? '01';
4545

4646
$this->miIO->send($device, 'set_rgb', [hexdec($bright . $value)]);
4747
}
@@ -54,8 +54,8 @@ public function getBrightness(Device $device)
5454
{
5555
$hexValue = $this->getRgbAndBrightness($device);
5656

57-
if (strlen($hexValue) == 8) {
58-
return substr($hexValue, 0, 2);
57+
if (strlen($hexValue) >= 7) {
58+
return strrev(substr(strrev($hexValue), 6));
5959
}
6060

6161
return null;
@@ -71,7 +71,7 @@ public function setBrightness(Device $device, $value)
7171
$value = dechex($value);
7272
}
7373

74-
$rgb = $this->getRgb($device);
74+
$rgb = $this->getRgb($device) ?? 'ffffff';
7575

7676
$this->miIO->send($device, 'set_rgb', [hexdec($value . $rgb)]);
7777
}
@@ -80,7 +80,7 @@ public function setBrightness(Device $device, $value)
8080
* @param Device $device
8181
* @return string|null
8282
*/
83-
public function getRgbAndBrightness(Device $device)
83+
public function getBrightnessAndRgb(Device $device)
8484
{
8585
$response = $this->miIO->send($device, 'get_prop', ['rgb']);
8686

@@ -95,7 +95,7 @@ public function getRgbAndBrightness(Device $device)
9595
* @param Device $device
9696
* @param int|string $value
9797
*/
98-
public function setRgbAndBrightness(Device $device, $value)
98+
public function setBrightnessAndRgb(Device $device, $value)
9999
{
100100
if (preg_match('/^[0-9a-f]{8}$/i', $value) !== false) {
101101
$value = hexdec($value);

0 commit comments

Comments
 (0)