本文整理汇总了PHP中Phue\Client::sendCommand方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::sendCommand方法的具体用法?PHP Client::sendCommand怎么用?PHP Client::sendCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phue\Client
的用法示例。
在下文中一共展示了Client::sendCommand方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: adjustLight
/**
* Adjust individual light
*
* @param $id
* @param $brightness
* @return array
*/
public function adjustLight($id, $brightness)
{
try {
$light = $this->client->sendCommand(new \Phue\Command\GetLightById($id));
$light->setOn(true);
$command = new \Phue\Command\SetLightState($light);
$command->brightness($brightness);
$this->client->sendCommand($command);
return array('command' => true);
} catch (\Exception $e) {
dd($e);
return array('command' => $e->getMessage());
}
}
示例2: setColorTemp
/**
* Set Color temperature
*
* @param int $value Color temperature value
*
* @return Light Self object
*/
public function setColorTemp($value)
{
$this->client->sendCommand((new SetLightState($this))->colorTemp((int) $value));
// Change both internal color temp and colormode state
$this->attributes->state->ct = (int) $value;
$this->attributes->state->colormode = 'ct';
return $this;
}
示例3: delete
/**
* Delete user
*/
public function delete()
{
$this->client->sendCommand(new DeleteUser($this));
}
示例4: setLinkButtonOn
/**
* Set link button state
*
* @param bool $state True for on, false for off
*
* @return self This object
*/
public function setLinkButtonOn($state = true)
{
$this->client->sendCommand(new SetBridgeConfig(['linkbutton' => (bool) $state]));
$this->attributes->linkbutton = (bool) $state;
return $this;
}
示例5: delete
/**
* Delete schedule
*/
public function delete()
{
$this->client->sendCommand(new Command\DeleteSchedule($this));
}
示例6: disableInstallNotification
/**
* Disable the install notification
*
* @return self This object
*/
public function disableInstallNotification()
{
$this->client->sendCommand(new SetBridgeConfig(['swupdate' => ['notify' => false]]));
$this->attributes->notify = false;
return $this;
}
示例7: setName
/**
* Set name of bridge
*
* @param string $name Name
*
* @return Bridge Self object
*/
public function setName($name)
{
$this->client->sendCommand(new SetBridgeConfig(['name' => (string) $name]));
$this->attributes->name = (string) $name;
return $this;
}
示例8: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$ip = $input->getArgument('ip');
$username = $input->getArgument('username');
if ($ip) {
$ipAddress = $ip;
} else {
$output->writeln('Finding your Bridge...');
$bridges = json_decode(file_get_contents('https://www.meethue.com/api/nupnp'));
/**
* No bridges - stop.
*/
if (!$bridges) {
$output->writeln('No bridges found - sorry!');
}
/**
* One bridge, grab IP.
*/
if (count($bridges) == 1) {
$ipAddress = $bridges[0]->internalipaddress;
}
/**
* Multiple bridges? Ask for IP.
*/
if (count($bridges) > 1) {
$choices = [];
foreach ($bridges as $bridge) {
$choices[] = $bridge->internalipaddress;
}
$helper = $this->getHelper('question');
$question = new ChoiceQuestion('We found multiple bridges. Which one do you want to connect to?', $choices, 0);
$question->setErrorMessage('Choice %s is invalid.');
$choice = $helper->ask($input, $output, $question);
$ipAddress = $choice;
$output->writeln('You have just selected: ' . $choice);
}
}
if ($input->getOption('yell')) {
//
}
/**
* Username.
*/
$user = $username ? $username : get_current_user();
$user = $user . substr(md5(microtime()), rand(0, 26), 10);
/**
* Authenticate with Bridge.
*/
$client = new Client($ipAddress, $user);
$output->writeln("Testing connection to bridge at {$client->getHost()}");
try {
$client->sendCommand(new Ping());
} catch (ConnectionException $e) {
$output->writeln("Issue connecting to bridge - " . $e->getMessage());
exit(1);
}
$output->writeln("Attempting to create user: " . $user . "...");
$output->writeln("Press the Bridge's button! Waiting...");
$maxTries = 30;
for ($i = 1; $i <= $maxTries; ++$i) {
try {
$response = $client->sendCommand(new CreateUser($user));
$output->write("\n");
$output->writeln("Successfully created new user: " . $response->username);
break;
} catch (LinkButtonException $e) {
$output->write(".");
} catch (Exception $e) {
$output->writeln("Failure to create user. Please try again!");
$output->writeln("Reason: " . $e->getMessage());
break;
}
sleep(1);
}
/**
* Save to memory.
* @todo Would prefer a better way of doing this, if you can think of one.
*/
if ($ipAddress && $user) {
file_put_contents("config.txt", json_encode(['ip' => $ipAddress, 'username' => $user]));
}
$output->writeln("Let there be light! Use `hue list` to see available commands.");
}