Skip to content

Commit

Permalink
update or reset from model updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed Feb 13, 2024
1 parent 97cd263 commit 8c3f597
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 69 deletions.
54 changes: 32 additions & 22 deletions core/class/Abeille.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1380,37 +1380,45 @@ public static function message($topic, $payload) {
$eqModel = $eqLogic->getConfiguration('ab::eqModel', []);
$modelSource = isset($eqModel['modelSource']) ? $eqModel['modelSource'] : 'Abeille';
$modelName = isset($eqModel['modelName']) ? $eqModel['modelName'] : '';
$modelPath = isset($eqModel['modelPath']) ? $eqModel['modelPath'] : '';
$modelForced = isset($eqModel['modelForced']) ? $eqModel['modelForced'] : false;
$modelSig = isset($eqModel['modelSig']) ? $eqModel['modelSig'] : $modelName;
$modelName1 = $modelName;

// Checking if model is defaultUnknown and there is now a real model for it (see #2211).
// Also rechecking if model is still the correct one (ex: TS011F => TS011F__TZ3000_2putqrmw)
// $eqSig = $eqLogic->getConfiguration('ab::signature', []);
if (($eqSig != []) && ($eqSig['modelId'] != "") && !$modelForced) {
// Any user or official model ?
// $modelInfos = self::findModel($eqSig['modelId'], $eqSig['manufId']);
$modelInfos = identifyModel($eqSig['modelId'], $eqSig['manufId']);
if ($modelInfos !== false) {
$modelSig = $modelInfos['modelSig'];
$modelName = $modelInfos['modelName'];
$modelSource = $modelInfos['modelSource'];
$eqHName = $eqLogic->getHumanName();
}
}
$zigbee = $eqLogic->getConfiguration('ab::zigbee', []);
if (isset($zigbee['modelId']) && ($zigbee['modelId'] != "") && !$modelForced) {
// Any user or official model ?
$modelInfos = identifyModel($zigbee['modelId'], $zigbee['manufId']);
if ($modelInfos !== false) {
$modelSig = $modelInfos['modelSig'];
$modelName = $modelInfos['modelName'];
$modelSource = $modelInfos['modelSource'];
$eqHName = $eqLogic->getHumanName();
// if (($eqSig != []) && ($eqSig['modelId'] != "") && !$modelForced) {
// // Any user or official model ?
// // $modelInfos = self::findModel($eqSig['modelId'], $eqSig['manufId']);
// $modelInfos = identifyModel($eqSig['modelId'], $eqSig['manufId']);
// if ($modelInfos !== false) {
// $modelSig = $modelInfos['modelSig'];
// $modelName = $modelInfos['modelName'];
// $modelSource = $modelInfos['modelSource'];
// $eqHName = $eqLogic->getHumanName();
// }
// }
if (($modelName == '') || (($modelName == "defaultUnknown") && !$modelForced)) {
// Any better model ?
$zigbee = $eqLogic->getConfiguration('ab::zigbee', []);
if (isset($zigbee['modelId']) && ($zigbee['modelId'] != "")) {
$modelInfos = identifyModel($zigbee['modelId'], $zigbee['manufId']);
if ($modelInfos !== false) {
$modelSource = $modelInfos['modelSource'];
$modelName = $modelInfos['modelName'];
$modelPath = isset($modelInfos['modelPath']) ? $modelInfos['modelPath'] : '';
$modelSig = $modelInfos['modelSig'];
$eqHName = $eqLogic->getHumanName();
message::add("Abeille", $eqHName.": Mise-à-jour à partir du modèle '${modelName}'", '');
}
}
}

if ($modelName != $modelName1)
message::add("Abeille", $eqHName.": Nouveau modèle trouvé. Mise-à-jour en cours.", '');
if ($modelName == '') {
message::add("Abeille", $eqHName.": Mise-à-jour impossible. Modele non identifié => Réparer", '');
return;
}

$dev = array(
'net' => $dest,
Expand All @@ -1420,6 +1428,8 @@ public static function message($topic, $payload) {
'modelName' => $modelName, // Model file name
'modelSig' => $modelSig, // Model signature
);
if ($modelPath != '')
$dev['modelPath'] = $modelPath;
Abeille::createDevice($action, $dev);

return;
Expand Down
94 changes: 47 additions & 47 deletions core/php/AbeilleCliToQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,20 @@
return; // ERROR
}
list($eqNet, $eqAddr) = explode("/", $eqLogic->getLogicalId());
$zgId = substr($eqNet, 7); // AbeilleX => X
$eqModel = $eqLogic->getConfiguration('ab::eqModel', []);
if (isset($eqModel['modelName']) && ($eqModel['modelName'] != ''))
$jsonId = $eqModel['modelName'];
else
$jsonId = '';
if (isset($eqModel['modelSource']) && ($eqModel['modelSource'] != '') && ($eqModel['modelSource'] != null))
$jsonLocation = $eqModel['modelSource'];
else
$jsonLocation = 'Abeille';
if ($jsonId == '') {
logDebug("CliToQueue: ERROR: jsonId empty for device ".$eqId);
return; // ERROR
}
// $zgId = substr($eqNet, 7); // AbeilleX => X
// $eqModel = $eqLogic->getConfiguration('ab::eqModel', []);
// if (isset($eqModel['modelName']) && ($eqModel['modelName'] != ''))
// $jsonId = $eqModel['modelName'];
// else
// $jsonId = '';
// if (isset($eqModel['modelSource']) && ($eqModel['modelSource'] != '') && ($eqModel['modelSource'] != null))
// $jsonLocation = $eqModel['modelSource'];
// else
// $jsonLocation = 'Abeille';
// if ($jsonId == '') {
// logDebug("CliToQueue: ERROR: jsonId empty for device ".$eqId);
// return; // ERROR
// }

// OBSOLETE: Moved to 'ab::zigbee'
// $sig = $eqLogic->getConfiguration('ab::signature');
Expand All @@ -162,42 +162,42 @@
// $modelId = "";
// $manufId = "";
// }
$zigbee = $eqLogic->getConfiguration('ab::zigbee', []);
$modelId = isset($zigbee['modelId']) ? $zigbee['modelId'] : '';
$manufId = isset($zigbee['manufId']) ? $zigbee['manufId'] : '';
// $zigbee = $eqLogic->getConfiguration('ab::zigbee', []);
// $modelId = isset($zigbee['modelId']) ? $zigbee['modelId'] : '';
// $manufId = isset($zigbee['manufId']) ? $zigbee['manufId'] : '';

// Model forced by user ?
$isManualModel = isset($eqModel['modelForced']) ? $eqModel['modelForced']: false;
// $modelForced = isset($eqModel['modelForced']) ? $eqModel['modelForced']: false;

if (($jsonId == "defaultUnknown") && ($modelId != "") && !$isManualModel) {
$jsonId2 = "";
$jsonLoc2 = "";
$localP = __DIR__."/../../core/config/devices/";
$abeilleP = __DIR__."/../../core/config/devices/";
if (file_exists($localP.$modelId."_".$manufId."/".$modelId."_".$manufId.".json")) {
$jsonId2 = $modelId."_".$manufId;
$jsonLoc2 = "local";
} else if (file_exists($abeilleP.$modelId."_".$manufId."/".$modelId."_".$manufId.".json")) {
$jsonId2 = $modelId."_".$manufId;
$jsonLoc2 = "Abeille";
} else if (file_exists($localP.$modelId."/".$modelId.".json")) {
$jsonId2 = $modelId;
$jsonLoc2 = "local";
} else if (file_exists($abeilleP.$modelId."/".$modelId.".json")) {
$jsonId2 = $modelId;
$jsonLoc2 = "Abeille";
}
if (($jsonId2 != $jsonId) || ($jsonLoc2 != $jsonLocation)) {
if (isset($dbgTcharp38)) logDebug("CliToQueue: New jsonId: ".$jsonId2."/".$jsonLoc2);
$eqModel = $eqLogic->getConfiguration('ab::eqModel', []);
$eqModel['modelName'] = $jsonId2;
$eqModel['modelSource'] = $jsonLoc2;
$eqLogic->setConfiguration('ab::eqModel', $eqModel);
$eqLogic->save();
$jsonId = $jsonId2;
$jsonLocation = $jsonLoc2;
}
}
// if (($jsonId == "defaultUnknown") && ($modelId != "") && !$modelForced) {
// $jsonId2 = "";
// $jsonLoc2 = "";
// $localP = __DIR__."/../../core/config/devices/";
// $abeilleP = __DIR__."/../../core/config/devices/";
// if (file_exists($localP.$modelId."_".$manufId."/".$modelId."_".$manufId.".json")) {
// $jsonId2 = $modelId."_".$manufId;
// $jsonLoc2 = "local";
// } else if (file_exists($abeilleP.$modelId."_".$manufId."/".$modelId."_".$manufId.".json")) {
// $jsonId2 = $modelId."_".$manufId;
// $jsonLoc2 = "Abeille";
// } else if (file_exists($localP.$modelId."/".$modelId.".json")) {
// $jsonId2 = $modelId;
// $jsonLoc2 = "local";
// } else if (file_exists($abeilleP.$modelId."/".$modelId.".json")) {
// $jsonId2 = $modelId;
// $jsonLoc2 = "Abeille";
// }
// if (($jsonId2 != $jsonId) || ($jsonLoc2 != $jsonLocation)) {
// if (isset($dbgTcharp38)) logDebug("CliToQueue: New jsonId: ".$jsonId2."/".$jsonLoc2);
// $eqModel = $eqLogic->getConfiguration('ab::eqModel', []);
// $eqModel['modelName'] = $jsonId2;
// $eqModel['modelSource'] = $jsonLoc2;
// $eqLogic->setConfiguration('ab::eqModel', $eqModel);
// $eqLogic->save();
// $jsonId = $jsonId2;
// $jsonLocation = $jsonLoc2;
// }
// }

if ($action == "update") {
$msg = array(
Expand Down

0 comments on commit 8c3f597

Please sign in to comment.