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

Commit

Permalink
YeePHP: add light power control
Browse files Browse the repository at this point in the history
  • Loading branch information
SharkEzz committed Jan 1, 2021
1 parent ccee4c8 commit 5a34e52
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ It can as well be used in your 'from scratch' project or in the framework of you
- [x] Set the color (RGB) of the light
- [x] Set the light brightness
- [x] Set the light name
- [ ] Set the light power (on of off)
- [x] Set the light power (on of off)
- [x] Get light infos (partially completed)
- [ ] Color Flow control
- [ ] Proper error handling
Expand Down
17 changes: 16 additions & 1 deletion src/Interfaces/YeePHPInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public function getColor(): string;
*/
public function getName(): string;

/**
* Toggle the light
*
* @return bool
*/
public function toggle(): self;

/**
* Set the color of the light
*
Expand All @@ -75,11 +82,19 @@ public function setBrightness(int $amount): self;
/**
* Set the light name
*
* @param string $name
* @param string $name The name of the light
* @return $this
*/
public function setName(string $name): self;

/**
* Set the light on or off
*
* @param string $power The desired state, can be "on" or "off"
* @return $this
*/
public function setPower(string $power): self;

/**
* Send the parameters to the light.
* @return bool
Expand Down
37 changes: 34 additions & 3 deletions src/YeePHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class YeePHP implements YeePHPInterface
'toggle',
'set_bright',
'set_name',
'set_rgb'
'set_rgb',
'set_power'
];

/**
Expand All @@ -54,6 +55,9 @@ class YeePHP implements YeePHPInterface
*/
protected $socket;

protected string $fadeEffect = 'smooth';
protected int $fadeDelay = 300;

/**
* Light constructor.
* @param string $ip The light IP
Expand Down Expand Up @@ -140,15 +144,22 @@ public function getName(): string
return $this->getProp('name');
}

public function toggle(): self
{
$this->createJob('toggle', []);

return $this;
}

/**
* @inheritDoc
*/
public function setColor(int $hexColor): self
{
$this->createJob('set_rgb', [
$hexColor,
'smooth',
500
$this->fadeEffect,
$this->fadeDelay
]);

return $this;
Expand All @@ -173,13 +184,33 @@ public function setBrightness(int $amount): self
return $this;
}

/**
* @inheritDoc
*/
public function setName(string $name): self
{
$this->createJob('set_name', [$name]);

return $this;
}

/**
* @inheritDoc
*/
public function setPower(string $power): self
{
if(!$power === 'on' || !$power === 'off')
throw new Exception('Invalid power state: ' . $power);

$this->createJob('set_power', [
$power,
$this->fadeEffect,
$this->fadeDelay
]);

return $this;
}

/**
* @inheritDoc
* @throws Exception
Expand Down

0 comments on commit 5a34e52

Please sign in to comment.