本文整理汇总了PHP中Phue\Client类的典型用法代码示例。如果您正苦于以下问题:PHP Client类的具体用法?PHP Client怎么用?PHP Client使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$this->info('Hello Philips Hue');
$client = new Client('192.168.1.197', 'newdeveloper');
$light = $client->getLights()[1];
$light->setOn(true);
$light->setBrightness(150);
}
示例2: send
/**
* Send command
*
* @param Client $client
* Phue Client
*
* @return Sensor[] List of Sensor objects
*/
public function send(Client $client)
{
// Get response
$results = $client->getTransport()->sendRequest("/api/{$client->getUsername()}/sensors");
$sensors = array();
foreach ($results as $sensorId => $attributes) {
$sensors[$sensorId] = new Sensor($sensorId, $attributes, $client);
}
return $sensors;
}
示例3: send
/**
* Send command
*
* @param Client $client Phue Client
*
* @return Group[] List of Group objects
*/
public function send(Client $client)
{
// Get response
$results = $client->getTransport()->sendRequest("/api/{$client->getUsername()}/groups");
$groups = [];
foreach ($results as $groupId => $attributes) {
$groups[$groupId] = new Group($groupId, $attributes, $client);
}
return $groups;
}
示例4: send
/**
* Send command
*
* @param Client $client Phue Client
*
* @return Rule[] List of Rule objects
*/
public function send(Client $client)
{
// Get response
$results = $client->getTransport()->sendRequest("/api/{$client->getUsername()}/rules");
$rules = [];
foreach ($results as $ruleId => $attributes) {
$rules[$ruleId] = new Rule($ruleId, $attributes, $client);
}
return $rules;
}
示例5: send
/**
* Send command
*
* @param Client $client Phue Client
*
* @return bool True if authorized, false if not
*/
public function send(Client $client)
{
// Get response
try {
$client->getTransport()->sendRequest("/api/{$client->getUsername()}");
} catch (UnauthorizedUserException $e) {
return false;
}
return true;
}
示例6: send
/**
* Send command
*
* @param Client $client Phue Client
*
* @return Schedule[] List of Schedule objects
*/
public function send(Client $client)
{
// Get response
$response = $client->getTransport()->sendRequest("/api/{$client->getUsername()}/schedules");
$schedules = [];
foreach ($response as $scheduleId => $attributes) {
$schedules[$scheduleId] = new Schedule($scheduleId, $attributes, $client);
}
return $schedules;
}
示例7: send
/**
* Send command
*
* @param Client $client
* Phue Client
*
* @return Light[] List of Light objects
*/
public function send(Client $client)
{
// Get response
$response = $client->getTransport()->sendRequest("/api/{$client->getUsername()}/lights");
$lights = array();
foreach ($response as $lightId => $attributes) {
$lights[$lightId] = new Light($lightId, $attributes, $client);
}
return $lights;
}
示例8: send
/**
* Send command
*
* @param Client $client Phue Client
*
* @return array List of timezones
*/
public function send(Client $client)
{
// Get response
$response = $client->getTransport()->sendRequestBypassBodyValidation("/api/{$client->getUsername()}/info/timezones");
$timezones = [];
foreach ($response as $timezone) {
$timezones[] = $timezone;
}
return $timezones;
}
示例9: send
/**
* Send command
*
* @param Client $client Phue Client
*
* @return self This object
*/
public function send(Client $client)
{
// Get response
$response = $client->getTransport()->sendRequest("/api/{$client->getUsername()}/lights/new");
$this->lastScan = $response->lastscan;
// Remove scan from response
unset($response->lastscan);
// Iterate through left over properties as lights
foreach ($response as $lightId => $light) {
$this->lights[$lightId] = $light->name;
}
return $this;
}
示例10: send
/**
* Send command
*
* @param Client $client
* Phue Client
*
* @return User[] List of User objects
*/
public function send(Client $client)
{
// Get response
$response = $client->getTransport()->sendRequest("/api/{$client->getUsername()}/config");
// Return empty list if no users
if (!isset($response->whitelist)) {
return array();
}
$users = array();
foreach ($response->whitelist as $username => $attributes) {
$users[$username] = new User($username, $attributes, $client);
}
return $users;
}
示例11: send
/**
* Send command
*
* @param Client $client Phue Client
*
* @return Light[] List of Light objects
*/
public function send(Client $client)
{
// Get response
$response = $client->getTransport()->sendRequest($client->getUsername());
// Return empty list if no lights
if (!isset($response->lights)) {
return [];
}
$lights = [];
foreach ($response->lights as $lightId => $attributes) {
$lights[$lightId] = new Light($lightId, $attributes, $client);
}
return $lights;
}
示例12: send
/**
* Send command
*
* @param Client $client Phue Client
*
* @return Group[] List of Group objects
*/
public function send(Client $client)
{
// Get response
$response = $client->getTransport()->sendRequest($client->getUsername());
// Return empty list if no groups
if (!isset($response->groups)) {
return [];
}
$groups = [];
foreach ($response->groups as $groupId => $attributes) {
$groups[$groupId] = new Group($groupId, $attributes, $client);
}
return $groups;
}
示例13: send
/**
* Send command
*
* @param Client $client Phue Client
*
* @return Schedule[] List of Schedule objects
*/
public function send(Client $client)
{
// Get response
$response = $client->getTransport()->sendRequest($client->getUsername());
// Return empty list if no schedules
if (!isset($response->schedules)) {
return [];
}
$schedules = [];
foreach ($response->schedules as $scheduleId => $attributes) {
$schedules[$scheduleId] = new Schedule($scheduleId, $attributes, $client);
}
return $schedules;
}
示例14: send
/**
* Send command
*
* @param Client $client Phue Client
*
* @return \stdClass Authentication response
*/
public function send(Client $client)
{
// Get response
$response = $client->getTransport()->sendRequest('/api', TransportInterface::METHOD_POST, $this->buildRequestData($client));
return $response;
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
/**
* Get the chosen light ID.
*/
$lightID = $input->getArgument('id');
/**
* Create client.
*/
$client = new Client(Hue::getConfig()->ip, Hue::getConfig()->username);
/**
* Check that the chosen light ID exists and is reachable.
*/
if (!isset($client->getLights()[$lightID]) || !$client->getLights()[$lightID]->isReachable()) {
$output->writeln('<error>Light doesn\'t exist or is not reachable!</error>');
$output->writeln('Use `hue lights` to see available lights.');
exit(1);
}
$light = $client->getLights()[$lightID];
/**
* Turn all light on or off.
*/
$on = $input->getArgument('on');
if ($on) {
$to = true;
if ($on == 'off') {
$to = false;
}
/**
* If set to on, turn on.
*/
$light->setOn($to);
/**
* If set to off, turn off & stop here.
*/
if (!$to) {
return true;
}
}
/**
* Get the color argument.
*/
$color = $input->getArgument('color');
/**
* Handle if only 'on' param set (intended to be color).
*/
if ($on && $on !== 'on' && $on !== 'off' && !$color) {
$color = $on;
}
/**
* Possible moods.
*/
$possible_moods = Colors::colors();
/**
* If have mood, set it.
*/
if ($color) {
/**
* If mood matches possible ones, go ahead.
*/
if (isset($possible_moods[$color])) {
$color = $possible_moods[$color];
/**
* Set the light to be that color.
*/
$light->setXY($color[0], $color[1])->setBrightness(100);
} else {
$output->writeln('<question>That doesn\'t look to be a supported color! Try one of these:</question>');
foreach ($possible_moods as $possible_mood => $mood_colors) {
$output->writeln('<comment>' . ucfirst($possible_mood) . '</comment>');
}
}
}
/**
if ($color) {
/**
* Calculate X & Y points.
*/
/*
$xy = Converter::hexToXY($color);
$red = [0.675, 0.322];
$green = [0.409, 0.518];
$blue = [0.167, 0.04];
$area = 1/2*(-$green[1]*$blue[0] + $red[1]*(-$green[0] + $blue[0]) + $red[0]*($green[1] - $blue[1]) + $green[0]*$blue[1]);
$alpha = 1/(2*$area)*($red[1]*$blue[0] - $red[0]*$blue[1] + ($blue[1] - $red[1])*$xy[0] + ($red[0] - $blue[0])*$xy[1]);
$beta = 1/(2*$area)*($red[0]*$green[1] - $red[1]*$green[0] + ($red[1] - $green[1])*$xy[0] + ($green[0] - $red[0])*$xy[1]);
$gamma = 1 - $alpha - $beta;
$altX = $alpha*$red[0] + $beta*$green[0] + $gamma*$blue[0];
$altY = $alpha*$red[1] + $beta*$green[1] + $gamma*$blue[1];
if ($alpha > 1 && $beta > 1 && $gamma > 1) {
$useXY = $xy;
} else {
$useXY = [$altX, $altY];
}
$client->sendCommand(
(new SetLightState($light))
//.........这里部分代码省略.........