Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Commit

Permalink
YeePHP: implemented setName method
Browse files Browse the repository at this point in the history
  • Loading branch information
SharkEzz committed Jan 1, 2021
1 parent ff20d50 commit 2591bea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Interfaces/YeePHPInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface YeePHPInterface
*
* @return bool
*/
public function isOnline(): bool;
public function isConnected(): bool;

/**
* Return true if the light is turned on, false otherwise
Expand Down
24 changes: 16 additions & 8 deletions src/YeePHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class YeePHP implements YeePHPInterface
public const ALLOWED_PROPS = [
'bright',
'rgb',
'name'
'name',
'power'
];

/**
Expand Down Expand Up @@ -86,7 +87,7 @@ public function __destruct()
/**
* @inheritDoc
*/
public function isOnline(): bool
public function isConnected(): bool
{
return $this->checkIsOnline();
}
Expand Down Expand Up @@ -158,6 +159,11 @@ public function setColor(int $hexColor): self
*/
public function setBrightness(int $amount): self
{
if($amount > 100)
$amount = 100;
else if($amount < 0)
$amount = 0;

$this->createJob('set_bright', [
$amount,
'smooth',
Expand All @@ -167,9 +173,11 @@ public function setBrightness(int $amount): self
return $this;
}

public function setName(string $name): YeePHPInterface
public function setName(string $name): self
{
// TODO: Implement setName() method.
$this->createJob('set_name', [$name]);

return $this;
}

/**
Expand Down Expand Up @@ -204,7 +212,7 @@ protected function connect(): bool
/**
* Get a certain prop value
*
* @param string $prop
* @param string $prop The prop name (refer to doc)
* @return string|null
* @throws Exception
*/
Expand Down Expand Up @@ -238,7 +246,7 @@ protected function checkIsOnline(): bool
/**
* Make a request to the light
*
* @param array $job
* @param array $job The job created by the createJob() method
* @return string|null
* @throws Exception
*/
Expand Down Expand Up @@ -273,8 +281,8 @@ protected function makeRequest(array $job): ?string
/**
* Create a new job to be committed
*
* @param string $method
* @param array $params
* @param string $method The method
* @param array $params The params
* @throws Exception
*/
protected function createJob(string $method, array $params): void
Expand Down
2 changes: 1 addition & 1 deletion tests/LightTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function setUp(): void

public function testCanSeeIfLightIsOnline(): void
{
$this->assertTrue($this->light->isOnline());
$this->assertTrue($this->light->isConnected());
}

public function testLightCanChangeColor(): void
Expand Down

0 comments on commit 2591bea

Please sign in to comment.