Skip to content

Commit

Permalink
Added support for models with variant + THS317-ET updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed Jan 2, 2024
1 parent 0f707c2 commit 67facb4
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 97 deletions.
139 changes: 66 additions & 73 deletions core/ajax/AbeilleModelChange.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@
throw new Exception('401 Unauthorized');
}

define('devicesDir', __DIR__ . '/../config/devices/'); // Abeille's supported devices
define('devicesLocalDir', __DIR__ . '/../config/devices_local/'); // Unsupported/user devices
require_once __DIR__ . '/../php/AbeilleModels.php'; // Libray to deal with models

// Perform the requested action
$action = $_POST['action'];

if (function_exists($action)) {
$action();
} else {
Expand All @@ -53,12 +51,11 @@
* Returns in JSON the list of existing models (known by Abeille).
* Includes built-in models and local models (if any).
*/
function getModelChoiceList()
{
function getModelChoiceList() {
// We allow the choice of local models and official models
// Associative array modelID => model data
$list = getDevicesList("local");
$list = array_merge($list, getDevicesList("Abeille"));
$list = getModelsList("local");
$list = array_merge($list, getModelsList("Abeille"));

// Retrieve the current model of the equipment (if it has one)
$eqId = (int) $_POST['eqId'];
Expand Down Expand Up @@ -86,8 +83,7 @@ function getModelChoiceList()
* forces it to 'manual' so that the model is no longer modified automatically
* from zigbee signature at equipment announcement.
*/
function setModelToDevice()
{
function setModelToDevice() {
// Retrieving equipment
$eqId = (int) $_POST['eqId'];
$eqLogic = eqLogic::byId($eqId);
Expand Down Expand Up @@ -156,8 +152,7 @@ function setModelToDevice()
* Restores normal (automatic) model selection for equipment.
* (= the model can be detected again by Abeille at the next announcement of the equipment)
*/
function disableManualModelForDevice()
{
function disableManualModelForDevice() {
// Retrieving equipment
$eqId = (int) $_POST['eqId'];
$eqLogic = eqLogic::byId($eqId);
Expand All @@ -182,70 +177,68 @@ function disableManualModelForDevice()
}



/** Code from .tools\gen_devices_list.php */
// TODO refactor to avoid code duplication

/* Get list of supported devices ($from="Abeille"), or user/custom ones ($from="local")
Returns: Associative array; $devicesList[$identifier] = array(), or false if error */
function getDevicesList($from = "Abeille")
{
$devicesList = [];

if ($from == "Abeille")
$rootDir = devicesDir;
else if ($from == "local")
$rootDir = devicesLocalDir;
else {
echo ("ERROR: Emplacement JSON '" . $from . "' invalide\n");
return false;
}

$dh = opendir($rootDir);
if ($dh === false) {
echo ('ERROR: getDevicesList(): opendir(' . $rootDir . ')\n');
return false;
}
while (($dirEntry = readdir($dh)) !== false) {
/* Ignoring some entries */
if (in_array($dirEntry, array(".", "..")))
continue;
$fullPath = $rootDir . $dirEntry;
if (!is_dir($fullPath))
continue;

$fullPath = $rootDir . $dirEntry . '/' . $dirEntry . ".json";
if (!file_exists($fullPath))
continue; // No local JSON model. Maybe just an auto-discovery ?
$dev = array(
'modelName' => $dirEntry,
'modelSource' => $from
);

/* Check if config is compliant with other device identification */
$content = file_get_contents($fullPath);
$devConf = json_decode($content, true);
$devConf = $devConf[$dirEntry]; // Removing top key
$dev['manufacturer'] = isset($devConf['manufacturer']) ? $devConf['manufacturer'] : '';
$dev['model'] = isset($devConf['model']) ? $devConf['model'] : '';
$dev['type'] = $devConf['type'];
$dev['icon'] = $devConf['configuration']['icon'];
$devicesList[$dirEntry] = $dev;

if (isset($devConf['alternateIds'])) {
$idList = explode(',', $devConf['alternateIds']);
foreach ($idList as $id) {
echo ("getDevicesList(): Alternate ID '" . $id . "' for '" . $dirEntry . "'\n");
$dev = array(
'modelName' => $dirEntry,
'modelSource' => $from
);
$devicesList[$id] = $dev;
}
}
}
closedir($dh);

return $devicesList;
}
// function getModelsList($from = "Abeille") {
// $devicesList = [];

// if ($from == "Abeille")
// $rootDir = modelsDir;
// else if ($from == "local")
// $rootDir = modelsLocalDir;
// else {
// echo ("ERROR: Emplacement JSON '" . $from . "' invalide\n");
// return false;
// }

// $dh = opendir($rootDir);
// if ($dh === false) {
// echo ('ERROR: getModelsList(): opendir(' . $rootDir . ')\n');
// return false;
// }
// while (($dirEntry = readdir($dh)) !== false) {
// /* Ignoring some entries */
// if (in_array($dirEntry, array(".", "..")))
// continue;
// $fullPath = $rootDir . $dirEntry;
// if (!is_dir($fullPath))
// continue;

// $fullPath = $rootDir . $dirEntry . '/' . $dirEntry . ".json";
// if (!file_exists($fullPath))
// continue; // No local JSON model. Maybe just an auto-discovery ?
// $dev = array(
// 'modelName' => $dirEntry,
// 'modelSource' => $from
// );

// /* Check if config is compliant with other device identification */
// $content = file_get_contents($fullPath);
// $devConf = json_decode($content, true);
// $devConf = $devConf[$dirEntry]; // Removing top key
// $dev['manufacturer'] = isset($devConf['manufacturer']) ? $devConf['manufacturer'] : '';
// $dev['model'] = isset($devConf['model']) ? $devConf['model'] : '';
// $dev['type'] = $devConf['type'];
// $dev['icon'] = $devConf['configuration']['icon'];
// $devicesList[$dirEntry] = $dev;

// if (isset($devConf['alternateIds'])) {
// $idList = explode(',', $devConf['alternateIds']);
// foreach ($idList as $id) {
// echo ("getModelsList(): Alternate ID '" . $id . "' for '" . $dirEntry . "'\n");
// $dev = array(
// 'modelName' => $dirEntry,
// 'modelSource' => $from
// );
// $devicesList[$id] = $dev;
// }
// }
// }
// closedir($dh);

// return $devicesList;
// }
1 change: 1 addition & 0 deletions core/class/AbeilleTools.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static function deamonlogFilter($loglevel = 'NONE', $pluginName, $loggerN
'modelName' => model file
'modelSource' => model file location
) */
// Note: OBSOLETE !! Use getModelsList() from AbeilleModels.php library
public static function getDevicesList($from = "Abeille") {
$devicesList = [];

Expand Down
2 changes: 2 additions & 0 deletions core/config/Abeille.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
$resourcePath = realpath(__DIR__.'/../../resources');
define('wifiLink', '/tmp/zigateWifi'); // For WIFI: Socat output
define('otaDir', 'tmp/fw_ota'); // OTA FW location relative to Abeille's root
define('modelsDir', __DIR__ . '/devices/'); // Abeille's supported devices
define('modelsLocalDir', __DIR__ . '/devices_local/'); // Unsupported/user devices

/* Inter-daemons queues:
array['<queueName>'] = array("id" => queueId, "max" => maxMsgSize) */
Expand Down
17 changes: 12 additions & 5 deletions core/config/devices/LISEZMOI.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
*** Répertoire "core/config/devices" pour modèles supportés
***

Ce répertoire contient les modèles d'équipement supportés par Abeille.

ATTENTION !! Toute modification de ce répertoire sera écrasée lors des mises-à-jour du plugin.

Pendant la phase d'inclusion, Abeille va chercher les modèles dans l'ordre suivant
- dans le répertoire 'devices_local' pour les équipements locaux/custom ou en cours de dev

Ce répertoire contient les modèles d'équipement supportés par Abeille.

Pendant la phase d'inclusion, Abeille va tenter d'identifier le modèle correspondant à la signature Zigbee, dans l'ordre suivant
- dans le répertoire 'devices_local' pour les équipements locaux/custom ou en cours de developpement
- puis dans ce répertoire officiel 'devices'
- et enfin si toujours pas trouvé, le modèle 'defaultUnknown.json' sera utilisé


Ce répertoire doit suivre la structure
<identificateur>/<identificateur>.json

ATTENTION !! Voir 'identificateur' plus bas dans le format du fichier.

Notes
- Plusieurs signatures Zigbee peuvent utiliser le même modèle (cas d'un équipement vendu sous differentes marques)
- Pour de très rares cas, d'autres modèles (à forcer à la main apres appairage) peuvent être utilisés.
Par ex l'équipement a toujours la meme signature mais une incompatibilité dans l'evolution de son firmware rendre
le modèle par défaut inutilisable (ex: Cas sonde TSH317 Owon: EP=03 pour les anciens, 01 pour les nouveaux).


Format de fichier
=================

Expand Down
55 changes: 55 additions & 0 deletions core/config/devices/THS317-ET_OWON/THS317-ET_OWON-old.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"THS317-ET_OWON-old": {
"comment": "Special model for old devices with EP 03. To be used as a 'forced model'",
"manufacturer": "Owon",
"zbManufacturer": "OWON",
"model": "THS317-ET",
"type": "Owon multi-sensor 1st gen",
"genericType": "Environment",
"timeout": "60",
"category": {
"heating": "1"
},
"comment": "WARNING: Recent devices are using EP01 while old one are on EP03 (see #2379)",
"configuration": {
"icon": "Owon-THS317-ET",
"mainEP": "03",
"batteryType": "2x1.5V AAA"
},
"commands": {
"Battery-Percent": {
"use": "inf_zbAttr-0001-BatteryPercent"
},
"Identify": {
"use": "act_zbCmdC-Identify",
"nextLine": "after"
},
"Temperature": {
"use": "inf_zbAttr-0402-MeasuredValue",
"isVisible": "1"
},
"Bind 0402-ToZigate": {
"use": "act_zbBindToZigate",
"params": "clustId=0402",
"execAtCreation": "yes"
},
"Bind 0001-ToZigate": {
"use": "act_zbBindToZigate",
"params": "clustId=0001",
"execAtCreation": "yes"
},
"SetReporting 0402-0000": {
"use": "act_zbConfigureReporting2",
"params": "clustId=0402&attrType=29&attrId=0000&minInterval=300&maxInterval=600",
"execAtCreation": "yes",
"comment": "Reporting every 5 to 10mins"
},
"SetReporting 0001-0021": {
"use": "act_zbConfigureReporting2",
"params": "clustId=0001&attrId=0021&attrType=20&minInterval=1800&maxInterval=3300",
"execAtCreation": "yes",
"comment": "Reporting every 30 to 55mins"
}
}
}
}
Loading

0 comments on commit 67facb4

Please sign in to comment.