Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
ggottwald committed Feb 18, 2018
1 parent 6133468 commit 051560b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function getRgb(Device $device)
{
$hexValue = $this->getRgbAndBrightness($device);

if (strlen($hexValue) == 8) {
return substr($hexValue, 2);
if (strlen($hexValue) >= 7) {
return strrev(substr(strrev($hexValue), 0, 6));
}

return null;
Expand All @@ -41,7 +41,7 @@ public function setRgb(Device $device, $value)
$value = dechex($value);
}

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

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

if (strlen($hexValue) == 8) {
return substr($hexValue, 0, 2);
if (strlen($hexValue) >= 7) {
return strrev(substr(strrev($hexValue), 6));
}

return null;
Expand All @@ -71,7 +71,7 @@ public function setBrightness(Device $device, $value)
$value = dechex($value);
}

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

$this->miIO->send($device, 'set_rgb', [hexdec($value . $rgb)]);
}
Expand All @@ -80,7 +80,7 @@ public function setBrightness(Device $device, $value)
* @param Device $device
* @return string|null
*/
public function getRgbAndBrightness(Device $device)
public function getBrightnessAndRgb(Device $device)
{
$response = $this->miIO->send($device, 'get_prop', ['rgb']);

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

0 comments on commit 051560b

Please sign in to comment.