1
0

ajout de la notification multi-utilisateur

This commit is contained in:
Daniel Tartavel 2022-09-05 13:46:41 +02:00
parent 7874ea1b7f
commit 0c9f8f8c3f
3 changed files with 59 additions and 33 deletions

14
config/config.php Normal file
View File

@ -0,0 +1,14 @@
<?php
$notificationLevel = ALERT;
$logLevel = DEBUG | INFO | NOTICE | WARNING | ERROR | ALERT;
// le premier utilisateur est l'utilisateur par défaut
$defaultUser = array(
"rdc" => "Daniel",
"garage" => "Daniel",
"entree" => "Daniel",
"etage" => "Maryclaire"
);
?>

View File

@ -1,5 +0,0 @@
<?php
?>

View File

@ -9,12 +9,30 @@ $apiServerIsActive = true;
require "constants.php";
if ($testMode)
{
$logLevel = ALL; // INFO | NOTICE | WARNING | ERROR | ALERT; //ALL;
$mqttServerIp = "192.168.1.253"; // IP address of mqttserver in test mode
$dataPath = "./";
$logFile = "./moha.log"; // Path of log file
$configDir = "./config"; // default config dir (production value is /etc/moha/)
$httpServerIp = "192.168.1.253";
}else
{
//$logLevel = DEBUG | INFO | NOTICE | WARNING | ERROR | ALERT;
$mqttServerIp = "127.0.0.1"; // IP address of mqttserver in production mode
$dataPath = "/usr/share/moha/";
$logFile = "/var/log/moha.log"; // Path of log file
$configDir = "/etc/moha"; // default config dir (production value is /etc/moha/)
$httpServerIp = "127.0.0.1";
}
require $configDir . "/config.php";
$listProperties = array("powerSource" => "batterie");
$listPropertiesKeys = array("expose");
//global variables
$notificationLevel = ALERT;
$topics = array(); // list of topics
$mids = array(); // list of message IDs
$devices = array(); // array of device objetcs
@ -41,23 +59,6 @@ $flagHooks = false;
$devicesRequest = false; // set to true when publishing device request to zigbee2mqtt
$presence = array(); // name and status of presence
if ($testMode)
{
$logLevel = ALL; // INFO | NOTICE | WARNING | ERROR | ALERT; //ALL;
$mqttServerIp = "192.168.1.253"; // IP address of mqttserver in test mode
$dataPath = "./";
$logFile = "./moha.log"; // Path of log file
$configDir = "./config"; // default config dir (production value is /etc/moha/)
$httpServerIp = "192.168.1.253";
}else
{
$logLevel = DEBUG | INFO | NOTICE | WARNING | ERROR | ALERT;
$mqttServerIp = "127.0.0.1"; // IP address of mqttserver in production mode
$dataPath = "/usr/share/moha/";
$logFile = "/var/log/moha.log"; // Path of log file
$configDir = "/etc/moha"; // default config dir (production value is /etc/moha/)
$httpServerIp = "127.0.0.1";
}
@ -72,12 +73,30 @@ textdomain("moha");
function notify($message, $device)
{
global $notificationMethods;
global $notificationMethods, $defaultUser;
$result = false;
//TODO destinataire selon fichier de config
$destinataire = array("daniel");
$destinataire = array();
if (empty($device))
{
$destinataire[] = reset($defaultUser); //default user if no device
}else
{
//TODO destinataire selon fichier de config
if (empty($device->users))
{
foreach($defaultUser as $topic => $nom)
{
if ( str_contains($device->friendlyName, $topic))
{
$destinataire[] = $nom;
}
}
}else
{
$destinataire = $device->users;
}
}
var_dump ($destinataire);
foreach($notificationMethods as $value)
{
foreach($destinataire as $dest)
@ -298,7 +317,7 @@ if (file_exists($dataPath . "devices.db"))
// Program start
logger(DEBUG, _("Program start"), __FILE__ . ":" . __LINE__, false);
logger(DEBUG, _("Program start"), __FILE__ . ":" . __LINE__);
$client = new Mosquitto\Client();
@ -307,7 +326,7 @@ try
connect2mqttServer();
}catch ( Mosquitto\Exception $err)
{
logger(ALERT, sprintf(_("Error connecting to mosquitto server, retrying in 10 seconds:"), $err), __FILE__ . ":" . __LINE__, false);
logger(ALERT, sprintf(_("Error connecting to mosquitto server, retrying in 10 seconds:"), $err), __FILE__ . ":" . __LINE__);
sleep (10);
exit(1);
}
@ -330,10 +349,8 @@ foreach($topics as $name => &$topic)
$topic->status = false;
}
// starting main loop
logger(INFO, _("Starting loop"), __FILE__ . ":" . __LINE__, false);
logger(INFO, _("Starting loop"), __FILE__ . ":" . __LINE__);
$oneshot = false;
logger(ALERT, _("Moha started"), __FILE__ . ":" . __LINE__);