- Files:
-
- 9 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
/trunk/L_Freebox.lua
r1 r3 9 9 10 10 11 local PLUGIN_VERSION = "0. 1"11 local PLUGIN_VERSION = "0.2" 12 12 13 13 local THIS_DEVICE = 0 … … 21 21 local settingsPerm = false 22 22 local refreshRate = 0 23 local netDevices = nil 23 24 24 25 local PLUGIN_SID = "urn:freebox-fr:serviceId:Freebox1" … … 67 68 local function setVarIfChanged(serviceId, name, value, deviceId, default) 68 69 local curValue = luup.variable_get(serviceId, name, deviceId) 69 70 70 if ((value ~= curValue) or (curValue == nil)) then 71 71 luup.variable_set(serviceId, name, value, deviceId) … … 74 74 return (default or false) 75 75 end 76 end 77 78 79 local function forceVarChange(serviceId, name, value, deviceId) 80 local curValue = luup.variable_get(serviceId, name, deviceId) 81 if (value == curValue) then 82 luup.variable_set(serviceId, name, "", deviceId) 83 end 84 luup.variable_set(serviceId, name, value, deviceId) 76 85 end 77 86 … … 363 372 364 373 local function checkNetworkDevices(checkSession) 365 local devices = {}366 367 374 if (checkSession) then 368 375 openSession() … … 398 405 data = getData(request, code, table.concat(result)) 399 406 if (data.success) then 407 local devices = {} 400 408 for i=1,count do 401 409 local id = data.result[i].id 402 410 devices[id] = {} 403 411 devices[id].name = data.result[i].primary_name 404 local ip = nil 412 devices[id].mac = "" 413 if (data.result[i].l2ident ~= nil 414 and data.result[i].l2ident.type == "mac_address") then 415 devices[id].mac = data.result[i].l2ident.id 416 end 417 devices[id].ip = "" 405 418 if (data.result[i].l3connectivities ~= nil) then 406 419 for j=1,5 do 407 if (data.result[i].l3connectivities[j] == nil) then 420 if (data.result[i].l3connectivities[j] ~= nil 421 and data.result[i].l3connectivities[j].af == "ipv4") then 422 devices[id].ip = data.result[i].l3connectivities[j].addr 408 423 break 409 end410 if (data.result[i].l3connectivities[j].af == "ipv4" or ip == nil) then411 ip = data.result[i].l3connectivities[j].addr412 424 end 413 425 end 414 426 end 415 if (ip ~= nil) then 416 devices[id].ip = ip 417 else 418 devices[id].ip = "undefined ip" 427 devices[id].reachable = data.result[i].reachable 428 if (netDevices ~= nil and netDevices[id] ~= nil and devices[id].mac ~= "") then 429 if (netDevices[id].reachable and not devices[id].reachable) then 430 forceVarChange(PLUGIN_SID, "PeripheriqueInjoignable", devices[id].mac, THIS_DEVICE) 431 elseif (not netDevices[id].reachable and devices[id].reachable) then 432 forceVarChange(PLUGIN_SID, "PeripheriqueJoignable", devices[id].mac, THIS_DEVICE) 433 end 419 434 end 420 devices[id].reachable = data.result[i].reachable421 435 end 436 netDevices = devices 422 437 else 423 438 log("Echec requête: " .. data.msg .. " ( " .. data.error_code .. " )", 2) … … 428 443 end 429 444 430 -- for k, v in pairs(devices) do 431 -- if (v.reachable) then 432 -- log(v.name .. " " .. v.ip .. " joignable") 433 -- else 434 -- log(v.name .. " " .. v.ip .. " injoignable") 435 -- end 436 -- end 445 local xml = "<net_devices>" 446 if (netDevices ~= nil) then 447 for k, v in pairs(netDevices) do 448 if (v.reachable) then 449 xml = xml .. "<device>" 450 xml = xml .. "<name>" .. v.name .. "</name>" 451 xml = xml .. "<ip>" .. v.ip .. "</ip>" 452 xml = xml .. "<mac>" .. v.mac .. "</mac>" 453 xml = xml .. "<reachable>true</reachable>" 454 xml = xml .. "</device>" 455 end 456 end 457 for k, v in pairs(netDevices) do 458 if (not v.reachable) then 459 xml = xml .. "<device>" 460 xml = xml .. "<name>" .. v.name .. "</name>" 461 xml = xml .. "<ip>" .. v.ip .. "</ip>" 462 xml = xml .. "<mac>" .. v.mac .. "</mac>" 463 xml = xml .. "<reachable>false</reachable>" 464 xml = xml .. "</device>" 465 end 466 end 467 end 468 xml = xml .. "</net_devices>" 469 setVarIfChanged(PLUGIN_SID, "PeripheriquesReseau", xml, THIS_DEVICE, false) 437 470 end 438 471 … … 643 676 local function getRefreshRate() 644 677 local rate = tonumber(luup.variable_get(PLUGIN_SID, "FrequenceMiseAJour", THIS_DEVICE) or "") 645 if (rate == nil or rate < 5) then678 if (rate == nil or (rate > 0 and rate < 5)) then 646 679 rate = 0 647 setVarIfChanged(PLUGIN_SID, "FrequenceMiseAJour", rate, THIS_DEVICE, false)680 setVarIfChanged(PLUGIN_SID, "FrequenceMiseAJour", string.format("%d", rate), THIS_DEVICE, false) 648 681 end 649 682 refreshRate = rate … … 657 690 rate = 0 658 691 end 659 setVarIfChanged(PLUGIN_SID, "FrequenceMiseAJour", rate, THIS_DEVICE, false)692 setVarIfChanged(PLUGIN_SID, "FrequenceMiseAJour", string.format("%d", rate), THIS_DEVICE, false) 660 693 local oldRate = refreshRate 661 694 refreshRate = rate … … 713 746 checkLanServer(false) 714 747 715 --checkNetworkDevices(false) 748 checkNetworkDevices(false) 749 750 -- local devices = luup.variable_get("urn:freebox-fr:serviceId:Freebox1", "PeripheriquesReseau", THIS_DEVICE) or "" 751 -- local mac = "" 752 -- local reachable = devices:match("<mac>"..mac.."</mac><reachable>(.-)</reachable>") 753 -- if (reachable == "true") then 754 -- log(mac .. " joignable") 755 -- elseif (reachable == "false") then 756 -- log(mac .. " injoignable") 757 -- else 758 -- log(mac .. " inconnu") 759 -- end 760 -- local ip = "" 761 -- reachable = devices:match("<ip>"..ip.."</ip>.-<reachable>(.-)</reachable>") 762 -- if (reachable == "true") then 763 -- log(ip .. " joignable") 764 -- elseif (reachable == "false") then 765 -- log(ip .. " injoignable") 766 -- else 767 -- log(ip .. " inconnu") 768 -- end 716 769 717 770 checkWifi(false) -
/trunk/D_Freebox.json
r1 r3 432 432 ] 433 433 }, 434 { 435 "Label": { 436 "lang_tag": "tabname_net_devices", 437 "text": "Peripheriques reseau" 438 }, 439 "Position": "1", 440 "TabType": "javascript", 441 "ScriptName": "J_Freebox.js", 442 "Function": "showNetDevices" 443 }, 434 444 { 435 445 "Label": { … … 437 447 "text": "Advanced" 438 448 }, 439 "Position": " 1",449 "Position": "2", 440 450 "TabType": "javascript", 441 451 "ScriptName": "shared.js", 442 452 "Function": "advanced_device" 453 }, 454 { 455 "Label": { 456 "lang_tag": "logs", 457 "text": "Logs" 458 }, 459 "Position": "3", 460 "TabType": "javascript", 461 "ScriptName": "shared.js", 462 "Function": "device_logs" 463 }, 464 { 465 "Label": { 466 "lang_tag": "notifications", 467 "text": "Notifications" 468 }, 469 "Position": "4", 470 "TabType": "javascript", 471 "ScriptName": "shared.js", 472 "Function": "device_notifications" 443 473 } 444 474 ], 445 "DeviceType": "urn:freebox-fr:device:Freebox:1" 475 "DeviceType": "urn:freebox-fr:device:Freebox:1", 476 "eventList": { 477 "event_1": { 478 "label": "Peripherique devient joignable", 479 "serviceId": "urn:freebox-fr:serviceId:Freebox1", 480 "argumentList" : { 481 "argument_1" : { 482 "dataType": "string", 483 "defaultValue": "", 484 "name": "PeripheriqueJoignable", 485 "comparisson": "=", 486 "prefix": "Adresse MAC", 487 "suffix": "" 488 } 489 } 490 }, 491 "event_2": { 492 "label": "Peripherique devient injoignable", 493 "serviceId": "urn:freebox-fr:serviceId:Freebox1", 494 "argumentList" : { 495 "argument_1" : { 496 "dataType": "string", 497 "defaultValue": "", 498 "name": "PeripheriqueInjoignable", 499 "comparisson": "=", 500 "prefix": "Adresse MAC", 501 "suffix": "" 502 } 503 } 504 } 505 }, 506 "eventList2": [ 507 { 508 "id": 1, 509 "label": { 510 "lang_tag": "device_reachable", 511 "text": "Peripherique devient joignable" 512 }, 513 "serviceId": "urn:freebox-fr:serviceId:Freebox1", 514 "argumentList": [ 515 { 516 "id": 1, 517 "dataType": "string", 518 "defaultValue": "", 519 "name": "PeripheriqueJoignable", 520 "comparisson": "=", 521 "prefix": { 522 "lang_tag": "mac_address", 523 "text": "Adresse MAC" 524 }, 525 "suffix": {} 526 } 527 ] 528 }, 529 { 530 "id": 2, 531 "label": { 532 "lang_tag": "device_unreachable", 533 "text": "Peripherique devient injoignable" 534 }, 535 "serviceId": "urn:freebox-fr:serviceId:Freebox1", 536 "argumentList": [ 537 { 538 "id": 1, 539 "dataType": "string", 540 "defaultValue": "", 541 "name": "PeripheriqueInjoignable", 542 "comparisson": "=", 543 "prefix": { 544 "lang_tag": "mac_address", 545 "text": "Adresse MAC" 546 }, 547 "suffix": {} 548 } 549 ] 550 } 551 ] 446 552 } -
/trunk/S_Freebox.xml
r1 r3 41 41 <dataType>boolean</dataType> 42 42 </stateVariable> 43 <stateVariable> 44 <name>PeripheriquesReseau</name> 45 <sendEventsAttribute>no</sendEventsAttribute> 46 <dataType>string</dataType> 47 </stateVariable> 48 <stateVariable> 49 <name>PeripheriqueJoignable</name> 50 <sendEventsAttribute>yes</sendEventsAttribute> 51 <dataType>string</dataType> 52 </stateVariable> 53 <stateVariable> 54 <name>PeripheriqueInjoignable</name> 55 <sendEventsAttribute>yes</sendEventsAttribute> 56 <dataType>string</dataType> 57 </stateVariable> 58 <stateVariable> 59 <name>PeripheriqueJoignable</name> 60 <sendEventsAttribute>no</sendEventsAttribute> 61 <dataType>string</dataType> 62 </stateVariable> 43 63 <stateVariable sendEvents="no"> 44 64 <name>A_ARG_TYPE_frequence</name> 45 65 <dataType>ui4</dataType> 66 </stateVariable> 67 <stateVariable sendEvents="no"> 68 <name>A_ARG_TYPE_mac</name> 69 <dataType>string</dataType> 46 70 </stateVariable> 47 71 </serviceStateTable>
Note: See TracChangeset
for help on using the changeset viewer.