1
0

debuggage

This commit is contained in:
Daniel Tartavel 2022-06-20 10:34:55 +02:00
parent da3f4ab51f
commit 58812c442f
13 changed files with 130 additions and 87 deletions

View File

@ -330,9 +330,11 @@ function apiSet($argList)
}else }else
{ {
$response = "setting property " . $argList["property"] . " of " . $argList["fn"] . " to value: " . $argList["value"]; $response = "setting property " . $argList["property"] . " of " . $argList["fn"] . " to value: " . $argList["value"];
$payload = array($argList["property"] => $argList["value"]); $device = $indexFriendlyNames[$argList["fn"]];
$device->payload = array($argList["property"] => $argList["value"]);
$device->set($argList["property"], IDLE);
publish($argList["topic"] . "/" . $argList["fn"], $payload, "set"); publish($argList["topic"] . "/" . $argList["fn"], $payload, "set");
//removeEvent($indexFriendlyName($argList["fn"]), $argList["property"], "OFF"); //removeEvent($indexFriendlyNames($argList["fn"]), $argList["property"], "OFF");
} }
return $response; return $response;
} }

View File

@ -39,9 +39,10 @@ class device
$this->availability = array("value" => null, "functions" => array()); $this->availability = array("value" => null, "functions" => array());
} }
public function set() //, $event = null) public function set($property, $method = IDLE) //, $event = null)
{ {
publish($this->topic . "/" . $this->friendlyName, $this->payload, "set"); //, $event); publish($this->topic . "/" . $this->friendlyName, $this->payload, "set");//, $event);
$this->properties[$property]["method"] = $method;
} }
public function get() public function get()

View File

@ -286,6 +286,8 @@ function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key)
logger(DEBUG, sprintf(_("old value was %s, new is %s" ), bool2string($property["value"]), bool2string($value)), __FILE__ . ":" . __LINE__); logger(DEBUG, sprintf(_("old value was %s, new is %s" ), bool2string($property["value"]), bool2string($value)), __FILE__ . ":" . __LINE__);
} }
$property["value"] = $value; $property["value"] = $value;
$r = $parentDevice->friendlyName;
logger(DEBUG, _("Changed value of ") . $r . "=> " . bool2string($value) , __FILE__ . ":" . __LINE__);
if (!empty($property["functions"])) if (!empty($property["functions"]))
{ {
logger(DEBUG,_("executing notifications functions"), __FILE__ . ":" . __LINE__); logger(DEBUG,_("executing notifications functions"), __FILE__ . ":" . __LINE__);

View File

@ -121,7 +121,7 @@ class radiateurs extends hook
$msg = array("current_heating_setpoint" => (!empty($this->prevTemp[$device->ieeeAddress])?$this->prevTemp[$device->ieeeAddress]:19)); $msg = array("current_heating_setpoint" => (!empty($this->prevTemp[$device->ieeeAddress])?$this->prevTemp[$device->ieeeAddress]:19));
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName), __FILE__ . ":" . __LINE__); logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName), __FILE__ . ":" . __LINE__);
$device->payload = $msg; $device->payload = $msg;
$device->set(); $device->set("current_heating_setpoint", AUTO);
$device->properties["current_heating_setpoint"]["method"] = AUTO; $device->properties["current_heating_setpoint"]["method"] = AUTO;
} }
} }

View File

@ -27,7 +27,9 @@ class rdc_chambre_eclairage extends hook
$lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->properties["illuminance_lux"]; $lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->properties["illuminance_lux"];
$targetAmbiance = $indexDevices[RDC_CHAMBRE_AMBIANCE]; $targetAmbiance = $indexDevices[RDC_CHAMBRE_AMBIANCE];
$targetEclairage = $indexDevices[RDC_CHAMBRE_ECLAIRAGE]; $targetEclairage = $indexDevices[RDC_CHAMBRE_ECLAIRAGE];
if ($property == "occupancy" and $value == ON) if ($property == "occupancy")
{
if ($value == ON and $lux < 150)
{ {
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
if ($targetAmbiance->properties["state"]["method"] == MANUAL) if ($targetAmbiance->properties["state"]["method"] == MANUAL)
@ -41,6 +43,7 @@ class rdc_chambre_eclairage extends hook
} }
$this->send($targetAmbiance, "state", "ON", $delayState, $method); $this->send($targetAmbiance, "state", "ON", $delayState, $method);
}
}elseif ($property == "contact") }elseif ($property == "contact")
{ {
logger(DEBUG, _("CASE: contact"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("CASE: contact"), __FILE__ . ":" . __LINE__);
@ -51,14 +54,22 @@ class rdc_chambre_eclairage extends hook
{ {
$this->send($targetEclairage, "state_l1", "OFF", false, IDLE); $this->send($targetEclairage, "state_l1", "OFF", false, IDLE);
} }
}elseif ($property == "state" and $value == "OFF") }elseif ($property == "state")
{
if ($value == "OFF")
{ {
logger(DEBUG, _("CASE: state => value = 'OFF'"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("CASE: state => value = 'OFF'"), __FILE__ . ":" . __LINE__);
$targetAmbiance->properties[$property]["method"] = IDLE; $targetAmbiance->properties[$property]["method"] = IDLE;
}elseif ($property == "state_l1" and $value == "OFF") removeEvent($targetAmbiance, $property, "OFF", IDLE);
}
}elseif ($property == "state_l1")
{
if ($value == "OFF")
{ {
logger(DEBUG, _("CASE: state_l1 => value = 'OFF'"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("CASE: state_l1 => value = 'OFF'"), __FILE__ . ":" . __LINE__);
$targetEclairage->properties[$property]["method"] = IDLE; //$targetEclairage->properties[$property]["method"] = IDLE;
removeEvent($targetAmbiance, $property, "OFF", IDLE);
}
}elseif ($property == "action") }elseif ($property == "action")
{ {
logger(DEBUG, _("CASE: action"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("CASE: action"), __FILE__ . ":" . __LINE__);
@ -70,7 +81,7 @@ class rdc_chambre_eclairage extends hook
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__); logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
} }
private function send(&$deviceObject, $property, $state, $delayState = false, $method = MANUAL) private function send(&$deviceObject, $property, $state, $delayState = false, $method = AUTO)
{ {
global $indexDevices; global $indexDevices;
$msg = array($property => $state); $msg = array($property => $state);
@ -78,15 +89,14 @@ class rdc_chambre_eclairage extends hook
//{ //{
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__); logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg; $deviceObject->payload = $msg;
$deviceObject->set(); $deviceObject->set($property, $method);
$deviceObject->properties[$property]["method"] = $method;
///}else ///}else
/*{ /*{
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__); logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
}*/ }*/
//echo 'delaystate = ' . var_dump($delayState); //echo 'delaystate = ' . var_dump($delayState);
if ($delayState !== false) setDelay($deviceObject, $this->delay, $this->timeUnit, "state", $delayState, true); if ($delayState !== false) setDelay($deviceObject, $this->delay, $this->timeUnit, "state", $delayState, true, IDLE);
} }
} }

View File

@ -11,7 +11,10 @@ class rdc_salon_eclairage extends hook
RDC_ENTREE_PORTE => "contact", RDC_ENTREE_PORTE => "contact",
RDC_SALON_LUMINOSITE => "illuminance_lux" RDC_SALON_LUMINOSITE => "illuminance_lux"
); );
protected $actionneurs = array(
array(RDC_SALON_MVMT, "occupancy", 1),
array(RDC_SALON_MVMT2, "occupancy", 1)
);
public $delay = 3; // amount of time in $timeunit public $delay = 3; // amount of time in $timeunit
public $timeUnit = "minute"; // unit of time for delay, second, minute, hour, day, week, month, year public $timeUnit = "minute"; // unit of time for delay, second, minute, hour, day, week, month, year
public $luminance_min = 50; public $luminance_min = 50;
@ -58,11 +61,8 @@ class rdc_salon_eclairage extends hook
logger(INFO, _("CASE: Contact Door"), __FILE__ . ":" . __LINE__); logger(INFO, _("CASE: Contact Door"), __FILE__ . ":" . __LINE__);
if ($value == false and $illuminance <= $this->luminance_min) if ($value == false and $illuminance <= $this->luminance_min)
{ {
logger(INFO, _("Door is open and illumance < min"), __FILE__ . ":" . __LINE__); logger(INFO, _("Door is open and illumance < min and method =>") . $deviceTarget->properties["state"]["method"], __FILE__ . ":" . __LINE__);
if ($deviceTarget->properties["state"]["method"] !== MANUAL) if ($deviceTarget->properties["state"]["method"] == IDLE)
{
$this->send($deviceTarget, "ON", false);
}else
{ {
$this->send($deviceTarget, "ON", "OFF", AUTO); $this->send($deviceTarget, "ON", "OFF", AUTO);
} }
@ -89,7 +89,7 @@ class rdc_salon_eclairage extends hook
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $param, bool2string($value)), __FILE__ . ":" . __LINE__); logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $param, bool2string($value)), __FILE__ . ":" . __LINE__);
} }
private function send(&$deviceTarget, $state, $delayState = false, $method = MANUAL) private function send(&$deviceTarget, $state, $delayState = false, $method = AUTO)
{ {
global $indexDevices; global $indexDevices;
@ -98,8 +98,8 @@ class rdc_salon_eclairage extends hook
//{ //{
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__); logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__);
$deviceTarget->payload = $msg; $deviceTarget->payload = $msg;
$deviceTarget->set(); $deviceTarget->set("state", "method");
$deviceTarget->properties["state"]["method"] = $method; //$deviceTarget->properties["state"]["method"] = $method;
/*}else /*}else
{ {
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__); logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__);

View File

@ -17,12 +17,16 @@ class rdc_sdb_eclairage extends hook
// devicelist[$ieeAddress][0] => property to watch // devicelist[$ieeAddress][0] => property to watch
// devicelist[$ieeAddress][1] => initialized = true // devicelist[$ieeAddress][1] => initialized = true
protected $devicelist = array( protected $devicelist = array(
//RDC_SDB_DOUCHE_MVMT => "occupancy", RDC_SDB_DOUCHE_MVMT => "occupancy",
RDC_SDB_PLAFOND_MVMT => "occupancy", RDC_SDB_PLAFOND_MVMT => "occupancy",
RDC_SDB_MVMT => "occupancy", RDC_SDB_MVMT => "occupancy",
RDC_SDB_WC_ECLAIRAGE => "state_l1" RDC_SDB_WC_ECLAIRAGE => "state_l1"
); );
protected $actionneurs = array(
array(RDC_SDB_DOUCHE_MVMT, "occupancy", 1),
array(RDC_SDB_PLAFOND_MVMT, "occupancy", 1),
array(RDC_SDB_MVMT, "occupancy", 1)
);
// callback fonction. Is called with these 3 parameters // callback fonction. Is called with these 3 parameters
public function callBack(&$device, $property, $value) public function callBack(&$device, $property, $value)
{ {
@ -36,42 +40,40 @@ class rdc_sdb_eclairage extends hook
{ {
case "occupancy": case "occupancy":
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
if ($value == ON ) if ($value == ON)
{ {
$this->send("ON"); if($deviceTarget->properties["state_l1"]["method"] == IDLE)
$deviceTarget->properties["state_l1"]["method"] = AUTO;
}else
{ {
//$delay = $this->delay;
//setDelay($deviceTarget, $delay, $this->timeUnit, "state_l1", "OFF", true, IDLE);
if ($deviceTarget->properties["state_l1"]["method"] != AUTO)
{
$delay = $this->delayManual;
$deviceTarget->properties["state_l1"]["method"] = MANUAL;
}else
{
$delay = $this->delay;
$deviceTarget->properties["state_l1"]["method"] = MANUAL;
}
setDelay($deviceTarget, $delay, $this->timeUnit, "state_l1", "OFF", true, IDLE);
}
logger(DEBUG, _("lighting with method auto"), __FILE__ . ":" . __LINE__);
//$deviceTarget->properties["state_l1"]["method"] = AUTO;
$this->send("ON", AUTO);
}
}elseif (testActionneurs($this->actionneurs))
{
logger(DEBUG, _("Actionneurs are all false"), __FILE__ . ":" . __LINE__);
setDelay($deviceTarget, $this->delay, $this->timeUnit, "state_l1", "OFF", true, IDLE);
}
break; break;
case "state_l1": case "state_l1":
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
/*if ($value == "ON") if ($value == "ON")
{ {
if ($deviceTarget->properties["state_l1"]["method"] == IDLE)
}else*/
if ($value == "OFF")
{ {
removeEvent($deviceTarget, "state_l1", "OFF"); logger(DEBUG, _("State_l1 is IDLE"), __FILE__ . ":" . __LINE__);
$deviceTarget->properties["state_l1"]["method"] = MANUAL;
setDelay($deviceTarget, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true, IDLE);
}
}elseif ($value == "OFF")
{
removeEvent($deviceTarget, "state_l1", "OFF", IDLE);
$deviceTarget->properties["state_l1"]["method"] = IDLE; $deviceTarget->properties["state_l1"]["method"] = IDLE;
logger(DEBUG, _("State_l1 is false light is off and method is ") . $deviceTarget->properties["state_l1"]["method"], __FILE__ . ":" . __LINE__);
} }
break; break;
} }
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, ($value == 0 ? "OFF" : "ON")), __FILE__ . ":" . __LINE__); logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
}else }else
{ {
logger (ERROR, RDC_SDB_WC_ECLAIRAGE . _(" does not exists"), __FILE__ . ":" . __LINE__); logger (ERROR, RDC_SDB_WC_ECLAIRAGE . _(" does not exists"), __FILE__ . ":" . __LINE__);
@ -79,14 +81,14 @@ class rdc_sdb_eclairage extends hook
} }
private function send($state) private function send($state, $method)
{ {
global $indexDevices; global $indexDevices;
$msg = array("state_l1" => $state); $msg = array("state_l1" => $state);
$device = &$indexDevices[RDC_SDB_WC_ECLAIRAGE]; $device = &$indexDevices[RDC_SDB_WC_ECLAIRAGE];
logger(INFO, sprintf(_("publishing message: %s to %s"), $state, $device->friendlyName), __FILE__ . ":" . __LINE__); logger(INFO, sprintf(_("publishing message: %s to %s"), $state, $device->friendlyName), __FILE__ . ":" . __LINE__);
$device->payload = $msg; $device->payload = $msg;
$device->set(null); $device->set("state_l1", $method);
} }
} }
$hooks["rdc_sdb_eclairage"] = new rdc_sdb_eclairage(); $hooks["rdc_sdb_eclairage"] = new rdc_sdb_eclairage();

View File

@ -164,7 +164,7 @@ class rdc_store extends hook
}elseif ($rafale != 0) }elseif ($rafale != 0)
{ {
//calcul du maxlevel par rapport a la vitesse des rafales //calcul du maxlevel par rapport a la vitesse des rafales
$r = round(($rafale-30)/4, 0, PHP_ROUND_HALF_UP)*10; $r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10;
if ($r < 0) $r = 0; if ($r < 0) $r = 0;
if ($motorReversal) if ($motorReversal)
{ {
@ -191,17 +191,17 @@ class rdc_store extends hook
logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__); logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
if ($this->storeLevel > $this->maxLevel) if ($this->storeLevel > $this->maxLevel)
{ {
$this->set($this->maxLevel); $this->setTo($this->maxLevel, AUTO);
}elseif ($store2level !== false) //$store2level = false then no change on store position }elseif ($store2level !== false) //$store2level = false then no change on store position
{ {
if ( $store2level > $this->maxLevel ) if ( $store2level > $this->maxLevel )
{ {
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__); logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
$this->set($this->maxLevel); $this->setTo($this->maxLevel, AUTO);
}else }else
{ {
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__); logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
$this->set($store2level); $this->setTo($store2level, AUTO);
} }
} }
}else }else
@ -211,13 +211,13 @@ class rdc_store extends hook
} }
private function set ($level) private function setTo($level, $method)
{ {
logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__); logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__);
if ($level <= 100) if ($level <= 100)
{ {
logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__); logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__);
$this->send(100 - $level); $this->send(100 - $level, $method);
}//else }//else
/*{ /*{
logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__); logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__);
@ -230,7 +230,7 @@ class rdc_store extends hook
if ($this->storeLevel > 0) if ($this->storeLevel > 0)
{ {
logger(DEBUG, "Close store :" . $reason, __FILE__ . ":" . __LINE__); logger(DEBUG, "Close store :" . $reason, __FILE__ . ":" . __LINE__);
$this->send(100); $this->send(100, IDLE);
} }
} }
@ -241,7 +241,7 @@ class rdc_store extends hook
$msg = array("position" => $level); $msg = array("position" => $level);
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__); logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg; $deviceObject->payload = $msg;
$deviceObject->set(AUTO); $deviceObject->set("position", $method);
} }
} }

View File

@ -164,7 +164,7 @@ class rdc_store extends hook
}elseif ($rafale != 0) }elseif ($rafale != 0)
{ {
//calcul du maxlevel par rapport a la vitesse des rafales //calcul du maxlevel par rapport a la vitesse des rafales
$r = round(($rafale-30)/4, 0, PHP_ROUND_HALF_UP)*10; $r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10;
if ($r < 0) $r = 0; if ($r < 0) $r = 0;
if ($motorReversal) if ($motorReversal)
{ {
@ -191,17 +191,17 @@ class rdc_store extends hook
logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__); logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
if ($this->storeLevel > $this->maxLevel) if ($this->storeLevel > $this->maxLevel)
{ {
$this->set($this->maxLevel); $this->setTo($this->maxLevel);
}elseif ($store2level !== false) }elseif ($store2level !== false) //$store2level = false then no change on store position
{ {
if ( $store2level > $this->maxLevel ) if ( $store2level > $this->maxLevel )
{ {
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__); logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
$this->set($this->maxLevel); $this->setTo($this->maxLevel);
}else }else
{ {
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__); logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
$this->set($store2level); $this->setTo($store2level);
} }
} }
}else }else
@ -211,13 +211,13 @@ class rdc_store extends hook
} }
private function set ($level) private function setTo($level)
{ {
logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__); logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__);
if ($level <= 100) if ($level <= 100)
{ {
logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__); logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__);
$this->send(100 - $level); $this->send(100 - $level, AUTO);
}//else }//else
/*{ /*{
logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__); logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__);
@ -230,7 +230,7 @@ class rdc_store extends hook
if ($this->storeLevel > 0) if ($this->storeLevel > 0)
{ {
logger(DEBUG, "Close store :" . $reason, __FILE__ . ":" . __LINE__); logger(DEBUG, "Close store :" . $reason, __FILE__ . ":" . __LINE__);
$this->send(100); $this->send(100, IDLE);
} }
} }
@ -241,7 +241,7 @@ class rdc_store extends hook
$msg = array("position" => $level); $msg = array("position" => $level);
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__); logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg; $deviceObject->payload = $msg;
$deviceObject->set(AUTO); $deviceObject->set("position", $method);
} }
} }

View File

@ -27,6 +27,7 @@ class rdc_wc_eclairage extends hook
logger(DEBUG, "CASE: state_l2", __FILE__ . ":" . __LINE__); logger(DEBUG, "CASE: state_l2", __FILE__ . ":" . __LINE__);
if ($value == "ON") if ($value == "ON")
{ {
logger(DEBUG, "method =" . $targetDevice->properties["state_l2"]["method"], __FILE__ . ":" . __LINE__);
if ($targetDevice->properties["state_l2"]["method"] == IDLE) if ($targetDevice->properties["state_l2"]["method"] == IDLE)
{ {
$targetDevice->properties["state_l2"]["method"] = MANUAL; $targetDevice->properties["state_l2"]["method"] = MANUAL;
@ -42,8 +43,8 @@ class rdc_wc_eclairage extends hook
logger(DEBUG, "CASE: occupancy", __FILE__ . ":" . __LINE__); logger(DEBUG, "CASE: occupancy", __FILE__ . ":" . __LINE__);
if ($value === true and $targetDevice->properties["state_l2"]["method"] == IDLE) if ($value === true and $targetDevice->properties["state_l2"]["method"] == IDLE)
{ {
$targetDevice->properties["state_l2"]["method"] = AUTO; //$targetDevice->properties["state_l2"]["method"] = AUTO;
$this->send($targetDevice, "ON"); $this->send($targetDevice, "ON", AUTO);
}elseif ($value === false and $targetDevice->properties["state_l2"]["method"] == AUTO) }elseif ($value === false and $targetDevice->properties["state_l2"]["method"] == AUTO)
{ {
//$targetDevice->properties["state_l2"]["method"] = IDLE; //$targetDevice->properties["state_l2"]["method"] = IDLE;
@ -53,14 +54,14 @@ class rdc_wc_eclairage extends hook
} }
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__); logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
} }
private function send($targetDevice, $state) private function send($targetDevice, $state, $method = IDLE)
{ {
global $indexDevices; global $indexDevices;
$msg = array("state_l2" => $state); $msg = array("state_l2" => $state);
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $targetDevice->friendlyName), __FILE__ . ":" . __LINE__); logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $targetDevice->friendlyName), __FILE__ . ":" . __LINE__);
$targetDevice->payload = $msg; $targetDevice->payload = $msg;
$targetDevice->set(null); $targetDevice->set("state_l2", $method);
} }
} }

View File

@ -27,6 +27,7 @@ class rdc_wc_eclairage extends hook
logger(DEBUG, "CASE: state_l2", __FILE__ . ":" . __LINE__); logger(DEBUG, "CASE: state_l2", __FILE__ . ":" . __LINE__);
if ($value == "ON") if ($value == "ON")
{ {
logger(DEBUG, "method =" . $targetDevice->properties["state_l2"]["method"], __FILE__ . ":" . __LINE__);
if ($targetDevice->properties["state_l2"]["method"] == IDLE) if ($targetDevice->properties["state_l2"]["method"] == IDLE)
{ {
$targetDevice->properties["state_l2"]["method"] = MANUAL; $targetDevice->properties["state_l2"]["method"] = MANUAL;
@ -44,7 +45,7 @@ class rdc_wc_eclairage extends hook
{ {
$targetDevice->properties["state_l2"]["method"] = AUTO; $targetDevice->properties["state_l2"]["method"] = AUTO;
$this->send($targetDevice, "ON"); $this->send($targetDevice, "ON");
}elseif ($value === false and $targetDevice->properties["state_l2"]["method"] != MANUAL) }elseif ($value === false and $targetDevice->properties["state_l2"]["method"] == AUTO)
{ {
//$targetDevice->properties["state_l2"]["method"] = IDLE; //$targetDevice->properties["state_l2"]["method"] = IDLE;
//$this->send($targetDevice, "OFF"); //$this->send($targetDevice, "OFF");

View File

@ -5,7 +5,7 @@ file_put_contents("/proc/".getmypid()."/comm",$title);
declare(ticks = 1); declare(ticks = 1);
$testMode = false; $testMode = false;
$webServerIsActive = true; $apiServerIsActive = true;
require "constants.php"; require "constants.php";
@ -338,7 +338,7 @@ while (true)
//logger(DEBUG, _("looping"), __FILE__ . ":" . __LINE__); //logger(DEBUG, _("looping"), __FILE__ . ":" . __LINE__);
} }
checkEvents(); checkEvents();
apiServer($read); if ($apiServerIsActive) apiServer($read);
} }
endMoha(); endMoha();

View File

@ -16,6 +16,30 @@
print ("MOHA-" . $logString . EOL); print ("MOHA-" . $logString . EOL);
} }
}*/ }*/
function testActionneurs(array $actionneurs)
{
global $indexDevices;
$r = 0;
foreach ($actionneurs as $device)
{
if (array_key_exists($device[0], $indexDevices))
{
if (array_key_exists($device[1], $indexDevices[$device[0]]->properties))
{
$s = ($indexDevices[$device[0]]->properties[$device[1]]["value"] == $device[2]);
logger(DEBUG, _("testActionneurs : result is ") . bool2string($indexDevices[$device[0]]->friendlyName) . "=>" . bool2string($s), __FILE__ . ":" . __LINE__ );
$r |= $s;
}else
{
logger(ERROR, _("no property : ") . $device[1] . bool2string($r), __FILE__ . ":" . __LINE__ );
}
}else
{
logger(ERROR, _("no device : ") . $device[0] . bool2string($r), __FILE__ . ":" . __LINE__ );
}
}
return !$r;
}
function htmlGetFriendlyNames($ieeeAddress = '') function htmlGetFriendlyNames($ieeeAddress = '')
{ {