From c93ed2919208d0729fa36dbd35355ec2f6f2be90 Mon Sep 17 00:00:00 2001 From: Frederic Bardin Date: Sat, 10 Sep 2016 18:00:02 +0200 Subject: [PATCH] v1.5 --- histo.txt | 27 ++--- include/about.php | 20 +++- include/functions.php | 2 +- include/rd_ZGPSwitch.php | 211 ++++++++++++++++++++++++++++++++++++++ include/rd_advanced.php | 145 ++++++++++++++++++++++++++ include/rules_details.php | 84 ++++++--------- include/scenes.php | 1 - include/text_en.json | 4 + include/text_fr.json | 4 + js/rules.js | 111 +++++++------------- themes/style.css | 9 +- 11 files changed, 477 insertions(+), 141 deletions(-) create mode 100644 include/rd_ZGPSwitch.php create mode 100644 include/rd_advanced.php diff --git a/histo.txt b/histo.txt index 9e3d7c2..c98e261 100644 --- a/histo.txt +++ b/histo.txt @@ -1,14 +1,15 @@ -v1.0 - 24/04/2015 : Creation -v1.1 - 04/05/2015 : Html tag attributes and javascript optimization -v1.2 - 07/06/2015 : Add Multi Lang support -v1.2.1 - 15/07/2015 : Correction of a select group display bug when a special case occured. -v1.2.2 - 16/07/2015 : Update logo in code and screenshots -v1.3 - 07/11/2015 : Add Automatic Configuration -v1.4 - 13/12/2015 : Add Effects scripts -v1.4.1 - 28/12/2015 : Correction to manage white only lights (='dimmable light' type) +v1.5 - 11/09/2016 : + - Add Sensors Rules management + - Update color conversion with new formulas from meethue + - Add 'on' status in setcolor/getcolor effect execution (not only color status) + - Update sample effects with save/restore original status + - Correct some minor display bugs v1.4.2 - 05/05/2016 : add new effect sample -v1.5 - 05/03/2016 : - - Add Sensors Rules management - - Update color conversion with new formulas from meethue - - Now, manage also 'on' status in setcolor/getcolor effect execution (not only color status) - - Update some sample effects with save/restore original status +v1.4.1 - 28/12/2015 : Correction to manage white only lights (='dimmable light' type) +v1.4 - 13/12/2015 : Add Effects scripts +v1.3 - 07/11/2015 : Add Automatic Configuration +v1.2.2 - 16/07/2015 : Update logo in code and screenshots +v1.2.1 - 15/07/2015 : Correction of a select group display bug when a special case occured. +v1.2 - 07/06/2015 : Add Multi Lang support +v1.1 - 04/05/2015 : Html tag attributes and javascript optimization +v1.0 - 24/04/2015 : Creation diff --git a/include/about.php b/include/about.php index 20b4ba9..8990466 100644 --- a/include/about.php +++ b/include/about.php @@ -10,8 +10,26 @@ $('#detail').hide("slide");
phpMyHue 1.5
F. Bardin 03-2016
F. Bardin 09-2016
Bridge IP :
Current language : +
+

+
+ $line){ + $line = preg_replace("/^(v.*) - /","$1 - ",$line); + echo "$line
\n"; +} +?> +
+ diff --git a/include/functions.php b/include/functions.php index 4c722af..c60a5f5 100644 --- a/include/functions.php +++ b/include/functions.php @@ -104,7 +104,7 @@ function display_lights_groups($prefid="",$cbpos="E",$brislider=false){ echo ""; echo ""; - echo ""; + echo ""; echo "
"; if ($cbpos == "B"){display_td_checkbox($prefid,"all");} echo ""; diff --git a/include/rd_ZGPSwitch.php b/include/rd_ZGPSwitch.php new file mode 100644 index 0000000..88ab356 --- /dev/null +++ b/include/rd_ZGPSwitch.php @@ -0,0 +1,211 @@ + $cval){ + if ($cval['operator'] == "eq"){ + $butval = $cval['value']; + break; + } +} + +// Get rule actions +// For Hue Tap : managed action is scene display or switch off lights (only 1 action allowed to stay simple, several actions wouldn't be very logical) +$selsceneid=""; +$selgroupid=""; +$htmode = "sc"; +foreach ($srules[$selruleid]['actions'] as $act => $aval){ + if (isset($aval['body']['scene'])){ + $htmode = "sc"; + $selsceneid = $aval['body']['scene']; + } elseif (isset($aval['body']['on'])){ + $selgroupid = preg_replace("/\/groups\/(.*)\/action/","$1", $aval['address']); + if ($aval['body']['on']==""){$htmode = "off";} + else {$htmode = "on";} + } +} + +echo "
"; +echo ""; +echo ""; +echo "
"; + +// Hue Tap button selection : Event value to button value is 34=1, 16=2, 17=3, 18=4 +echo ""; + +// Action : Scene or lights group on/off +echo ""; +echo "
"; +echo ""; +echo ""; +echo ""; +echo "
"; // htradio + +echo "
"; +echo ""; +// Scenes list +$HueAPI->loadInfo("scenes"); +// Create id->name array +$a_sname=""; +foreach ($HueAPI->info['scenes'] as $sceneid => $sval){ + $a_sname[$sceneid] = $sval['name']; +} +asort($a_sname); +// Display scenes list +echo ""; + +// On/Off list (all+groups) +$HueAPI->loadInfo("groups"); +createGroupList($selgroupid, "selhton", " ".$trs["On"]); +createGroupList($selgroupid, "selhtoff", " ".$trs["Off"]); + +echo "
"; +echo "
"; + +//------------------------------------------------------ +// Create a group list for a defined action +//------------------------------------------------------ +function createGroupList($gid, $selid, $label_suffix){ + global $trs,$HueAPI; + + echo ""; +} // createGroupList + +?> + diff --git a/include/rd_advanced.php b/include/rd_advanced.php new file mode 100644 index 0000000..6a135ce --- /dev/null +++ b/include/rd_advanced.php @@ -0,0 +1,145 @@ +".$trs["Conditions"]; +echo " "; +echo ""; +echo ""; +echo ""; +echo ""; +echo "\n"; +echo ""; +echo "
".$trs["Address"]."".$trs["Operator"]."".$trs["Value"]."\n"; +foreach ($srules[$selruleid]['conditions'] as $cond => $cval){getCondRow($sensorid, $cond, $cval);} +echo "
"; +echo "\n"; + +// Actions +echo "
".$trs["Actions"]; +echo " "; +echo ""; +echo ""; +echo ""; +echo ""; +echo "\n"; +echo ""; +echo "
".$trs["Address"]."".$trs["Method"]."".$trs["Action"]."\n"; +foreach ($srules[$selruleid]['actions'] as $act => $aval){getActRow($act, $aval);} +echo "
"; +echo "".$trs["method_warning"].""; +echo "
\n"; + +?> + diff --git a/include/rules_details.php b/include/rules_details.php index 8c41769..fa52076 100644 --- a/include/rules_details.php +++ b/include/rules_details.php @@ -9,8 +9,10 @@ @$sensorid=$_REQUEST['sensor']; @$selruleid=$_REQUEST['rule']; +@$advmode=$_REQUEST['advmode']; // Advanced mode (true if supply) // Load sensors informations +$HueAPI->loadInfo("sensors/$sensorid"); $HueAPI->loadInfo("rules"); $maxelem = 4; // Max allowed conditions or actions @@ -18,16 +20,19 @@ // Display selected sensor rules $rulesnum=0; $srules = array(); +$a_srules = array(); foreach ($HueAPI->info['rules'] as $ruleid => $rval) { // Look for conditions on selected sensor if (preg_match("/\/sensors\/$sensorid/",$rval['conditions']['0']['address'])){ $rulesnum++; $srules[$ruleid] = $rval; + $a_srules[$ruleid] = $rval['name']; } } -// If no rule : auto select CREATE option +// If no rule : auto select CREATE option, else sort by name if ($rulesnum == 0){$selruleid="0";} +else {asort($a_srules);} echo ""; echo ""; @@ -37,10 +42,10 @@ echo "\n"; -foreach ($srules as $ruleid => $rval){ +foreach ($a_srules as $ruleid => $rname){ echo "\n"; + echo ">$rname\n"; } echo "\n"; @@ -73,35 +78,24 @@ echo ">"; echo ""; // srradio - // Conditions echo "
\n"; - echo "
".$trs["Conditions"]; - echo " "; - echo ""; - echo ""; - echo ""; - echo ""; - echo "\n"; - echo ""; - echo "
".$trs["Address"]."".$trs["Operator"]."".$trs["Value"]."\n"; - foreach ($srules[$selruleid]['conditions'] as $cond => $cval){getCondRow($sensorid, $cond, $cval);} - echo "
"; - echo "
\n"; - // Actions - echo "
".$trs["Actions"]; - echo " "; - echo ""; - echo ""; - echo ""; - echo ""; - echo "\n"; - echo ""; - echo "
".$trs["Address"]."".$trs["Method"]."".$trs["Action"]."\n"; - foreach ($srules[$selruleid]['actions'] as $act => $aval){getActRow($act, $aval);} - echo "
"; - echo "".$trs["method_warning"].""; - echo "
\n"; + // Look for simple settings (depending on sensor type) + $sensor_found=false; + unset($simplemode); + if (! isset($advmode)){ // If advanced mode not asked + foreach (glob("include/rd_*.php") as $rd_file){ + $rd_sensor = preg_replace("/include\/rd_(.*).php/","$1",$rd_file); + if ($rd_sensor == $HueAPI->info['sensors'][$sensorid]['type']){ + $simplemode=true; + include $rd_file; + break; + } + } + } + + // Advanced settings if no simple settings used + if (! isset($simplemode)){include 'include/rd_advanced.php';} // Management buttons (Add/Update+Delete) echo " "; @@ -117,6 +111,11 @@ } echo ""; + // Manage simple/advanced button if needed + echo " "; + if (isset($advmode)){echo "";} + if (isset($simplemode)){echo "";} + // Empty div for dialog echo "
"; } @@ -125,27 +124,10 @@ $("#srsel").selectmenu({width : 'auto'}); $("#srradio").buttonset({width : 'auto'}); -// Buttons are disabled on init, they are enable on a row selection -$("#cmvup, #amvup").button({ - icons: {primary: "ui-icon-arrowthick-1-n"}, - text: false, - disabled: true -}); -$("#cmvdn, #amvdn").button({ - icons: {primary: "ui-icon-arrowthick-1-s"}, - text: false, - disabled: true -}); -$("#cdel, #adel").button({ - icons: {primary: "ui-icon-trash"}, - text: false, - disabled: true -}); -// 'Add' buttons -$("#cadd, #aadd").button({ - icons: {primary: "ui-icon-plusthick"}, - text: false -}); $("#rupd, #rdel").button(); + +// simple/advanced button +$("#simplemod, #advmod").button(); + sensorRulesDetail(); diff --git a/include/scenes.php b/include/scenes.php index febf660..902e131 100644 --- a/include/scenes.php +++ b/include/scenes.php @@ -21,7 +21,6 @@ } asort($a_sname); - // Display scenes echo ""; $oldname = ""; diff --git a/include/text_en.json b/include/text_en.json index 01b9709..bb74332 100644 --- a/include/text_en.json +++ b/include/text_en.json @@ -108,5 +108,9 @@ "Update":"Update", "Delete":"Delete", "Add":"Add", +"Button":"Button", +"Simple_mode":"Simple mode", +"Advanced_mode":"Advanced mode", +"Histo":"Histo", "":"" } diff --git a/include/text_fr.json b/include/text_fr.json index 7d487e0..a88df5f 100644 --- a/include/text_fr.json +++ b/include/text_fr.json @@ -108,5 +108,9 @@ "Update":"Mettre à jour", "Delete":"Supprimer", "Add":"Ajouter", +"Button":"Bouton", +"Simple_mode":"Mode Simple", +"Advanced_mode":"Mode Avancé", +"Histo":"Histo", "":"" } diff --git a/js/rules.js b/js/rules.js index 6a8020a..fd26900 100644 --- a/js/rules.js +++ b/js/rules.js @@ -49,7 +49,7 @@ function rulesTab(){ // Functions for rules details tab //======================================= //--------------------------------------- -// Trigger row selection +// Trigger row selection (advanced mode) // Select a row for conditions or actions acts as a radio button // Row selection impacts button enable/disable //--------------------------------------- @@ -88,7 +88,7 @@ function catchRowSelection(objectid){ } // catchRowSelection //--------------------------------------- -// Trigger operator change +// Trigger operator change (advanced mode) //--------------------------------------- function catchSelopeChange(objectid){ $(objectid).on("selectmenuchange", function (event,val) { @@ -101,7 +101,7 @@ function catchSelopeChange(objectid){ } // catchSelopeChange //-------------------------------------------------- -// Set the state (enable/disable) of the tables buttons +// Set the state (enable/disable) of the tables buttons (advanced mode) // These buttons are : up, down, delete, add //-------------------------------------------------- function setButtonsState(){ @@ -127,7 +127,7 @@ function setButtonsState(){ } // setButtonsState //---------------------------------------------------------- -// Update up and down button depending on the selected row +// Update up and down button depending on the selected row (advanced mode) // parameter : tableid = id of table buttons //---------------------------------------------------------- function updateUpDownState(tableid){ @@ -158,7 +158,7 @@ function updateUpDownState(tableid){ } // updateUpDownState //--------------------------------------- -// Initialize the rows count with displayed rule +// Initialize the rows count with displayed rule (advanced mode) //--------------------------------------- function InitRowsCount(){ nbcond = $(tabdetail+" tbody input.csel").length; @@ -169,13 +169,13 @@ function InitRowsCount(){ } // InitRowsCount //--------------------------------------- -// Function for 'sensor' rules detail tab +// Function for 'sensor' rules detail tab (advanced mode included) //--------------------------------------- function sensorRulesDetail(){ InitRowsCount(); // Trigger rule display on selection - $("#srsel").on("selectmenuchange", function (event,val) { + $("#srsel").on("selectmenuchange", function(){ var sensorid = $("#sensorid").val(); var ruleid = $(this).val(); $(tabdetail).load("details.php?rt=rules&nh=&sensor="+sensorid+"&rule="+ruleid, function(){ @@ -206,10 +206,14 @@ function sensorRulesDetail(){ // Manage update of rule $("#rupd").click(function(){updateRule();}); $("#rdel").click(function(){deleteRule();}); + + // Manage switch between simple and advanced mode if existing + $("#simplemod").click(function(){switchToAdvMode(false);}); + $("#advmod").click(function(){switchToAdvMode(true)});; } // sensorRulesDetail //----------------------------------------------------- -// Move up a table row +// Move up a table row (advanced mode) // parameter : // - tableid = id the table where the row is to move up //----------------------------------------------------- @@ -228,7 +232,7 @@ function mvUpSelectedDetail(tableid){ } // mvUpSelectedDetail //----------------------------------------------------- -// Move down a table row +// Move down a table row (advanced mode) // parameter : // - tableid = id the table where the row is to move down //----------------------------------------------------- @@ -247,7 +251,7 @@ function mvDownSelectedDetail(tableid){ } // mvDownSelectedDetail //----------------------------------------------------- -// Delete selected row +// Delete selected row (advanced mode) // parameters : // - tableid = id the table where the row is to delete //----------------------------------------------------- @@ -270,7 +274,7 @@ function delSelectedDetail(tableid){ } // delSelectedDetail //----------------------------------------------------- -// Add new condition row +// Add new condition row (advanced mode) //----------------------------------------------------- function addCond(){ var sensorid = $("#sensorid").val(); @@ -285,7 +289,7 @@ function addCond(){ } // addCond //----------------------------------------------------- -// Add new action row +// Add new action row (advanced mode) //----------------------------------------------------- function addAct(){ $("#acttable").append(''); @@ -299,6 +303,8 @@ function addAct(){ //----------------------------------------------------- // Update rule with current display +// Remark : call getConditionsJson and getActionJson from each specific display +// The specific display are in lib and named rd_.php //----------------------------------------------------- function updateRule(){ // Get values @@ -308,68 +314,13 @@ function updateRule(){ var rule_status = $("#srradio [name=srradio]:checked").val(); // Get conditions - var tdnum; - var cond,address,operator,value; - cond = ""; - $("#condtable tr").each(function(){ - address = ""; - tdnum = 0; - $(this).find("td").each(function(){ - tdnum++; - switch(tdnum){ - case 1 : // Check box = ignored - break; - case 2 : // Sensor address - address = $(this).find("input").val(); - break; - case 3 : // Operator - operator = $(this).find("select").val(); - break; - case 4 : // Value - value = $(this).find("input").val(); - break; - } - }); - if (address != "" && operator != ""){ - if (cond != ""){cond += ",";} - cond += '{"address":"/sensors/'+sensorid+'/'+address+'","operator":"'+operator+'"'; - if (operator != "dx"){ - cond += ',"value":"'+value+'"'; - } - cond += '}'; - } - }); + var cond = getConditionsJson(sensorid); +//msg("cond="+cond); // Get actions - var act,method,body; - act = ""; - $("#acttable tr").each(function(){ - address = ""; - tdnum = 0; - $(this).find("td").each(function(){ - tdnum++; - switch(tdnum){ - case 1 : // Check box = ignored - break; - case 2 : // Action address - address = $(this).find("input").val(); - break; - case 3 : // Method - method = $(this).find("select").val(); - break; - case 4 : // Json body send as action - body = $(this).find("input").val(); - break; - } - }); - if (address != "" && method != ""){ - if (act != ""){act += ",";} - act += '{"address":"'+address+'","method":"'+method+'"'; - act += ',"body":{'+body+'}'; - act += '}'; - } - }); - + var act = getActionsJson(); +//msg("act="+act); + // Create json string only if condition and action exist if (cond != "" && act != ""){ var cmdjs = "&cmdjs={"; @@ -441,7 +392,21 @@ function deleteRule(){ } } }); +} // deleteRule +//----------------------------------------------------- +// Switch to simple or advanced mode +//----------------------------------------------------- +function switchToAdvMode(advmode){ + var sensorid = $("#sensorid").val(); + var ruleid = $("#srsel").val(); -} // deleteRule + var advstr= ""; + if (advmode){advstr = "&advmode="+advmode;} + $(tabdetail).load("details.php?rt=rules&nh=&sensor="+sensorid+"&rule="+ruleid+advstr, function(){ + scrollCurrentTab("#detail"); + }); + // re-Initialize rows counters and buttons + InitRowsCount(); +} // switchToAdvMode diff --git a/themes/style.css b/themes/style.css index d592909..cbb7ff9 100644 --- a/themes/style.css +++ b/themes/style.css @@ -23,6 +23,9 @@ a { a.about { color: #f29a00; } +#histo { + text-align: left; +} /* Style for generic elements */ table { @@ -317,4 +320,8 @@ HIL002 : 2 lamps (2 bottom) /* Classes for effects debug window */ #runout { text-align:left; -} \ No newline at end of file +} +/* Class for selectmenu with overflow property like div */ +.overflow { + height: 150px; +}