/** * 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; }
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 {
/** * @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); }