Skip to content

Commit

Permalink
Dev models: tuyaEF00/fromDevice => private/EF00
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed Mar 19, 2024
1 parent 3e45296 commit a4a03e8
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 56 deletions.
2 changes: 1 addition & 1 deletion core/ajax/Abeille.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ function sendToCmd($topic, $payload = '') {
$curArr = $eqLogic->getConfiguration($eqConfKey, []);
foreach ($newArr as $setKey => $setVal) {
$curArr[$setKey] = $setVal;
logDebug(" ${eqConfKey}[${setKey}]=${setVal}");
logDebug(" ${eqConfKey}[${setKey}]=".json_encode($setVal, JSON_UNESCAPED_SLASHES));
}
$eqLogic->setConfiguration($eqConfKey, $curArr);
$eqLogic->save();
Expand Down
14 changes: 8 additions & 6 deletions core/class/Abeille.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3066,11 +3066,11 @@ public static function createDevice($action, $dev) {
else
$eqLogic->setConfiguration('poll', null);

// Tuya specific infos: OBSOLETE soon. Replaced by 'fromDevice'
if (isset($model['tuyaEF00']))
$eqLogic->setConfiguration('ab::tuyaEF00', $model['tuyaEF00']);
else
$eqLogic->setConfiguration('ab::tuyaEF00', null);
// Tuya specific infos: OBSOLETE ! Replaced by 'private' + 'EF00' + 'type=tuya'
// if (isset($model['tuyaEF00']))
// $eqLogic->setConfiguration('ab::tuyaEF00', $model['tuyaEF00']);
// else
// $eqLogic->setConfiguration('ab::tuyaEF00', null);

// Xiaomi specific infos: OBSOLETE soon. Replaced by 'fromDevice'
// if (isset($model['xiaomi']))
Expand Down Expand Up @@ -3103,7 +3103,7 @@ public static function createDevice($action, $dev) {
}
$eqLogic->setConfiguration('ab::zigbee', $zigbee);

// JSON model infos
// JSON model infos => 'ab::eqModel'
$eqModelInfos = array(
// Model infos
'modelSource' => $modelSource, // Equipment model file location
Expand All @@ -3117,8 +3117,10 @@ public static function createDevice($action, $dev) {
'manuf' => isset($model['manufacturer']) ? $model['manufacturer'] : '',
'model' => isset($model['model']) ? $model['model'] : '',
'type' => $model['type'],

// 'lastUpdate' => time(), // Store last update from model. // Tcharp38: created for Abeille but not used
// 'variables' // Optional
// 'private' // Optional
);
if ($modelPath != "${modelName}/${modelName}.json")
$eqModelInfos['modelPath'] = $modelPath;
Expand Down
11 changes: 8 additions & 3 deletions core/class/AbeilleParser.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,15 @@ function deviceConfigure($net, $addr) {
}
} else
$eq['customization'] = null;
if (isset($eqModel['tuyaEF00']))
$eq['tuyaEF00'] = $eqModel['tuyaEF00'];
// if (isset($eqModel['tuyaEF00']))
// $eq['tuyaEF00'] = $eqModel['tuyaEF00'];
// else
// $eq['tuyaEF00'] = null;
// Really required here ?
if (isset($eqModel['private']))
$eq['private'] = $eqModel['private'];
else
$eq['tuyaEF00'] = null;
$eq['private'] = null;

/* Config ongoing. Informing Abeille for EQ creation/update */
$msg = array(
Expand Down
2 changes: 1 addition & 1 deletion core/config/Abeille.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Abeille's static config file
*/

define('lastDbVersion', 20240312);
define('lastDbVersion', 20240319);
$in = "/tmp/AbeilleDeamonInput";
$resourcePath = realpath(__DIR__.'/../../resources');
define('wifiLink', '/tmp/zigateWifi'); // For WIFI: Socat output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
"params": "clustId=0006&attrId=0000"
}
},
"tuyaEF00": {
"fromDevice": {
"private": {
"EF00": {
"type": "tuya",
"65": {
"function": "rcvValue",
"info": "0001-01-0021"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@
"isHistorized": 1
}
},
"tuyaEF00": {
"fromDevice": {
"private": {
"EF00": {
"type": "tuya",
"05": {
"function": "rcvValue",
"info": "01-measuredValue"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
"nextLine": "after"
}
},
"tuyaEF00": {
"fromDevice": {
"private": {
"EF00": {
"type": "tuya",
"10": {
"function": "rcvValue",
"info": "01-setpoint"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@
"isVisible": "1"
}
},
"tuyaEF00": {
"fromDevice": {
"private": {
"EF00": {
"type": "tuya",
"02": {
"function": "rcvValue",
"info": "01-setpoint"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@
"nextLine": "after"
}
},
"tuyaEF00": {
"fromDevice": {
"private": {
"EF00": {
"type": "tuya",
"01": {
"function": "rcvValue",
"info": "status1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
"isVisible": 1
}
},
"tuyaEF00": {
"fromDevice": {
"private": {
"EF00": {
"type": "tuya",
"01": {
"function": "rcvValue0Is1",
"info": "01-presence"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@
"isVisible": 0
}
},
"tuyaEF00": {
"fromDevice": {
"private": {
"EF00": {
"type": "tuya",
"02": {
"function": "rcvThermostat-Mode"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
"isVisible": 1
}
},
"tuyaEF00": {
"fromDevice": {
"private": {
"EF00": {
"type": "tuya",
"01": {
"function": "rcvValue",
"info": "0006-01-0000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
"isVisible": 1
}
},
"tuyaEF00": {
"fromDevice": {
"private": {
"EF00": {
"type": "tuya",
"01": {
"function": "rcvValue",
"info": "01-doorTrigger",
Expand All @@ -55,4 +56,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
"isVisible": 1
}
},
"tuyaEF00": {
"fromDevice": {
"private": {
"EF00": {
"type": "tuya",
"01": {
"function": "rcvValue0Is1",
"info": "01-smokeAlarm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@
"nextLine": "after"
}
},
"tuyaEF00": {
"fromDevice": {
"private": {
"EF00": {
"type": "tuya",
"02": {
"function": "rcvThermostat-Mode",
"info": "01-mode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@
"isVisible": 1
}
},
"tuyaEF00": {
"fromDevice": {
"private": {
"EF00": {
"type": "tuya",
"02": {
"function": "rcvValue",
"info": "01-CO2_ppm"
Expand Down
23 changes: 15 additions & 8 deletions core/php/AbeilleParser-Tuya.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function tuyaGetDp($msg) {
// bitmap 0x05 1/2/4 Large end representation for lengths greater than 1 byte

// Receive a datapoint, map it to a specific function an decode it.
// Mapping is defined "per device" directly in its model (tuyaEF00/fromDevice).
// Mapping is defined "per device" directly in its model (private + type="tuya").
function tuyaDecodeDp($addr, $ep, $dp, $mapping) {
$dpId = $dp['id'];
if (!isset($mapping[$dpId])) {
Expand All @@ -86,8 +86,9 @@ function tuyaDecodeDp($addr, $ep, $dp, $mapping) {
}

/* New syntax
"tuyaEF00": {
"fromDevice": {
"private": {
"EF00": {
"type": "tuya",
"01": { "function": "rcvValueDiv", "info": "0006-01-0000", "div": 1 },
"02": { "function": "rcvValue", "info": "0008-01-0000" },
}
Expand Down Expand Up @@ -273,11 +274,14 @@ function tuyaDecodeEF00Cmd($net, $addr, $ep, $cmdId, $msg) {

if (($cmdId == "01") || ($cmdId == "02")) {
// parserLog('debug', 'eq='.json_encode($eq));
if (!isset($eq['tuyaEF00']) || !isset($eq['tuyaEF00']['fromDevice'])) {
// if (!isset($eq['tuyaEF00']) || !isset($eq['tuyaEF00']['fromDevice'])) {
// TODO: EF00 might not be always the cluster in Tuya DP mode
if (!isset($eq['private']) || !isset($eq['private']['EF00'])) {
parserLog2('debug', $addr, " No defined Tuya mapping => ignoring (msg=".$msg.")");
return [];
}
$mapping = $eq['tuyaEF00']['fromDevice'];
// $mapping = $eq['tuyaEF00']['fromDevice'];
$mapping = $eq['private']['EF00'];
// parserLog('debug', ' Tuya mapping='.json_encode($mapping));

$tSqn = substr($msg, 0, 4); // uint16
Expand All @@ -290,8 +294,10 @@ function tuyaDecodeEF00Cmd($net, $addr, $ep, $cmdId, $msg) {
if ($a !== false)
$attributesN[] = $a;
else { // Unknown DP
if (!isset($eq['tuyaEF00']['unknown']) || !isset($eq['tuyaEF00'][$dp['id']]))
$eq['tuyaEF00']['unknown'][$dp['id']] = $dp;
// if (!isset($eq['tuyaEF00']['unknown']) || !isset($eq['tuyaEF00'][$dp['id']]))
// $eq['tuyaEF00']['unknown'][$dp['id']] = $dp;
// TODO: Is that the right converstion to 'private' section ?
$eq['private']['EF00']['unknown'][$dp['id']] = $dp;
}

// Move to next DP
Expand All @@ -303,7 +309,8 @@ function tuyaDecodeEF00Cmd($net, $addr, $ep, $cmdId, $msg) {
$tSeq = substr($msg, 0, 4);
$msg = substr($msg, 4); // Skip tSqn
$dp = tuyaGetDp($msg);
$mapping = $eq['tuyaEF00']['fromDevice'];
// $mapping = $eq['tuyaEF00']['fromDevice'];
$mapping = $eq['private']['EF00'];
$a = tuyaDecodeDp($addr, $ep, $dp, $mapping);
if ($a !== false)
$attributesN[] = $a;
Expand Down
17 changes: 8 additions & 9 deletions core/php/AbeilleParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,21 +390,20 @@ function updateDeviceFromDB($eqId) {
$eq['modelForced'] = isset($eqModel['modelForced']) ? $eqModel['modelForced'] : false;
if (isset($eqModel['modelPath'])) // Forced model variant case
$eq['modelPath'] = $eqModel['modelPath'];

$private = $eqLogic->getConfiguration('ab::private', null);
if ($private !== null) {
$eq['private'] = $private;
if (isset($eqModel['private'])) {
$eq['private'] = $eqModel['private'];
parserLog('debug', " 'private' updated to ".json_encode($eq['private'], JSON_UNESCAPED_SLASHES));
} else if (isset($eq['private']))
} else if ($GLOBALS['eqList'][$net][$addr]['private'])
unset($GLOBALS['eqList'][$net][$addr]['private']);

$fromDevice = $eqLogic->getConfiguration('ab::fromDevice', null); // OBSOLETE soon. Replaced by 'private'
if ($fromDevice !== null) { // OBSOLETE soon. Replaced by 'private'
$eq['fromDevice'] = $fromDevice;
parserLog('debug', " 'fromDevice' updated to ".json_encode($eq['fromDevice']));
} else if (isset($eq['fromDevice']))
unset($GLOBALS['eqList'][$net][$addr]['fromDevice']);
$eq['tuyaEF00'] = $eqLogic->getConfiguration('ab::tuyaEF00', null); // OBSOLETE soon. Replaced by 'private'
parserLog('debug', " 'tuyaEF00' updated to ".json_encode($eq['tuyaEF00'])); // OBSOLETE soon. Replaced by 'private'
// $eq['tuyaEF00'] = $eqLogic->getConfiguration('ab::tuyaEF00', null); // OBSOLETE soon. Replaced by 'private'
// parserLog('debug', " 'tuyaEF00' updated to ".json_encode($eq['tuyaEF00'])); // OBSOLETE soon. Replaced by 'private'
// $eq['xiaomi'] = $eqLogic->getConfiguration('ab::xiaomi', null); // OBSOLETE soon. Replaced by 'private'
// parserLog('debug', " 'xiaomi' updated to ".json_encode($eq['xiaomi'])); // OBSOLETE soon. Replaced by 'private'

Expand Down Expand Up @@ -535,9 +534,9 @@ function signalHandler($signal) {
'modelSource' => '',
'modelForced' => isset($eqModel['modelForced']) ? $eqModel['modelForced'] : false,
'customization' => $eqLogic->getConfiguration('ab::customization', null),
//'private' => // Set if exists in model
//'private' => // Optional: Set if 'private' section exists in model
//'fromDevice' => // Set if exists in model // OBSOLETE soon
'tuyaEF00' => $eqLogic->getConfiguration('ab::tuyaEF00', null), // OBSOLETE soon => replaced by 'private'
// 'tuyaEF00' => $eqLogic->getConfiguration('ab::tuyaEF00', null), // OBSOLETE soon => replaced by 'private'
// 'xiaomi' => $eqLogic->getConfiguration('ab::xiaomi', null), // OBSOLETE soon => replaced by 'private'
// Optional 'notStandard-0400-0000'
);
Expand Down
1 change: 1 addition & 0 deletions docs/fr_FR/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ChangeLog
- Réseau: Affichage table des liens Zigate 1 à l'ouverture.
- SonOff ZbminiL2: Correction 'mac capa' incorrect => 'RxOnWhenIdle'.
- Interne: Mises-à-jour 'check_json' + 'update_json' pour changement 'tuyaEF00/fromDevice' => 'private/EF00'.
- Modèles d'équipement: Suppression 'tuyaEF00/fromDevice' => remplacé par 'private/EF00'.

240308-BETA-1
-------------
Expand Down
30 changes: 27 additions & 3 deletions plugin_info/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ function updateConfigDB() {
* - Cmds DB: 'onGroupBroadcast'/'offGroupBroadcast' replaced by 'cmd-0006'
* - Cmds DB: 'ab::trigOut' syntax updated to associative array
*/
if (intval($dbVersion) < 20240312) {
if (intval($dbVersion) < 20240319) {
// 'eqLogic' + 'cmd' DB updates
$eqLogics = eqLogic::byType('Abeille');
foreach ($eqLogics as $eqLogic) {
Expand Down Expand Up @@ -953,23 +953,47 @@ function updateConfigDB() {
// ab::xiaomi replaced by ab::eqModel['private'] + type=xiaomi
$xiaomi = $eqLogic->getConfiguration('ab::xiaomi', null);
if ($xiaomi !== null) {
$eqMode['private'] = [];
$eqModel['private'] = [];
foreach ($xiaomi['fromDevice'] as $pKey => $pVal) {
$pVal['type'] = "xiaomi";
$eqModel['private'][$pKey] = $pVal;
}
$saveEqModel = true;
$eqLogic->setConfiguration('ab::xiaomi', null);
log::add('Abeille', 'debug', ' '.$eqHName.": 'ab::xiaomi' replaced by 'private' entries");
}
// eqLogic DB: 'ab::tuyaEF00' => 'ab::eqModel['private']['EF00']'
/* Reminder
Old syntax
"tuyaEF00": {
"fromDevice": {
"01": { "function": "rcvValueDiv", "info": "0006-01-0000", "div": 1 }
}
}
New syntax
"private": {
"EF00": {
"type": "tuya",
"01": { "function": "rcvValueDiv", "info": "0006-01-0000", "div": 1 }
}
}
*/
$tuyaEF00 = $eqLogic->getConfiguration('ab::tuyaEF00', 'nada');
if ($tuyaEF00 != 'nada') {
$eqModel['private']['EF00'] = $tuyaEF00['fromDevice'];
$eqModel['private']['EF00']['type'] = "tuya";
$saveEqModel = true;
$eqLogic->setConfiguration('ab::tuyaEF00', null);
log::add('Abeille', 'debug', ' '.$eqHName.": 'ab::tuyaEF00' moved to 'ab::eqModel['private']['EF00']");
}
// ab::signature content moved into 'ab::zigbee'
$sig = $eqLogic->getConfiguration('ab::signature', null);
if ($sig !== null) {
$zigbee['modelId'] = isset($sig['modelId']) ? $sig['modelId'] : '';
$zigbee['manufId'] = isset($sig['manufId']) ? $sig['manufId'] : '';
$saveEqZigbee = true;
$eqLogic->setConfiguration('ab::signature', null);
log::add('Abeille', 'debug', ' '.$eqHName.": 'ab::signature' content moved in 'ab::zigbee'");
$saveEqZigbee = true;
}
// eqLogic DB: 'groupEPx' => 'ab::eqModel['variables']'
for ($g = 1; $g <= 8; $g++) {
Expand Down

0 comments on commit a4a03e8

Please sign in to comment.