Skip to content

Commit

Permalink
Check model tool update
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed Nov 14, 2023
1 parent 2c7f49f commit b9c0fdb
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions .tools/check_json.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// {"heating":"1","security":"0","energy":"0","light":"0","opening":"0","automatism":"0","multimedia":"0","default":"0"}
$eqCategories = ['heating', 'security', 'energy', 'light', 'opening', 'automatism', 'multimedia', 'default'];

// eqLogic generic types
$eqGenTypes = ['Other', 'Battery', 'Camera', 'Heating', 'Electricity', 'Environment', 'Generic', 'Light', 'Mode', 'Multimedia', 'Weather', 'Opening', 'Outlet', 'Robot', 'Security', 'Thermostat', 'Fan', 'Shutter'];

// Cmd 'action' & 'info' subtypes
$actSubTypes = ['other', 'slider', 'message', 'color', 'select'];
$infSubTypes = ['numeric', 'binary', 'string'];
Expand Down Expand Up @@ -38,7 +41,7 @@ function newDevError($file, $type, $msg) {
global $devErrors;
$e = array(
"file" => $file,
"type" => $type,
"type" => $type, // 'ERROR', 'WARNING'
"msg" => $msg
);
$devErrors[] = $e;
Expand Down Expand Up @@ -77,6 +80,7 @@ function cmdSubTypeIsOk($type, $subType) {
function checkDevice($devName, $dev) {
global $missingCmds;
global $commandsList;
global $eqGenTypes;

if (!isset($dev[$devName])) {
newDevError($devName, "ERROR", "Corruped JSON. Expecting '".$devName."' top key");
Expand All @@ -95,10 +99,10 @@ function checkDevice($devName, $dev) {
// Checking 'genericType'
if (isset($dev[$devName]['genericType'])) {
$genType = $dev[$devName]['genericType'];
$validGenTypes = ['Other', 'Battery', 'Camera', 'Heating', 'Electricity', 'Environment', 'Generic', 'Light', 'Mode', 'Multimedia', 'Weather', 'Opening', 'Outlet', 'Robot', 'Security', 'Thermostat', 'Fan', 'Shutter'];
if (!in_array($genType, $validGenTypes))
if (!in_array($genType, $eqGenTypes))
$error = newDevError($devName, "ERROR", "Invalid 'genericType' defined: ".$genType);
}
} /* else
$error = newDevError($devName, "WARNING", "No equipment genericType' defined"); */

// Checking 'category'
if (!isset($dev[$devName]['category'])) {
Expand Down Expand Up @@ -271,7 +275,7 @@ function checkDevice($devName, $dev) {
continue;
if (substr($key, 0, 7) == "comment")
continue;
newDevError($devName, "ERROR", "Invalid device key '".$key."'");
newDevError($devName, "ERROR", "Invalid device top key '".$key."'");
}
}

Expand Down Expand Up @@ -348,8 +352,8 @@ function checkCommand($cmdName, $cmd) {
}
} // End checkCommand()

function buildDevicesList() {
echo "Building devices list ...\n";
function buildDevModelsList() {
echo "Building devices models list ...\n";
global $devicesList;
$devicesList = [];
$dh = opendir(devicesDir);
Expand Down Expand Up @@ -497,8 +501,9 @@ function checkDeviceCommands($devName, $fullPath) {
}

// Checking all remaining #var# cases
// #EP# => replaced at during pairing
// #EP# => replaced at Jeedom EQ creation (pairing)
// #select# => dynamic variable, replaced at run time
// #title# + #message# => dynamic variables, replaced at run time
// echo "newCmdText=".$newCmdText."\n";
while (true) {
$start = strpos($newCmdText, "#"); // Start
Expand All @@ -507,8 +512,7 @@ function checkDeviceCommands($devName, $fullPath) {

$len = strpos(substr($newCmdText, $start + 1), "#"); // Length
if ($len === false) {
newDevError($devName, "ERROR", "No closing dash (#) for cmd '".$cmdJName."'");
$error = true;
$error = newDevError($devName, "ERROR", "No closing dash (#) for cmd '".$cmdJName."'");
break;
}
$len += 2;
Expand All @@ -517,21 +521,18 @@ function checkDeviceCommands($devName, $fullPath) {

if ($var == "#EP#") {
if (!isset($device['configuration']['mainEP'])) {
newDevError($devName, "ERROR", "'#EP#' found but NO 'mainEP'");
$error = true;
$error = newDevError($devName, "ERROR", "'#EP#' found but NO 'mainEP'");
}
} else if ($var == "#select#") {
if (!isset($devCmd['listValue']) && !isset($newCmd['listValue'])) {
newDevError($devName, "ERROR", "Undefined 'listValue' for '#select#'");
$error = true;
$error = newDevError($devName, "ERROR", "Undefined 'listValue' for '#select#'");
}
} else {
$allowed = ['#value#', '#slider#', '#title#', '#message#', '#color#', '#onTime#', '#IEEE#', '#addrIEEE#', '#ZigateIEEE#', '#ZiGateIEEE#', '#addrGroup#'];
// Tcharp38 note: don't know purpose of slider/title/message/color/onTime/GroupeEPx
if (!in_array($var, $allowed)) {
if (substr($var, 0, 9) != "#GroupeEP") {
newDevError($devName, "ERROR", "Missing '".$var."' variable data for cmd '".$cmdJName."'");
$error = true;
$error = newDevError($devName, "ERROR", "Missing '".$var."' variable data for cmd '".$cmdJName."'");
}
}
}
Expand Down Expand Up @@ -576,7 +577,7 @@ function checkDeviceCommands($devName, $fullPath) {
break;
}
if (count($devicesList) == 0) {
buildDevicesList();
buildDevModelsList();
buildAllCommandsList();
}

Expand Down

0 comments on commit b9c0fdb

Please sign in to comment.