diff --git a/config/config.php b/config/config.php new file mode 100644 index 0000000..a7262f1 --- /dev/null +++ b/config/config.php @@ -0,0 +1,14 @@ + "Daniel", +"garage" => "Daniel", +"entree" => "Daniel", +"etage" => "Maryclaire" +); + +?> diff --git a/config/logger.php b/config/logger.php deleted file mode 100644 index 0b2df93..0000000 --- a/config/logger.php +++ /dev/null @@ -1,5 +0,0 @@ - - diff --git a/moha.php b/moha.php index 3bda603..b6feb6c 100644 --- a/moha.php +++ b/moha.php @@ -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__);