diff --git a/modules/ssdp_finder/ssdp_devices_scan.inc.php b/modules/ssdp_finder/ssdp_devices_scan.inc.php index 78974468..aba85302 100644 --- a/modules/ssdp_finder/ssdp_devices_scan.inc.php +++ b/modules/ssdp_finder/ssdp_devices_scan.inc.php @@ -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']; @@ -128,13 +168,12 @@ 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 ]; @@ -142,7 +181,30 @@ function Scan() } } } - 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) @@ -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"];