Skip to content

Commit

Permalink
Merge branch 'release/0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sabinus52 committed Jun 29, 2019
2 parents 4de8b26 + 988d526 commit ac75834
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog


### v0.2 - 29/06/2019

Add class `Color` for to control light


### v0.1 - 08/05/2019

Initial release (version beta)
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
],
"require": {
"php": "^5.2||^7",
"guzzlehttp/guzzle": "~6"
"guzzlehttp/guzzle": "~6",
"mexitek/phpcolors": "dev-master"
},
"autoload": {
"psr-4" : {
"Sabinus\\TuyaCloudApi\\" : "src/"
}
}
}
}
7 changes: 7 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<phpunit bootstrap="test/bootstrap.php" colors="true" verbose="true">
<testsuites>
<testsuite name="all">
<directory>test</directory>
</testsuite>
</testsuites>
</phpunit>
51 changes: 51 additions & 0 deletions src/Tools/Color.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Librairie des transformations des couleurs en surcharge de la classe Color
*
* @author Olivier <[email protected]>
*
* @package TuyaCloudApi
* @link https://github.com/mexitek/phpColors
*/

namespace Sabinus\TuyaCloudApi\Tools;

use Mexitek\PHPColors\Color as MexitekColor;


class Color extends MexitekColor
{

/**
* Corrections pour retourner les valeurs en pourcentage sur la saturation et la luminosité
*
* @see Mexitek\PHPColors\Color::hexToHsl
*/
public static function hexToHsl($color)
{
$HSL = parent::hexToHsl($color);

// Correction en pourcentage
$HSL['H'] = (int) $HSL['H'];
$HSL['S'] = (int) round($HSL['S']*100);
$HSL['L'] = (int) round($HSL['L']*100);

return $HSL;
}


/**
* Couvertion des valeurs de la saturation et la luminosité de pourcentage en décimale
*
* @see Mexitek\PHPColors\Color::hslToHex
*/
public static function hslToHex($hsl = array())
{
// Correction en decimal
if (isset($hsl['S'])) $hsl['S'] = $hsl['S'] / 100;
if (isset($hsl['L'])) $hsl['L'] = $hsl['L'] / 100;

return parent::hslToHex($hsl);
}

}
44 changes: 44 additions & 0 deletions test/Tools/ColorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Test de la class Color
*
* @author Olivier <[email protected]>
*
* @package TuyaCloudApi
*/

use PHPUnit\Framework\TestCase;
use Sabinus\TuyaCloudApi\Tools\Color;


class ColorTest extends TestCase
{

public function testRGB2HEX()
{
$this->assertSame('007fff', Color::rgbToHex(array('R' => 0, 'G' => 127, 'B' => 255)));
$this->assertSame('cf2080', Color::rgbToHex(array('R' => 207, 'G' => 32, 'B' => 128)));
}


public function testHEX2RGB()
{
$this->assertSame(array('R' => 0, 'G' => 127, 'B' => 255), Color::hexToRgb('007fff'));
$this->assertSame(array('R' => 207, 'G' => 32, 'B' => 128), Color::hexToRgb('cf2080'));
}


public function testHEX2HSL()
{
$this->assertSame(array('H' => 210, 'S' => 100, 'L' => 50), Color::hexToHsl('007fff'));
$this->assertSame(array('H' => 327, 'S' => 73, 'L' => 47), Color::hexToHsl('cf2080'));
}


public function testHSL2HEX()
{
$this->assertSame('0080ff', Color::hslToHex(array('H' => 210, 'S' => 100, 'L' => 50)));
$this->assertSame('cf2081', Color::hslToHex(array('H' => 327, 'S' => 73, 'L' => 47)));
}

}
19 changes: 19 additions & 0 deletions test/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

require __DIR__.'/../vendor/autoload.php';
includeAll(__DIR__.'/../src');


function includeAll($dir) {
$f = scandir($dir);
foreach ($f as $f2) {
if ($f2 == "." || $f2 == "..") continue;
if (is_dir($dir . DIRECTORY_SEPARATOR . $f2)) {
includeAll($dir . DIRECTORY_SEPARATOR . $f2);
} else {
if (substr($f2, -4) == ".php") {
include_once($dir . DIRECTORY_SEPARATOR . $f2);
}
}
}
}

0 comments on commit ac75834

Please sign in to comment.