Skip to content

Commit

Permalink
AbeilleRepair
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed Nov 15, 2023
1 parent 2522fab commit 2d84b6c
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 58 deletions.
100 changes: 61 additions & 39 deletions core/php/AbeilleRepair.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,83 +157,105 @@ function repairDevice($eqId, $eqLogic) {
if (isset($ep2['groups']))
logMessage('debug', ' Groups='.json_encode($ep2['groups']));
if (!isset($zigbee['groups']) || !isset($zigbee['groups'][$epId2])) {
msgToCli("step", "Server cluster 0004 infos");
msgToCli("step", "EP${epId2} server cluster 0004 infos");
logMessage('debug', ' Requesting groups membership for EP '.$epId2);
msgToCmd(PRIO_HIGH, "Cmd".$net."/".$addr."/getGroupMembership", "ep=".$epId2);
return; // To reduce requests on first missing groups membership
}
}
msgToCli("step", "Server cluster 0004 infos", "ok");
msgToCli("step", "EP${epId2} server cluster 0004 infos", "ok");
}

// Zigbee main signature correct ?
// Should reflect the signature of the first EP supporting cluster 0000
$sig = $eqLogic->getConfiguration('ab::signature', []);
logMessage('debug', ' ab::signature='.json_encode($sig));
$newSig = [];
$zbSig = $eqLogic->getConfiguration('ab::signature', []);
logMessage('debug', ' ab::signature='.json_encode($zbSig));
$zbNewSig = [];
foreach ($zigbee['endPoints'] as $epId2 => $ep2) {
if (strpos($ep2['servClusters'], '0000') === false)
continue; // No basic cluster for this EP

if (!isset($ep2['manufId']) || !isset($ep2['modelId'])) {
logMessage('debug', ' Missing model or manuf for EP '.$epId2);
logMessage('debug', ' ERROR: Missing model or manuf for EP '.$epId2);
return;
}

// model or manuf are now either known or unsupported
if (!isset($newSig['manufId']) && ($ep2['manufId'] != ''))
$newSig['manufId'] = $ep2['manufId'];
if (!isset($newSig['modelId']) && ($ep2['modelId'] != ''))
$newSig['modelId'] = $ep2['modelId'];
if (!isset($zbNewSig['manufId']) && ($ep2['manufId'] != ''))
$zbNewSig['manufId'] = $ep2['manufId'];
if (!isset($zbNewSig['modelId']) && ($ep2['modelId'] != ''))
$zbNewSig['modelId'] = $ep2['modelId'];

// Profalux specific case: using 'location' to get identifier
if (!isset($newSig['modelId']) && isset($ep2['location']) && ($ep2['location'] != '')) {
if (!isset($zbNewSig['modelId']) && isset($ep2['location']) && ($ep2['location'] != '')) {
logMessage('debug', " Profalux case: Using 'location'=".$ep2['location']);
$newSig['modelId'] = $ep2['location'];
$newSig['manufId'] = '';
$zbNewSig['modelId'] = $ep2['location'];
$zbNewSig['manufId'] = '';
}
}
if ($newSig != $sig) {
$eqLogic->setConfiguration('ab::signature', $newSig);
if ($zbNewSig != $zbSig) {
$eqLogic->setConfiguration('ab::signature', $zbNewSig);
$eqLogic->save();
logMessage('debug', " ab::signature updated to ".json_encode($newSig));
$sig = $newSig;
logMessage('debug', " ab::signature updated to ".json_encode($zbNewSig));
$zbSig = $zbNewSig;
}
if (!isset($sig['modelId'])) {
logMessage('debug', " Device ERROR: Invalid main Zigbee signature: ".json_encode($sig));
if (!isset($zbSig['modelId'])) {
msgToCli("step", "Zigbee signature");
logMessage('debug', " Device ERROR: Invalid main Zigbee signature: ".json_encode($zbSig));
return;
}
msgToCli("step", "Zigbee signature", "ok");

// Is model correct ?
// ab::eqModel = array(
// 'id' =>
// 'location' =>
// 'type' =>
// 'sig' => model signature
// 'id' => model file name
// 'location' => model file source
// 'type' => model type
// 'forcedByUser' => true|false
// )
$model = $eqLogic->getConfiguration('ab::eqModel', []);
logMessage('debug', ' ab::eqModel='.json_encode($model));
if (!isset($model['id']) || ($model['id'] == 'defaultUnknown')) {
logMessage('debug', " Model is 'defaultUnknown' or undefined.");
$m = AbeilleTools::findModel($sig['modelId'], $sig['manufId']);
if ($m !== false) {
$model['id'] = $m['jsonId'];
$model['location'] = $m['location'];
$model['type'] = $m['type'];
$modelChanged = false;
if (!isset($model['id']) || ($model['id'] == '')) {
msgToCli("step", "Model file name");
$modelContent = AbeilleTools::findModel($zbSig['modelId'], $zbSig['manufId']);
if ($modelContent !== false) {
$model['sig'] = $modelContent['modelSig'];
$model['id'] = $modelContent['jsonId'];
$model['location'] = $modelContent['location'];
$model['type'] = $modelContent['type'];
$model['forcedByUser'] = false;
$eqLogic->setConfiguration('ab::eqModel', $model);
$eqLogic->save();
logMessage('debug', " ab::eqModel updated to ".json_encode($model));
} else if (!isset($model['id'])) {
$model['id'] = 'defaultUnknown';
$model['location'] = 'Abeille';
$model['type'] = 'Unknown device';
$modelChanged = true;
}
}
if (!isset($model['sig']) || ($model['sig'] == '')) {
msgToCli("step", "Model signature");
logMessage('debug', " Missing model sig.");
if ($modelContent !== false) {
$model['sig'] = $modelContent['modelSig'];
$model['id'] = $modelContent['jsonId'];
$model['location'] = $modelContent['location'];
$model['type'] = $modelContent['type'];
$model['forcedByUser'] = false;
$eqLogic->setConfiguration('ab::eqModel', $model);
$eqLogic->save();
logMessage('debug', " ab::eqModel updated to ".json_encode($model));
$modelChanged = true;
// } else if (!isset($model['id'])) {
// $model['id'] = 'defaultUnknown';
// $model['location'] = 'Abeille';
// $model['type'] = 'Unknown device';
// $model['forcedByUser'] = false;
// $modelChanged = true;
}
}
if ($modelChanged) {
$eqLogic->setConfiguration('ab::eqModel', $model);
$eqLogic->save();
logMessage('debug', " ab::eqModel updated to ".json_encode($model));
}
if (isset($model['id']) && ($model['id'] != ''))
msgToCli("step", "Model file name", "ok");
if (isset($model['sig']) && ($model['sig'] != ''))
msgToCli("step", "Model signature", "ok");

logMessage('debug', ' Device OK');
}
Expand Down
39 changes: 24 additions & 15 deletions desktop/js/Abeille.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,33 @@ function refreshAdvEq() {
document.getElementById("idZgType").value = eq.zgType;
document.getElementById("idZbModel").value = eq.zbModel;
document.getElementById("idZbManuf").value = eq.zbManuf;

document.getElementById("idModelSig").value = eq.modelSig;
document.getElementById("idModelName").value = eq.modelName;
document.getElementById("idModelSource").value = eq.modelSource;
// Reset model choice to 'auto' if model has been forced
if (eq.modelForced) {
var $pRestoreModelAuto = $(
"<p><stron>{{Vous avez forcé le modèle de cet équipement. }}</strong></p>"
);
var $aRestoreModelAuto = $(
'<a href="#" id="linkRestoreAutoModel" style="text-decoration:underline;">{{ Rétablir le fonctionnement normal (modèle auto)}}</a>'
);
$pRestoreModelAuto
.append($aRestoreModelAuto)
.insertAfter("#idModelChangeBtn");
}
if (typeof eq.zigbee.manufCode != "undefined")
document.getElementById("idManufCode").value =
eq.zigbee.manufCode;
for (const [epId, ep] of Object.entries(eq.zigbee.endPoints)) {
// console.log("LA epId=", epId +", ep=", ep);
if (typeof ep.dateCode != "undefined")
document.getElementById("idDateCode").value = ep.dateCode;
else if (typeof ep.swBuildId != "undefined")
document.getElementById("swBuildId").value = ep.swBuildId;
}

docUrl = document.getElementById("idDocUrl");
docUrl.setAttribute("href", js_urlProducts + "/" + eq.modelName);
if (eq.modelSource == "local") {
Expand All @@ -93,22 +117,7 @@ function refreshAdvEq() {
document.getElementById("idBatteryType").value =
"{{Batterie}} " + eq.batteryType;

if (typeof eq.zigbee.manufCode != "undefined")
document.getElementById("idManufCode").value =
eq.zigbee.manufCode;

// Reset model choice to 'auto' if model has been forced
if (eq.modelForced) {
var $pRestoreModelAuto = $(
"<p><stron>{{Vous avez forcé le modèle de cet équipement. }}</strong></p>"
);
var $aRestoreModelAuto = $(
'<a href="#" id="linkRestoreAutoModel" style="text-decoration:underline;">{{ Rétablir le fonctionnement normal (modèle auto)}}</a>'
);
$pRestoreModelAuto
.append($aRestoreModelAuto)
.insertAfter("#idModelChangeBtn");
}

// Show/hide zigate or devices part
zgPart = document.getElementById("idAdvZigate");
Expand Down
8 changes: 4 additions & 4 deletions desktop/php/Abeille-Eq-Advanced-Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@

<div class="form-group">
<label class="col-sm-3 control-label">{{Date fabrication}} (DateCode)</label>
<div class="col-sm-5" advInfo="0000-01-0006">
<input type="text" id="" value="" readonly>
<div class="col-sm-5">
<input type="text" id="idDateCode" title="{{Cluster 0000, attribut 0006/DateCode}}" value="" readonly>
</div>
</div>

<div class="form-group">
<label class="col-sm-3 control-label">{{Version SW}} (SWBuildID)</label>
<div class="col-sm-5" advInfo="0000-01-4000">
<input type="text" id="" value="" readonly>
<div class="col-sm-5">
<input type="text" id="idSwBuildId" title="{{Cluster 0000, attribut 4000/SWBuildID}}"value="" readonly>
</div>
</div>

Expand Down

0 comments on commit 2d84b6c

Please sign in to comment.