debug + réglage rdc_store
This commit is contained in:
@ -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,127 +40,178 @@ class rdc_store extends hook
|
||||
$storeDevice = $indexDevices[RDC_STORE];
|
||||
//$this->maxLevel = 100;
|
||||
$r = 100;
|
||||
$moving = "STOP";
|
||||
$motorReversal = false;
|
||||
|
||||
if (array_key_exists("position", $storeDevice->properties))
|
||||
if (array_key_exists("moving", $storeDevice->properties))
|
||||
{
|
||||
$this->storeLevel = 100 - $storeDevice->properties["position"]["value"];
|
||||
logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__);
|
||||
}else
|
||||
{
|
||||
$this->storeLevel = 0;
|
||||
//return true;
|
||||
$moving = $storeDevice->properties["moving"]["value"];
|
||||
logger(DEBUG, "Moving = " . $moving, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
|
||||
if (array_key_exists("motor_reversal", $storeDevice->properties))
|
||||
{
|
||||
$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 ($storeDevice->properties["motor_reversal"]["value"] == "ON")
|
||||
{
|
||||
$exterieurLuxMoyen = $exterieur_lux;
|
||||
$motorReversal = true;
|
||||
}else
|
||||
{
|
||||
$motorReversal = false;
|
||||
}
|
||||
logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__);
|
||||
logger(DEBUG, "Motor reversal =" . bool2string($motorReversal), __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties))
|
||||
|
||||
if ($moving == "STOP")
|
||||
{
|
||||
$salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10);
|
||||
if ($salon_lux == 0)
|
||||
if (array_key_exists("position", $storeDevice->properties))
|
||||
{
|
||||
$salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"];
|
||||
}
|
||||
logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if ($exterieur_lux > 30000 or $salon_lux >600)
|
||||
{
|
||||
logger(DEBUG, "exterieur_lux > 30000 or salon_lux >600", __FILE__ . ":" . __LINE__);
|
||||
if ($this->maxLevel != 0 and $salon_lux > 100)
|
||||
{
|
||||
$store2level = $this->storeLevel + 15;
|
||||
if ( $store2level > $this->maxLevel )
|
||||
if ($motorReversal)
|
||||
{
|
||||
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
|
||||
$this->set($this->maxLevel);
|
||||
$this->storeLevel = $storeDevice->properties["position"]["value"];
|
||||
}else
|
||||
{
|
||||
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
|
||||
$this->set($store2level);
|
||||
$this->storeLevel = 100 - $storeDevice->properties["position"]["value"];
|
||||
}
|
||||
logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__);
|
||||
}else
|
||||
{
|
||||
$this->storeLevel = 0;
|
||||
//return true;
|
||||
}
|
||||
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
|
||||
{
|
||||
$exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"];
|
||||
$exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5);
|
||||
if ($exterieurLuxMoyen == 0)
|
||||
{
|
||||
$exterieurLuxMoyen = $exterieur_lux;
|
||||
}
|
||||
logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties))
|
||||
{
|
||||
$salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10);
|
||||
if ($salon_lux == 0)
|
||||
{
|
||||
$salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"];
|
||||
}
|
||||
logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if ($exterieur_lux > 30000 or $salon_lux >600)
|
||||
{
|
||||
logger(DEBUG, "exterieur_lux > 30000 or salon_lux >600", __FILE__ . ":" . __LINE__);
|
||||
if ($this->maxLevel != 0 and $salon_lux > 100)
|
||||
{
|
||||
$store2level = $this->storeLevel + 15;
|
||||
if ( $store2level > $this->maxLevel )
|
||||
{
|
||||
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
|
||||
$this->set($this->maxLevel);
|
||||
}else
|
||||
{
|
||||
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
|
||||
$this->set($store2level);
|
||||
}
|
||||
}
|
||||
}elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 450)
|
||||
{
|
||||
logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 1000", __FILE__ . ":" . __LINE__);
|
||||
$this->close("Luminosité faible");
|
||||
}
|
||||
if (array_key_exists(METEO, $indexDevices))
|
||||
{
|
||||
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
|
||||
{
|
||||
$rainTmp = $indexDevices[METEO]->properties["rainin"]["value"];
|
||||
$rain = $rainTmp - $rainS;
|
||||
$rainS = $rainTmp;
|
||||
logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
|
||||
{
|
||||
if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50)
|
||||
{
|
||||
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6);
|
||||
if ($rafale == 0)
|
||||
{
|
||||
$rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"];
|
||||
}
|
||||
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);
|
||||
logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
}
|
||||
}elseif ($exterieurLuxMoyen < 9000 and $salon_lux < 1000)
|
||||
{
|
||||
logger(DEBUG, "exterieurLuxMoyen < 9000 and salon_lux < 1000", __FILE__ . ":" . __LINE__);
|
||||
$this->close("Luminosité faible");
|
||||
}
|
||||
if (array_key_exists(METEO, $indexDevices))
|
||||
{
|
||||
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
|
||||
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||
if ($rafale >= 70 or $rain != 0)
|
||||
{
|
||||
$rainTmp = $indexDevices[METEO]->properties["rainin"]["value"];
|
||||
$rain = $rainTmp - $rainS;
|
||||
$rainS = $rainTmp;
|
||||
logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
|
||||
$this->maxLevel = 0;
|
||||
logger(DEBUG, sprintf("rafale = %s and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__);
|
||||
$this->close("vent trop fort ou pluie");
|
||||
return 0;
|
||||
}elseif ($rafale != 0)
|
||||
{
|
||||
if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50)
|
||||
//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)
|
||||
{
|
||||
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6);
|
||||
if ($rafale == 0)
|
||||
$this->maxLevel = $r;
|
||||
}else
|
||||
{
|
||||
$rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"];
|
||||
$this->maxLevel = 100 - $r;
|
||||
}
|
||||
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
|
||||
{
|
||||
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12);
|
||||
logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
}
|
||||
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||
if ($rafale >= 50 or $rain != 0)
|
||||
{
|
||||
$this->maxLevel = 0;
|
||||
logger(DEBUG, sprintf("rafale = %s and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__);
|
||||
$this->close("vent trop fort ou pluie");
|
||||
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;
|
||||
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__);
|
||||
logger(DEBUG, "maxlevel=" . $this->maxLevel, __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:
|
||||
}
|
||||
logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
|
||||
if ($this->storeLevel > $this->maxLevel)
|
||||
switch ($property)
|
||||
{
|
||||
case "rainin":
|
||||
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
|
||||
$this->close("Pluie");
|
||||
break;
|
||||
case "windgustkmh";
|
||||
logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
|
||||
if ($this->storeLevel > $this->maxLevel)
|
||||
{
|
||||
$this->set($this->maxLevel);
|
||||
}
|
||||
}else
|
||||
{
|
||||
$this->set($this->maxLevel);
|
||||
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)
|
||||
|
Reference in New Issue
Block a user