1
0

- lots of debugging

- beginning to add graphical stats
- beginning to add device by type
- added a dashboard "etage"
- begining to add notification to multiple recipients in freemobile hook
This commit is contained in:
2022-03-28 00:40:34 +02:00
parent 80234fc505
commit 0d35b1ff3f
24 changed files with 491 additions and 205 deletions

View File

@@ -21,42 +21,54 @@ function webDashboard($socket, $n="Général")
$propertyObject = $device->properties[$property];
$value = $propertyObject["value"];
logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)));
$response .= $device->friendlyName . aliases($device->friendlyName, $property) . " => " . bool2string(_($value)) . EOL;
$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);
$response .= "     " . displayChoice($device, $property, $value);
}
if(($propertyObject["access"] & 4))
{
logger(DEBUG, _("can get value") . ($propertyObject["access"] & 4), __FILE__ . ":" . __LINE__);
$response .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyObject["name"] . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "','" . $device->friendlyName . "','" . $propertyObject["name"] . "')\">";
$response .= '<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyObject["name"] . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "','" . $device->friendlyName . "','" . $propertyObject["name"] . "')\">";
}
}
$response .= EOLH;
}else
{
$response .= bool2string(_($value));
if(array_key_exists("unit", $propertyObject))
{
$response .= $propertyObject["unit"];
logger(DEBUG, _("unit = ") . $unit, __FILE__ . ":" . __LINE__);
}
$response .= EOLH;
}
}else
{
logger(ERROR, _("Property do not exist"), __FILE__ . ":" . __LINE__);
logger(ERROR, _("Property does not exists"), __FILE__ . ":" . __LINE__);
}
}else
{
logger(ERROR, _("Device do not exist"), __FILE__ . ":" . __LINE__);
logger(ERROR, _("Device does not exists"), __FILE__ . ":" . __LINE__);
}
}
}else
{
logger(ERROR, _("Dashboard does not exists"), __FILE__ . ":" . __LINE__);
$response = _("dashboard not found");
}
htmlSend($socket, $response);
htmlSend($socket, $response, '<meta http-equiv="refresh" content="10">');
}
function displayChoice($device, $propertyName)
function displayChoice($device, $propertyName, $value)
{
logger(INFO, _("function displayChoice"), __FILE__ . ":" . __LINE__);
$propertyObject = $device->properties[$propertyName];
$unit = '';
if(array_key_exists("unit", $propertyObject))
{
@@ -68,43 +80,54 @@ function displayChoice($device, $propertyName)
{
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);
$formHTML .= mkHTML($device, $propertyName, $choice);
break;
case "numeric":
logger(DEBUG, _("type is numeric"), __FILE__ . ":" . __LINE__);
$formHTML = '<input type="range" id="' . $propertyObject["name"] . '"';
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 = '<input type="number" id="' . $device->topic . "/"
. $device->friendlyName . "/"
. $propertyObject["name"] ."/value" . '"'
. ' min="' . $propertyObject["value_min"] . '"'
. ' max="' . $propertyObject["value_max"] . '"'
. $step
. ' value="' . $value . '">' . $unit . EOL;
$formHTML .= '<input type="range" id="' . $device->topic . "/" . $device->friendlyName . "/" . $propertyObject["name"] . '"';
$formHTML .= ' name="' . $propertyObject["name"] . '"';
$formHTML .= ' min="' . $propertyObject["value_min"] . '"';
$formHTML .= ' max="' . $propertyObject["value_max"] . '"';
$formHTML .= ' value="' . $propertyObject["value"] . '"';
if (array_key_exists("value_step", $propertyObject))
{
$formHTML .= ' step="' . $propertyObject["value_step"] . '"';
}
$formHTML .= " onchange=\"setPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', this.value, '" . $propertyObject["name"] . "')\">";
$formHTML .= $step;
$formHTML .= " oninput=\"setPropertyValue('" . $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);
$formHTML .= mkHTML($device, $propertyName, $choice);
break;
default:
logger(DEBUG, "type of property not recognized:" . $propertyObject["type"] , __FILE__ . ":" . __LINE__);
}
return $formHTML;
}
function mkHTML($device, $propertyName, $choice)
{
global $listenPort, $httpServerIp;
$html = "";
logger(DEBUG, _("function mkHTML"), __FILE__ . ":" . __LINE__);
logger(DEBUG, "function mkHTML", __FILE__ . ":" . __LINE__);
foreach ($choice as $key => $value)
{
$html .= '<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyName . "/" . $key . '" value="' . $value . "\" onmouseup=\"setPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', '" . $value . "', '" . $propertyName . "')\">";
@@ -205,13 +228,14 @@ function webBrowse($socket, $argList, $page="/browse")
function displayProperty($device, $key, $value, $response)
{
$tab="";
$response .= $key . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
if (array_key_exists("access", $value))
{
if(($value["access"] & 2))
{
logger(DEBUG, _("Write Access OK ") . ($value["access"] & 2), __FILE__ . ":" . __LINE__);
$response .= displayChoice($device, $key);
logger(DEBUG, _("Write Access OK: ") . ($value["access"] & 2) . "value:" . $value["value"], __FILE__ . ":" . __LINE__);
$response .= displayChoice($device, $key, $value["value"]);
}
if(($value["access"] & 4))
{
@@ -276,8 +300,11 @@ function webGet($argList)
$response = sprintf(_('"%s" or "%s" does not exists'), $argList["topic"], $argList["fn"]);
}else
{
logger(DEBUG, _("Getting "), __FILE__ . ":" . __LINE__ );
$property = $argList["property"];
$response = "GET: " . bool2string($device->$property["value"]);
$response = "Sending GET command for: " . $argList["topic"] . $argList["fn"];
$payload = array($argList["property"] => "");
publish($argList["topic"] . "/" . $argList["fn"], $payload, "get");
}
}
return $response;
@@ -301,7 +328,7 @@ function webSet($argList)
{
$response = "setting property " . $argList["property"] . " of " . $argList["fn"] . " to value: " . $argList["value"];
$payload = array($argList["property"] => $argList["value"]);
publish(Z2M . "/" . $argList["fn"], $payload);
publish($argList["topic"] . "/" . $argList["fn"], $payload);
//removeEvent($indexFriendlyName($argList["fn"]), $argList["property"], "OFF");
}
return $response;