示例#1
0
 /**
  * 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
0
文件: GetSensors.php 项目: sqmk/phue
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
文件: GetLights.php 项目: sqmk/phue
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
文件: GetUsers.php 项目: sqmk/phue
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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());
     }
 }
示例#15
0
文件: Http.php 项目: Mahlstrom/Phue
 /**
  * Send request
  *
  * @param string   $address API address
  * @param string   $method  Request method
  * @param \stdClass $body    Post body
  *
  * @return string Request response
  * @throws Exception\ConnectionException
  * @throws \Exception
  */
 public function sendRequest($address, $method = self::METHOD_GET, \stdClass $body = null)
 {
     // Build request url
     $url = "http://{$this->client->getHost()}/api/{$address}";
     // Open connection
     $this->getAdapter()->open();
     // Send and get response
     $results = $this->getAdapter()->send($url, $method, $body ? json_encode($body) : null);
     $status = $this->getAdapter()->getHttpStatusCode();
     $contentType = $this->getAdapter()->getContentType();
     // Close connection
     $this->getAdapter()->close();
     // Throw connection exception if status code isn't 200 or wrong content type
     if ($status != 200 || $contentType != 'application/json') {
         throw new ConnectionException('Connection failure');
     }
     // Parse json results
     $jsonResults = json_decode($results);
     // Get first element in array if it's an array response
     if (is_array($jsonResults)) {
         $jsonResults = $jsonResults[0];
     }
     // Get error type
     if (isset($jsonResults->error)) {
         throw $this->getExceptionByType($jsonResults->error->type, $jsonResults->error->description);
     }
     // Get success object only if available
     if (isset($jsonResults->success)) {
         $jsonResults = $jsonResults->success;
     }
     return $jsonResults;
 }
示例#16
0
文件: Light.php 项目: Mahlstrom/Phue
 /**
  * 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;
 }
示例#17
0
文件: Http.php 项目: sqmk/phue
 /**
  * Send request
  *
  * @param string $address
  *            API address
  * @param string $method
  *            Request method
  * @param \stdClass $body
  *            Post body
  *
  * @return \stdClass Json body
  */
 protected function getJsonResponse($address, $method = self::METHOD_GET, \stdClass $body = null)
 {
     // Build request url
     $url = "http://{$this->client->getHost()}{$address}";
     // Open connection
     $this->getAdapter()->open();
     // Send and get response
     $results = $this->getAdapter()->send($url, $method, $body ? json_encode($body) : null);
     $status = $this->getAdapter()->getHttpStatusCode();
     $contentType = $this->getAdapter()->getContentType();
     // Throw connection exception if status code isn't 200 or wrong content type
     if ($status != 200 || $contentType != 'application/json') {
         throw new ConnectionException('Connection failure');
     }
     // Parse json results
     $jsonResults = json_decode($results);
     return $jsonResults;
 }
示例#18
0
文件: User.php 项目: bendspoons/Phue
 /**
  * Delete user
  */
 public function delete()
 {
     $this->client->sendCommand(new DeleteUser($this));
 }
示例#19
0
 /**
  * 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;
 }
示例#20
0
 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))
                 ->xy($useXY[0], $useXY[1])
         );
     }
     */
     /**
      * If effect option on, set the effect.
      */
     $effect = $input->getOption('effect') ? $input->getOption('effect') : 'none';
     if ($light->isOn() && $light->isReachable()) {
         $light->setEffect($effect);
     }
     /**
      * If brightness option on, set it.
      */
     if ($input->getOption('brightness') && $light->isOn() && $light->isReachable()) {
         $light->setBrightness($input->getOption('brightness'));
     }
     /**
      * If rename option set, rename.
      */
     if ($input->getOption('rename')) {
         $light->setName($input->getOption('rename'));
     }
 }
示例#21
0
 /**
  * Send command
  *
  * @param Client $client Phue Client
  *
  * @return mixed|void
  */
 public function send(Client $client)
 {
     $client->getTransport()->sendRequest("{$client->getUsername()}/config", TransportInterface::METHOD_PUT, (object) $this->config);
 }
示例#22
0
 /**
  * Send command
  *
  * @param Client $client Phue Client
  *
  * @return mixed|void
  */
 public function send(Client $client)
 {
     $client->getTransport()->sendRequest("{$client->getUsername()}/schedules/{$this->scheduleId}", TransportInterface::METHOD_DELETE);
 }
示例#23
0
 /**
  * Send command
  *
  * @param Client $client
  *            Phue Client
  *
  * @return mixed
  */
 public function send(Client $client)
 {
     // Get response
     $response = $client->getTransport()->sendRequest("/api/{$client->getUsername()}/lights", TransportInterface::METHOD_POST);
     return $response;
 }
示例#24
0
 /**
  * Send command
  *
  * @param Client $client Phue Client
  *
  * @return mixed|void
  */
 public function send(Client $client)
 {
     $client->getTransport()->sendRequest("{$client->getUsername()}/groups/{$this->groupId}", TransportInterface::METHOD_PUT, (object) $this->attributes);
 }
示例#25
0
 /**
  * Send command
  *
  * @param Client $client Phue Client
  *
  * @return string Scene Id
  */
 public function send(Client $client)
 {
     $client->getTransport()->sendRequest("/api/{$client->getUsername()}/scenes/{$this->id}", TransportInterface::METHOD_PUT, (object) ['name' => $this->name, 'lights' => $this->lights]);
     return $this->id;
 }
示例#26
0
 /**
  * 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;
 }
示例#27
0
 /**
  * Get schedulable params
  *
  * @param Client $client Phue Client
  *
  * @return array Key/value pairs of params
  */
 public function getSchedulableParams(Client $client)
 {
     return ['address' => "{$client->getUsername()}/groups/{$this->groupId}/action", 'method' => TransportInterface::METHOD_PUT, 'body' => (object) $this->params];
 }
示例#28
0
 /**
  * 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);
 }
示例#29
0
 /**
  * Send command
  *
  * @param Client $client
  *            Phue Client
  */
 public function send(Client $client)
 {
     $client->getTransport()->sendRequest("/api/{$client->getUsername()}/lights/{$this->lightId}", TransportInterface::METHOD_PUT, (object) array('name' => $this->name));
 }
示例#30
0
 /**
  * Send command
  *
  * @param Client $client Phue Client
  */
 public function send(Client $client)
 {
     $client->getTransport()->sendRequest("/api/{$client->getUsername()}/groups/{$this->groupId}", TransportInterface::METHOD_DELETE);
 }