Skip to content

Commit

Permalink
Merge pull request #292 from tarasfrompir/master
Browse files Browse the repository at this point in the history
вернул назад
  • Loading branch information
T-REX-XP committed Sep 18, 2018
2 parents 732d32f + a176366 commit 9344863
Showing 1 changed file with 74 additions and 11 deletions.
85 changes: 74 additions & 11 deletions modules/ssdp_finder/ssdp_devices_scan.inc.php
Expand Up @@ -60,12 +60,52 @@ function Scan()
if ($everything)
{

// подключение массива существующих модулей для найденных устройств
include_once (DIR_MODULES . 'ssdp_finder/extended_modules.php');

// перебираем по очереди все найденные устройства
foreach($everything as $deviceInfo)
{

// если устройство yeelight
if (substr($deviceInfo['location'], 0, 9) == "yeelight:")
{
$control_url = str_ireplace("yeelight:", "http:", $deviceInfo['location']);

// проверяем на наличие в базе для запрета вывода
$uuid = $deviceInfo['location'];
$existed = SQLSelectOne("SELECT * FROM $table_name WHERE UUID='" . $uuid . "'");

// need for chek device type
$device_type = 'YeelightSmartBulb'; //DeviceType
$services = 'YeelightSmartBulb'; //DeviceServices
// проверяем на наличие модуля в системе
$mod_cheked = SQLSelectOne("SELECT * FROM plugins WHERE MODULE_NAME LIKE '" . $modules['YeelightSmartBulb'] . "'");

if (!array_search_result($result, 'UUID', $uuid) && !is_null($uuid) && !($existed))
{
$result[] = [
"ID" => $existed["ID"], //existed id Majordomo
"TITLE" => 'Yeelight bulb', //friendly name
"ADDRESS" => 'https://www.yeelight.com', //presentation url (web UI of device),//presentation url (web UI of device)
"UUID" => $deviceInfo['location'],
"LOGO" => "/templates/ssdp_finder/img/YeelightSmartBulb.png", //Logo
"DESCRIPTION" => 'Yeelight WiFi Light', //description get from xml or field "server"
"TYPE" => $device_type, //DeviceType
"SERIAL" => 'not existed', //serialnumber
"MANUFACTURERURL" => 'https://www.yeelight.com', //manufacturer url
"UPDATED" => '', "MODEL" => 'not existed', //model
"MODELNUMBER" => 'not existed', //modelNumber
"MANUFACTURER" => 'YeelightSmartBulb', //Manufacturer
"SERVICES" => $services, //list services of device
"CONTROLADDRESS" => $control_url, //list services of device
"EXTENDED_MODULES" => $modules[$device_type], // проверка на наличие модуля
"MODULE_INSTALLED" => $mod_cheked, //chek the installed module
"EXTENDED_SIMPLEDEVICE" => check_seample_device($device_type) , //chek the simple device extended
];
$_SESSION[$uuid] = $logo;
}
}
else // иначе проверяем остальные устройства
{

// то что надо обработать в первую очередь
$device = $deviceInfo['description']['device'];
$control_url = $deviceInfo['location'];
Expand Down Expand Up @@ -128,21 +168,43 @@ function Scan()
"TYPE" => $device_type, //DeviceType
"SERIAL" => $serialnumber, //serialnumber
"MANUFACTURERURL" => $device["manufacturerURL"], //manufacturer url
"UPDATED" => date('Y-m-d H:i:s'),
"MODEL" => $device["modelName"], //model
"UPDATED" => '', "MODEL" => $device["modelName"], //model
"MODELNUMBER" => $device["modelNumber"], //modelNumber
"MANUFACTURER" => $device["manufacturer"], //Manufacturer
"SERVICES" => $services, //list services of device
"CONTROLADDRESS" => $control_url, //list services of device
"EXTENDED_MODULES" => $modules[$device_type],
"EXTENDED_MODULES" => ext_search_modules($services),
"MODULE_INSTALLED" => $mod_cheked, //chek the installed module
"EXTENDED_SIMPLEDEVICE" => check_seample_device($device_type) , //chek the simple device extended
];
$_SESSION[$uuid] = $logo;
}
}
}
return $result;
}

return $result;
}

function ext_search_modules($services)
{
// подключение массива существующих модулей для найденных устройств
include_once (DIR_MODULES . 'ssdp_finder/extended_modules.php');


//DebMes ($services);
$services = explode (',',$services);
foreach ( $services as $service)
{
$ext_module = $modules['MediaServer'];
DebMes ($service);
DebMes ('modules - '.serialize($modules));
if ($ext_module) {
$out = $ext_module;
return $ext_module;
}
}
return;
}

function array_search_result($array, $key, $value)
Expand Down Expand Up @@ -206,17 +268,18 @@ function getServices($device)
{
$name = $device["serviceList"]["service"]["serviceType"];
array_push($result, $name);
} else
if (isset($device["serviceList"]["service"]))
{
}
else
{
foreach($device["serviceList"]["service"] as $type)
{
$name = $type["serviceType"];
array_push($result, $name);
};
}
}

// иногда сервис уходит в глубь файла описания еще на одно поле ["deviceList"]["device"]

if (isset($device["deviceList"]["device"]["serviceList"]["service"]["serviceType"]))
{
$name = $device["deviceList"]["device"]["serviceList"]["service"]["serviceType"];
Expand Down

0 comments on commit 9344863

Please sign in to comment.