debug + réglage rdc_store
This commit is contained in:
parent
b2f79dd49c
commit
413c25c0b7
@ -98,7 +98,7 @@ class db extends mysqli
|
||||
{
|
||||
$value = $this->result->fetch_array(MYSQLI_NUM);
|
||||
//var_dump($value);
|
||||
logger(DEBUG, _("result is: ") . print_r($value, true), __FILE__ . ":" . __LINE__);
|
||||
logger(DEBUG, _("result is: ") . print_r($value[0], true), __FILE__ . ":" . __LINE__);
|
||||
return $value[0];
|
||||
}
|
||||
}
|
||||
|
@ -28,23 +28,29 @@ class hook
|
||||
static $requestflag = 0;
|
||||
$result = true;
|
||||
// assigne the function to the sensors devices
|
||||
if ($this->active === true)
|
||||
{
|
||||
foreach ($this->devicelist as $ieeeAddress => $property)
|
||||
{
|
||||
|
||||
if (array_key_exists($ieeeAddress, $indexDevices))
|
||||
{
|
||||
logger(DEBUG, _("Device: ") . $ieeeAddress, __FILE__ . ":" . __LINE__);
|
||||
if (!array_key_exists($this->hookName, $indexDevices[$ieeeAddress]->properties[$property]["functions"]))
|
||||
{
|
||||
//if (!array_key_exists($this->hookName, $indexDevices[$ieeeAddress]->properties[$property]["functions"]))
|
||||
//{
|
||||
if (array_key_exists($property, $indexDevices[$ieeeAddress]->properties))
|
||||
{
|
||||
logger(DEBUG, _("Trying to store callback"), __FILE__ . ":" . __LINE__);
|
||||
if (array_key_exists("functions", $indexDevices[$ieeeAddress]->properties[$property]))
|
||||
{
|
||||
if ($this->active === true)
|
||||
{
|
||||
$indexDevices[$ieeeAddress]->properties[$property]["functions"][$this->hookName] = array($this,"callback");
|
||||
logger(DEBUG, sprintf(_("Property '%s' of %s is initialized with callback"), $property, $indexDevices[$ieeeAddress]->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
|
||||
}elseif ($this->active === false)
|
||||
{
|
||||
unset ($indexDevices[$ieeeAddress]->properties[$property]["functions"][$this->hookName]);
|
||||
logger(DEBUG, $indexDevices[$ieeeAddress]->friendlyName . "/" . $property . _(" Unsetting ") .$this->hookName , __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
}else
|
||||
{
|
||||
logger(WARNING, sprintf(_("Hook %s can not initialize Property '%s' of device %s"), $this->hookName, $property, $ieeeAddress), __FILE__ . ":" . __LINE__);
|
||||
@ -55,10 +61,10 @@ class hook
|
||||
logger(WARNING, sprintf(_("Hook %s can not initialize Property '%s' of device %s : property does not exists"), $this->hookName, $property, $indexDevices[$ieeeAddress]->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
$result = false;
|
||||
}
|
||||
}else
|
||||
{
|
||||
logger(DEBUG, _("Callback already installed"), __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
//}else
|
||||
//{
|
||||
// logger(DEBUG, _("Callback already installed"), __FILE__ . ":" . __LINE__);
|
||||
//}
|
||||
}else
|
||||
{
|
||||
logger(ERROR, $ieeeAddress . (" does not exists"), __FILE__ . ":" . __LINE__);
|
||||
@ -75,7 +81,6 @@ class hook
|
||||
mkIndexes();
|
||||
}
|
||||
|
||||
}
|
||||
//echo "result => "; var_dump($result);
|
||||
if ($result === true)
|
||||
{
|
||||
@ -83,13 +88,7 @@ class hook
|
||||
logger(INFO, $this->hookName . _(" initialized"), __FILE__ . ":" . __LINE__);
|
||||
//var_dump($this);
|
||||
}
|
||||
}/*else
|
||||
{
|
||||
$this->initialized = true;
|
||||
logger(INFO, $this->hookName . _("hook is disabled"), __FILE__ . ":" . __LINE__);
|
||||
}*/
|
||||
//print(var_export($indexDevices[$ieeeAddress],true));
|
||||
//storeDB($devices,"debug.devices");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ function getDevicesValues($topic)
|
||||
|
||||
function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key)
|
||||
{
|
||||
global $mohaDB, $properties2log;
|
||||
global $mohaDB, $properties2log, $hooks;
|
||||
//$changed[$fn]["key"] = $key;
|
||||
//$changed[$fn]["value"] = $value;
|
||||
|
||||
@ -293,13 +293,14 @@ function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger(INFO, print_r($function, true), __FILE__ . ":" . __LINE__);
|
||||
if ( $function[0]->active === true )
|
||||
$active = $hooks[$function[0]->hookName]->active;
|
||||
logger(INFO, "active = " . bool2string($active), __FILE__ . ":" . __LINE__);
|
||||
if ( $active === true )
|
||||
{
|
||||
$function($parentDevice, $key, $value);
|
||||
}else
|
||||
{
|
||||
logger(INFO, $function . _(" is disabled"), __FILE__ . ":" . __LINE__ );
|
||||
logger(INFO, $function[0]->hookName . _(" is disabled"), __FILE__ . ":" . __LINE__ );
|
||||
}
|
||||
|
||||
}catch (Exception $e)
|
||||
|
@ -4,6 +4,7 @@ class availability
|
||||
{
|
||||
public $hookname = "availability";
|
||||
public $initialized = true;
|
||||
public $active = true;
|
||||
// by default all devices are listening for availability
|
||||
|
||||
function __construct()
|
||||
@ -21,6 +22,10 @@ class availability
|
||||
}
|
||||
}
|
||||
|
||||
function installHooks(&$indexDevices)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// callback fonction. Is called with these 3 parameters
|
||||
// $device -> calling device
|
||||
// $property -> parameter passed by mqtt
|
||||
|
@ -3,7 +3,7 @@
|
||||
class rdc_store extends hook
|
||||
{
|
||||
public $hookName = "rdc_store";
|
||||
public $active = false; //enable/disable hook (true => enabled)
|
||||
public $active = true; //enable/disable hook (true => enabled)
|
||||
public $timer = 0;
|
||||
public $luminance_min = 60;
|
||||
public $luminance_max = 3000;
|
||||
@ -29,7 +29,6 @@ class rdc_store extends hook
|
||||
{
|
||||
global $mohaDB, $devices, $indexDevices;
|
||||
|
||||
if ($this->active)
|
||||
logger(DEBUG, "Callback : RDC_STORE", __FILE__ . ":" . __LINE__);
|
||||
$rain = 0;
|
||||
static $rainS;
|
||||
@ -41,10 +40,37 @@ class rdc_store extends hook
|
||||
$storeDevice = $indexDevices[RDC_STORE];
|
||||
//$this->maxLevel = 100;
|
||||
$r = 100;
|
||||
$moving = "STOP";
|
||||
$motorReversal = false;
|
||||
|
||||
if (array_key_exists("moving", $storeDevice->properties))
|
||||
{
|
||||
$moving = $storeDevice->properties["moving"]["value"];
|
||||
logger(DEBUG, "Moving = " . $moving, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("motor_reversal", $storeDevice->properties))
|
||||
{
|
||||
if ($storeDevice->properties["motor_reversal"]["value"] == "ON")
|
||||
{
|
||||
$motorReversal = true;
|
||||
}else
|
||||
{
|
||||
$motorReversal = false;
|
||||
}
|
||||
logger(DEBUG, "Motor reversal =" . bool2string($motorReversal), __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
|
||||
if ($moving == "STOP")
|
||||
{
|
||||
if (array_key_exists("position", $storeDevice->properties))
|
||||
{
|
||||
if ($motorReversal)
|
||||
{
|
||||
$this->storeLevel = $storeDevice->properties["position"]["value"];
|
||||
}else
|
||||
{
|
||||
$this->storeLevel = 100 - $storeDevice->properties["position"]["value"];
|
||||
}
|
||||
logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__);
|
||||
}else
|
||||
{
|
||||
@ -55,7 +81,7 @@ class rdc_store extends hook
|
||||
{
|
||||
$exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"];
|
||||
$exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5);
|
||||
if ($exterieur_lux == 0)
|
||||
if ($exterieurLuxMoyen == 0)
|
||||
{
|
||||
$exterieurLuxMoyen = $exterieur_lux;
|
||||
}
|
||||
@ -86,9 +112,9 @@ class rdc_store extends hook
|
||||
$this->set($store2level);
|
||||
}
|
||||
}
|
||||
}elseif ($exterieurLuxMoyen < 9000 and $salon_lux < 1000)
|
||||
}elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 450)
|
||||
{
|
||||
logger(DEBUG, "exterieurLuxMoyen < 9000 and salon_lux < 1000", __FILE__ . ":" . __LINE__);
|
||||
logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 1000", __FILE__ . ":" . __LINE__);
|
||||
$this->close("Luminosité faible");
|
||||
}
|
||||
if (array_key_exists(METEO, $indexDevices))
|
||||
@ -113,6 +139,23 @@ class rdc_store extends hook
|
||||
}
|
||||
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("windspeedkmh", $indexDevices[METEO]->properties))
|
||||
{
|
||||
if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50)
|
||||
{
|
||||
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
$vent = $mohaDB->moyenne($indexDevices[METEO], "windspeedkmh", 6);
|
||||
if ($vent == 0)
|
||||
{
|
||||
$vent = $indexDevices[METEO]->properties["windspeedkmh"]["value"];
|
||||
}
|
||||
logger(DEBUG, "vitesse du vent =" . $vent, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if ($vent > $rafale)
|
||||
{
|
||||
$rafale = $vent;
|
||||
}
|
||||
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
|
||||
{
|
||||
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12);
|
||||
@ -120,7 +163,7 @@ class rdc_store extends hook
|
||||
}
|
||||
}
|
||||
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||
if ($rafale >= 50 or $rain != 0)
|
||||
if ($rafale >= 70 or $rain != 0)
|
||||
{
|
||||
$this->maxLevel = 0;
|
||||
logger(DEBUG, sprintf("rafale = %s and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__);
|
||||
@ -128,26 +171,28 @@ class rdc_store extends hook
|
||||
return 0;
|
||||
}elseif ($rafale != 0)
|
||||
{
|
||||
$this->maxLevel = ($r = 120 - round($rafale/4, 0, PHP_ROUND_HALF_UP)*10)<0 ? 0 : $r;
|
||||
//$this->maxLevel = 100 / $rafale;
|
||||
//calcul du maxlevel par rapport a la vitesse des rafales
|
||||
$r = round(($rafale-20)/5, 0, PHP_ROUND_HALF_UP)*10;
|
||||
if ($r < 0) $r = 0;
|
||||
if ($motorReversal)
|
||||
{
|
||||
$this->maxLevel = $r;
|
||||
}else
|
||||
{
|
||||
$this->maxLevel = 100 - $r;
|
||||
}
|
||||
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__);
|
||||
//$store2level = $this->maxLevel;
|
||||
|
||||
switch ($property)
|
||||
{
|
||||
/*case "illuminance_lux":
|
||||
logger(DEBUG, "CASE: illuminance_lux:" . $value, __FILE__ . ":" . __LINE__);
|
||||
|
||||
break;*/
|
||||
case "rainin":
|
||||
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
|
||||
$this->close("Pluie");
|
||||
break;
|
||||
case "windgustkmh";
|
||||
logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__);
|
||||
//case "windspeedkmh":
|
||||
// logger(DEBUG, "CASE: windspeedkmh:" . $value, __FILE__ . ":" . __LINE__);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
@ -156,12 +201,17 @@ class rdc_store extends hook
|
||||
{
|
||||
$this->set($this->maxLevel);
|
||||
}
|
||||
}else
|
||||
{
|
||||
logger(DEBUG, _("Store is Moving ") . $moving, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function set ($level)
|
||||
{
|
||||
logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__);
|
||||
if ($this->storeLevel < $level AND $level <=100)
|
||||
if ($level <= 100)
|
||||
{
|
||||
logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__);
|
||||
$this->send(100 - $level);
|
||||
@ -193,4 +243,6 @@ class rdc_store extends hook
|
||||
}
|
||||
|
||||
$hooks["rdc_store"] = new rdc_store();
|
||||
|
||||
?>
|
||||
print_r($function[0], true)
|
||||
|
Loading…
Reference in New Issue
Block a user