예제 #1
0
파일: Bridge.php 프로젝트: a15lam/php-wemo
 /**
  * Retrieves all paired bridge devices.
  *
  * @param bool $refresh Set true to force device discovery
  *
  * @return mixed
  * @throws \Exception
  */
 public function getPairedDevices($refresh = false)
 {
     if ($refresh === false) {
         $device = Discovery::lookupDevice('ip', $this->ip);
         if (isset($device['device']) && is_array($device['device'])) {
             return $device['device'];
         }
     }
     $service = $this->services['BridgeService']['serviceType'];
     $controlUrl = $this->services['BridgeService']['controlURL'];
     $method = 'GetEndDevices';
     $arguments = ['DevUDN' => $this->getUDN($refresh), 'ReqListType' => 'PAIRED_LIST'];
     $rs = $this->client->request($controlUrl, $service, $method, $arguments);
     $rs = $this->unwrapResponse($rs);
     $rs = WemoClient::xmlToArray($rs['u:GetEndDevicesResponse']['DeviceLists']);
     // Standalone devices.
     $devices = $rs['DeviceLists']['DeviceList']['DeviceInfos'];
     if (static::isArrayAssoc($devices)) {
         $devices = $rs['DeviceLists']['DeviceList']['DeviceInfos']['DeviceInfo'];
     }
     foreach ($devices as $k => $d) {
         $d['IsGroupAction'] = 'NO';
         $devices[$k] = $d;
     }
     // Grouped devices.
     $groupedDeviceList = [];
     $groupedDevices = $rs['DeviceLists']['DeviceList']['GroupInfos'];
     if (static::isArrayAssoc($groupedDevices)) {
         $groupedDeviceList[] = $rs['DeviceLists']['DeviceList']['GroupInfos']['GroupInfo'];
     }
     foreach ($groupedDeviceList as $gd) {
         if (!empty($gd['GroupID']) && !empty($gd['GroupName']) && !empty($gd['GroupCapabilityValues'])) {
             $devices[] = ['DeviceID' => $gd['GroupID'], 'FriendlyName' => $gd['GroupName'], 'CurrentState' => $gd['GroupCapabilityValues'], 'productName' => $gd['DeviceInfos']['DeviceInfo'][0]['productName'], 'IsGroupAction' => 'YES'];
             if (isset($gd['DeviceInfos']) && isset($gd['DeviceInfos']['DeviceInfo'])) {
                 foreach ($gd['DeviceInfos']['DeviceInfo'] as $gdi) {
                     $gdi['IsGroupAction'] = 'NO';
                     $devices[] = $gdi;
                 }
             }
         }
     }
     return $devices;
 }
예제 #2
0
 /**
  * WemoClient constructor.
  *
  * @param array $mapping
  *
  * @throws WemoException
  */
 public function __construct(array $mapping)
 {
     foreach ($mapping as $key => $map) {
         if (!isset($map['player'])) {
             throw new WemoException("No 'player' set in device mapping");
         } elseif (!isset($map['wemo'])) {
             throw new WemoException("No 'wemo' set in device mapping");
         }
         $wemoInstance = [];
         if (is_array($map['wemo'])) {
             foreach ($map['wemo'] as $wemo) {
                 $wemoInstance[] = Discovery::getDeviceByName($wemo);
             }
         } else {
             $wemoInstance[] = Discovery::getDeviceByName($map['wemo']);
         }
         $map['wemo'] = $wemoInstance;
         $mapping[$key] = $map;
     }
     $this->mapping = $mapping;
 }
예제 #3
0
파일: test.php 프로젝트: a15lam/php-wemo
//echo "Off: ".print_r($bulb1->state(), true).PHP_EOL;
//
//$switch = \a15lam\PhpWemo\Discovery::getBaseDeviceByName('Foyer Light');
////$switch = new \a15lam\PhpWemo\Devices\LightSwitch('192.168.1.68');
//$switch = new \a15lam\PhpWemo\Devices\LightSwitch('foyer_light');
//echo $switch->state();
//$switch->On();
//sleep(2);
//$switch->Off();
//
//$switch = new \a15lam\PhpWemo\Devices\WemoSwitch('192.168.1.71');
//$switch->On();
//sleep(2);
//$switch->Off();
//sleep(2);
//$switch->On();
//print_r($switch->state());
//
//$wb = \a15lam\PhpWemo\Discovery::getDeviceByName('media room');
//$wb->on();
//sleep(2);
//echo "state:".$wb->state().PHP_EOL;
//sleep(2);
//$wb->off();
//sleep(1);
//echo "state:".$wb->state().PHP_EOL;
//$b = new \a15lam\PhpWemo\WemoClient('192.168.1.68');
//echo "here".PHP_EOL;
//print_r($b->info('setup.xml'));
$devices = \a15lam\PhpWemo\Discovery::find(true);
print_r($devices);
예제 #4
0
파일: console.php 프로젝트: a15lam/php-wemo
         echo "[{$i}] {$l}";
     }
 }
 $choice = -1;
 while (!isset($list[$choice])) {
     if ($choice !== -1) {
         echo "Invalid choice. Please select from 0 to " . (count($list) - 1) . PHP_EOL;
     }
     $choice = trim(readline("\nPlease select a Wemo device to control (0..." . (count($list) - 1) . "): "));
 }
 if ((int) $choice === count($list) - 1) {
     echo 'Bye...' . PHP_EOL;
     exit;
 }
 $chosen = explode('.', $list[$choice][0]);
 $device = \a15lam\PhpWemo\Discovery::lookupDevice('id', $chosen[0]);
 $deviceClass = $device['class_name'];
 $myDevice = null;
 if ($deviceClass === \a15lam\PhpWemo\Devices\Bridge::class) {
     $bridgeDevices = $device['device'];
     $bridgeDevice = [];
     foreach ($bridgeDevices as $bd) {
         if ($bd['id'] === $chosen[1]) {
             $bridgeDevice = $bd;
             break;
         }
     }
     $deviceType = $bridgeDevice['productName'];
     if ('Lighting' === $deviceType) {
         $myDevice = new \a15lam\PhpWemo\Devices\WemoBulb($chosen[0], $chosen[1]);
     } else {
예제 #5
0
 /**
  * @param $id
  *
  * @return mixed
  * @throws \Exception
  */
 protected static function getDeviceIpById($id)
 {
     $device = Discovery::lookupDevice('id', $id);
     if (isset($device['ip'])) {
         return $device['ip'];
     }
     throw new \Exception('Invalid device id supplied. No device found by id ' . $id);
 }
예제 #6
0
<?php

require __DIR__ . '/../vendor/autoload.php';
$refresh = isset($argv[1]) ? $argv[1] : false;
$devices = \a15lam\PhpWemo\Discovery::find($refresh);
print_r($devices);