/** * 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; }
/** * Fetches device details * * @param $devices * * @return array */ protected static function getDeviceInfo($devices) { $infos = []; foreach ($devices as $device) { $sender = $device['_sender']; $ip = substr($sender, 0, strpos($sender, ':')); $wc = new WemoClient($ip); $info = $wc->info('setup.xml'); $info = $info['root']['device']; $id = str_replace(' ', '_', strtolower($info['friendlyName'])); $data = ['id' => $id, 'ip' => $ip, 'deviceType' => $info['deviceType'], 'friendlyName' => $info['friendlyName'], 'modelName' => $info['modelName'], 'UDN' => $info['UDN']]; if (static::isBridge($info['UDN'])) { $bridge = new Bridge($ip); $bridgeDevices = $bridge->getPairedDevices(true); foreach ($bridgeDevices as $i => $bridgeDevice) { $bridgeDevice['id'] = str_replace(' ', '_', strtolower($bridgeDevice['FriendlyName'])); $bridgeDevices[$i] = $bridgeDevice; } $data['class_name'] = Bridge::class; $data['device'] = $bridgeDevices; } else { if (static::isLightSwitch($info['UDN'])) { $data['class_name'] = LightSwitch::class; } else { if (static::isWemoSwitch($info['UDN'])) { $data['class_name'] = WemoSwitch::class; } } } $infos[] = $data; } return $infos; }