-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitHub #88 - Add commands to update sensor config and state
- Loading branch information
Showing
3 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Phue: Philips Hue PHP Client | ||
* | ||
* @author Michael Squires <sqmk@php.net> | ||
* @copyright Copyright (c) 2012 Michael K. Squires | ||
* @license http://github.com/sqmk/Phue/wiki/License | ||
*/ | ||
|
||
namespace Phue\Command; | ||
|
||
use Phue\Client; | ||
use Phue\Transport\TransportInterface; | ||
|
||
/** | ||
* Update sensor config command | ||
*/ | ||
class UpdateSensorConfig extends CreateSensor | ||
{ | ||
/** | ||
* Sensor Id | ||
* | ||
* @var string | ||
*/ | ||
protected $sensorId; | ||
|
||
/** | ||
* Sensor config | ||
* | ||
* @var array | ||
*/ | ||
protected $config = []; | ||
|
||
/** | ||
* Constructs a command | ||
* | ||
* @param mixed $sensor Sensor Id or Sensor object | ||
*/ | ||
public function __construct($sensor) | ||
{ | ||
$this->sensorId = (string) $sensor; | ||
} | ||
|
||
/** | ||
* Config attribute | ||
* | ||
* @param string $key Key | ||
* @param mixed $value Value | ||
* | ||
* @return self This object | ||
*/ | ||
public function configAttribute($key, $value) | ||
{ | ||
$this->config[$key] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Send command | ||
* | ||
* @param Client $client Phue Client | ||
*/ | ||
public function send(Client $client) | ||
{ | ||
$client->getTransport()->sendRequest( | ||
"/api/{$client->getUsername()}/sensors/{$this->sensorId}/config", | ||
TransportInterface::METHOD_PUT, | ||
(object) $this->config | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Phue: Philips Hue PHP Client | ||
* | ||
* @author Michael Squires <sqmk@php.net> | ||
* @copyright Copyright (c) 2012 Michael K. Squires | ||
* @license http://github.com/sqmk/Phue/wiki/License | ||
*/ | ||
|
||
namespace Phue\Command; | ||
|
||
use Phue\Client; | ||
use Phue\Transport\TransportInterface; | ||
|
||
/** | ||
* Update sensor state command | ||
*/ | ||
class UpdateSensorState extends CreateSensor | ||
{ | ||
/** | ||
* Sensor Id | ||
* | ||
* @var string | ||
*/ | ||
protected $sensorId; | ||
|
||
/** | ||
* Sensor state | ||
* | ||
* @var array | ||
*/ | ||
protected $state = []; | ||
|
||
/** | ||
* Constructs a command | ||
* | ||
* @param mixed $sensor Sensor Id or Sensor object | ||
*/ | ||
public function __construct($sensor) | ||
{ | ||
$this->sensorId = (string) $sensor; | ||
} | ||
|
||
/** | ||
* State attribute | ||
* | ||
* @param string $key Key | ||
* @param mixed $value Value | ||
* | ||
* @return self This object | ||
*/ | ||
public function stateAttribute($key, $value) | ||
{ | ||
$this->state[$key] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Send command | ||
* | ||
* @param Client $client Phue Client | ||
*/ | ||
public function send(Client $client) | ||
{ | ||
$client->getTransport()->sendRequest( | ||
"/api/{$client->getUsername()}/sensors/{$this->sensorId}/state", | ||
TransportInterface::METHOD_PUT, | ||
(object) $this->state | ||
); | ||
} | ||
} |