properties))
{
$propertyObject = $device->properties[$property];
$value = $propertyObject["value"];
logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)), __FILE__ . ":" . __LINE__);
$response .= $device->friendlyName . aliases($device->friendlyName, $property) . ' => ';
if (array_key_exists("access", $propertyObject))
{
logger(DEBUG, _("Access = ") . $propertyObject["access"], __FILE__ . ":" . __LINE__);
if(($propertyObject["access"] & 2))
{
logger(DEBUG, _("Write Access OK ") . ($propertyObject["access"] & 2), __FILE__ . ":" . __LINE__);
$response .= " " . displayChoice($device, $property, $value);
$response .= " " . displayMethod($device, $property) . EOL;
}
if(($propertyObject["access"] & 4))
{
logger(DEBUG, _("can get value") . ($propertyObject["access"] & 4), __FILE__ . ":" . __LINE__);
$response .= 'friendlyName . "/" . $propertyObject["name"] . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "','" . $device->friendlyName . "','" . $propertyObject["name"] . "')\">" . EOL;
}else
{
$response .= $value;
}
//$response .= EOLH;
}else
{
$response .= bool2string(_($value));
if(array_key_exists("unit", $propertyObject))
{
$response .= $propertyObject["unit"];
logger(DEBUG, _("unit = ") . $unit, __FILE__ . ":" . __LINE__);
}
}
if (array_key_exists($property, $properties2log))
{
$response .= ' Stats';
}
}else
{
logger(ERROR, _("Property does not exists"), __FILE__ . ":" . __LINE__);
}
}else
{
logger(ERROR, _("Device does not exists"), __FILE__ . ":" . __LINE__);
}
$response .= EOLH;
}
}else
{
logger(ERROR, _("Dashboard does not exists"), __FILE__ . ":" . __LINE__);
$response = _("dashboard not found");
}
htmlSend($socket, $response, '');
}
function displayChoice($device, $propertyName, $value)
{
logger(DEBUG, _("function displayChoice"), __FILE__ . ":" . __LINE__);
$propertyObject = $device->properties[$propertyName];
$unit = '';
if(array_key_exists("unit", $propertyObject))
{
$unit = $propertyObject["unit"];
logger(DEBUG, _("unit = ") . $unit, __FILE__ . ":" . __LINE__);
}
if (!array_key_exists("type", $propertyObject)) return "";
switch ($propertyObject["type"])
{
case "binary":
logger(DEBUG, _("type is binary"), __FILE__ . ":" . __LINE__);
$formHTML = bool2string($value);
$choice["on"] = $propertyObject["value_on"];
$choice["off"] = $propertyObject["value_off"];
if (array_key_exists("toggle", $propertyObject))
{
$choice["toggle"] = $propertyObject["toggle"];
}
$formHTML .= mkHTML($device, $propertyName, $choice);
break;
case "numeric":
logger(DEBUG, _("type is numeric") . "#" . $value . "#", __FILE__ . ":" . __LINE__);
$step = '';
if (array_key_exists("value_step", $propertyObject))
{
$step = ' step="' . $propertyObject["value_step"] . '"';
}
//$formHTML .= $device->friendlyName . aliases($device->friendlyName, $property) . ' => ';
$formHTML = 'friendlyName . "/"
. $propertyObject["name"] . '"'
. ' min="' . $propertyObject["value_min"] . '"'
. ' max="' . $propertyObject["value_max"] . '"'
. $step
. ' value="' . $value . '">' . $unit . EOL;
$formHTML .= 'friendlyName . "/" . $propertyObject["name"] . '"';
$formHTML .= ' name="' . $propertyObject["name"] . '"';
$formHTML .= ' min="' . $propertyObject["value_min"] . '"';
$formHTML .= ' max="' . $propertyObject["value_max"] . '"';
$formHTML .= ' value="' . $propertyObject["value"] . '"';
$formHTML .= $step;
$formHTML .= " oninput=\"setPropertyNumberValue('" . $device->topic . "', '" . $device->friendlyName . "', this.value, '" . $propertyObject["name"] . "')\">";
break;
case "enum":
logger(DEBUG, _("type is enum"), __FILE__ . ":" . __LINE__);
$formHTML = bool2string($value);
$choice = $propertyObject["values"];
$formHTML .= mkHTML($device, $propertyName, $choice);
break;
default:
logger(DEBUG, "type of property not recognized:" . $propertyObject["type"] , __FILE__ . ":" . __LINE__);
break;
}
return $formHTML;
}
function displayMethod($device, $propertyName)
{
$html = 'friendlyName . "/" . $propertyName . '" method="' . IDLE . "\" onmouseup=\"setPropertyMethod('" . $device->topic . "', '" . $device->friendlyName . "', '" . IDLE . "', '" . $propertyName . "')\">";
$html = 'friendlyName . "/" . $propertyName . "/" . '" method="' . AUTO . "\" onmouseup=\"setPropertyMethod('" . $device->topic . "', '" . $device->friendlyName . "', '" . AUTO . "', '" . $propertyName . "')\">";
$html = 'friendlyName . "/" . $propertyName . "/" . '" method="' . MANUAL . "\" onmouseup=\"setPropertyMethod('" . $device->topic . "', '" . $device->friendlyName . "', '" . MANUAL . "', '" . $propertyName . "')\">";
}
function mkHTML($device, $propertyName, $choice)
{
$html = "";
logger(DEBUG, "function mkHTML", __FILE__ . ":" . __LINE__);
foreach ($choice as $key => $value)
{
$html .= 'friendlyName . "/" . $propertyName . "/" . strtolower($value) . '" value="' . $value . "\" onmouseup=\"setPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', '" . $value . "', '" . $propertyName . "')\">";
}
return $html;
}
function apiBrowse($socket, $argList, $page="/browse")
{
global $topics, $devices, $listenPort,$indexDevices;
logger(INFO, _("Generic response to choose device and property"), __FILE__ . ":" . __LINE__);
//$response = "
" . nl2br(print_r($var, true)) . ""; }elseif($command === "dump") { $response = "Dump" . EOL; $response .= "" . nl2br(var_export($var, true)) . ""; } }else { $response = _("Object do not exists"); } return $response; } function apiNotify($argList) { if (!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList) or !array_key_exists("condition", $argList) or !array_key_exists("value", $argList)) { $response = _("Error: With 'notify' command, you need 5 parameters: topic, fn, property, condition, value"); }else { $response = _("notify command have been set"); $monitored[] = new watch($argList["topic"], $argList["fn"], $argList["property"], $argList["condition"], $argList["value"]); } return $response; } function apiVerbose($argList) { global $logLevel, $logLevels; logger(DEBUG, _("apiVerbose function"), __FILE__ . ":" . __LINE__); $response = ""; //print_r($argList); foreach ($logLevels as $value => $level) { //print $level . " => " . $value . " ==>" . strtoupper(trim($argList["cmd"])) . EOL; if (strtoupper(trim($argList["verbose"])) == $level) { print "change of " . $level . EOL; $logLevel ^= $value; } if ($logLevel & $value) { $response .= $level . _(" is active") . EOLH; }else { $response .= $level . _(" is inactive") . EOLH; } } return $response; } function getFn($argList) { global $indexDevices; $jsonArray = array(); logger(INFO, _("getFn function"), __FILE__ . ":" . __LINE__); if (array_key_exists("ieeeAddress", $argList)) { logger(DEBUG, "ieeeAddress = " . $argList["ieeeAddress"], __FILE__ . ":" . __LINE__); if (array_key_exists($argList["ieeeAddress"], $indexDevices)) { logger(DEBUG, "FriendlyName is " . $indexDevices[$argList["ieeeAddress"]]->friendlyName, __FILE__ . ":" . __LINE__); $response = '["' . $argList["ieeeAddress"] . '":"' . $indexDevices[$argList["ieeeAddress"]]->friendlyName . '"]'; } }else { $flag = false; //$response = "{"; foreach($indexDevices as $ieeeAddress => $device) { /*if ($flag == false) { $flag = true; }else { $response .= ', '; } */ //$response .= '"' . $ieeeAddress . '" : "' . $indexDevices[$ieeeAddress]->friendlyName . '"'; $jsonArray[$ieeeAddress] = $indexDevices[$ieeeAddress]->friendlyName; array_multisort($jsonArray); } $response = json_encode($jsonArray, JSON_UNESCAPED_SLASHES); print $response; //print_r(json_decode($response)); } logger(DEBUG, "response = " . $response, __FILE__ . ":" . __LINE__); return $response; } function PropertiesDashboard($argList) { global $indexProperties; require_once "apiserver/javascript.php"; logger(INFO, _("propertiesDashboard function"), __FILE__ . ":" . __LINE__); $response = insertJavascript(); $property = $argList["property"]; //print_r($indexProperties[$property]); foreach($indexProperties as $propertyName => $index) { if (str_contains($propertyName, $property )) { foreach($index as $device) { $propertyObject = $device->properties[$propertyName]; $value = $propertyObject["value"]; logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)), __FILE__ . ":" . __LINE__); $response .= $device->friendlyName . aliases($device->friendlyName, $propertyName) . ' => '; if (array_key_exists("access", $propertyObject)) { logger(DEBUG, _("Access = ") . $propertyObject["access"], __FILE__ . ":" . __LINE__); if(($propertyObject["access"] & 2)) { logger(DEBUG, _("Write Access OK ") . ($propertyObject["access"] & 2), __FILE__ . ":" . __LINE__); $response .= " " . displayChoice($device, $propertyName, $value); } if(($propertyObject["access"] & 4)) { logger(DEBUG, _("can get value") . ($propertyObject["access"] & 4), __FILE__ . ":" . __LINE__); $response .= 'friendlyName . "/" . $propertyObject["name"] . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "','" . $device->friendlyName . "','" . $propertyObject["name"] . "')\">"; }else { $response .= bool2string($value); } $response .= EOLH; }else { $response .= bool2string(_($value)); if(array_key_exists("unit", $propertyObject)) { $response .= $propertyObject["unit"]; logger(DEBUG, _("unit = ") . $unit, __FILE__ . ":" . __LINE__); } $response .= EOLH; } } } } return $response; } function apiHookActive($argList, $status) { global $hooks; if (array_key_exists($argList["hook"], $hooks)) { $hooks[$argList["hook"]]->active = $status; if ($status) { return $argList["hook"] . _(" has been enabled"); }else { return $argList["hook"] . _(" has been disabled"); } }else { return _("Hook does not exists"); } } function deleteDevice($argList) { global $indexFriendlyNames; logger(DEBUG, _("removing ") . $indexFriendlyNames[$argList["fn"]]->friendlyname , __FILE__ . ":" . __LINE__); //unset($indexFriendlyNames[$argList["fn"]]); } /* function apiDisplayByType($argList) { global $indexTypes, $config; require_once $config . "porpertiesbytype.php"; require_once "apiserver/javascript.php"; $response .= insertJavascript(); foreach($indexTypes[$argList["type"]] as $device) { foreach($) displayProperty($device, $device->, $value, $response) } } */ function whoIsPresent($argList) { if (array_key_exists("nom", $argList)) { $nom = $argList["nom"]; $r = isPresent($nom); if ($r) { $r = $nom . _(" est présent") . EOLH; logger(DEBUG, _(" est présent") , __FILE__ . ":" . __LINE__); }elseif(!$r) { $r = $nom . _(" est absent") . EOLH; logger(DEBUG, _("Testing doors") , __FILE__ . ":" . __LINE__); }else { $r = $nom . _(" n'existe pas dans la base de données") . EOLH; logger(DEBUG, _("Testing doors") , __FILE__ . ":" . __LINE__); } }else { $r = isPresent(false, true); $r = "Sont présent: " . EOLH . $r . EOLH; } return $r; } function test() { global $scripts; $portes = array(); $msg = _("Opened doors:") . EOLH; logger(DEBUG, _("Testing doors") , __FILE__ . ":" . __LINE__); echo "testing doors"; $portes = $scripts["test_portes"]->testPortes(); if (!empty($portes)) { foreach($portes as $value) { $msg .= $value . EOL; } }else { $msg .= _("No doors opened"); } return $msg; } function unavailable() { global $indexDevices; $msg = _("List of unavailable devices:") . EOLH; foreach($indexDevices as $ieeeAddress => $device) { if (key_exists("availability", $device->properties)) { if ($device->properties["availability"]["value"] == "offline") { $msg .= $device->friendlyName . EOLH; } } } return $msg; } function help() { $msg = "
Commands | Description and Parameters | "; $msg .= "
browse | Browse device List fn=friendlyname topic=topicname |
dashboard | Display dashboards Name of the dashboard |
deletedevice | |
disable | Disable a hook name of the hook |
dump | Display the content of a variable variable name |
enable | Enable a hook name of the hook |
friendlyname | Return friendlyname from ieeeadress ieeeadress of device |
get | Get value of the property of a device fn=friendlyname, topic=topic name, property=property name |
ispresent | Return the presence of a person Name of the person |
notify | Notify when property condition and value topic, fn, property, condition, value |
type | |
present | List persons present |
Dump the content of a variable variable name | |
property | Display all devices with given property Property to display |
set | Set value of the property of a device fn=friendlyname, topic=topic name, property=property name |
test | Return all opened doors |
unavailable | Displey all unavalaible devices |
verbose | Enable or disable log levels " . htmlDisplayLoglevels() . " |