本文整理汇总了PHP中Phue\Client::getLights方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getLights方法的具体用法?PHP Client::getLights怎么用?PHP Client::getLights使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phue\Client
的用法示例。
在下文中一共展示了Client::getLights方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLights
/**
* @return \Phue\Light[]
*/
public function getLights()
{
try {
$lights = array();
foreach ($this->client->getLights() as $lightId => $light) {
$light->isOn() ? $class = 'light-on' : ($class = 'light-off');
$light->isOn() ? $brightness = $light->getBrightness() : ($brightness = 0);
array_push($lights, array('id' => $lightId, 'name' => $light->getName(), 'brightness' => $brightness, 'isOn' => $light->isOn(), 'class' => $class));
}
return $lights;
} catch (\Exception $e) {
return array('error' => $e->getMessage());
}
}
示例2: 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);
}
示例3: 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))
//.........这里部分代码省略.........
示例4: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
/**
* Create client.
*/
$client = new Client(Hue::getConfig()->ip, Hue::getConfig()->username);
/**
* Turn all lights on or off.
*/
$on = $input->getArgument('on');
if ($on) {
$to = true;
if ($on == 'off') {
$to = false;
}
/**
* If set to on, turn on.
*/
foreach ($client->getLights() as $lightId => $light) {
$light->isReachable() ? $light->setOn($to) : '';
}
/**
* If set to off, turn off & stop here.
*/
if (!$to) {
return true;
}
}
$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 each light to be that color.
*/
foreach ($client->getLights() as $lightId => $light) {
if ($light->isReachable()) {
$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>');
}
}
}
/**
* No arguments added, just list available lights.
*/
if (!$on && !$color) {
if ($client->getLights()) {
foreach ($client->getLights() as $lightId => $light) {
$rows[] = [$light->getId(), $light->getName(), $light->getType(), $light->isOn() ? '✔' : '✘', $light->isReachable() ? '✔' : '✘'];
}
$table = new Table($output);
$table->setHeaders(array('ID', 'Name', 'Type', 'On', 'Reachable'))->setRows($rows);
$table->render();
}
}
/**
* If effect option on, set the effect for all lights.
*/
$effect = $input->getOption('effect') ? $input->getOption('effect') : 'none';
foreach ($client->getLights() as $lightId => $light) {
if ($light->isOn() && $light->isReachable()) {
$light->setEffect($effect);
}
}
/**
* If brightness option on, set it.
*/
if ($input->getOption('brightness')) {
foreach ($client->getLights() as $lightId => $light) {
if ($light->isOn() && $light->isReachable()) {
$light->setBrightness($input->getOption('brightness'));
}
}
}
}