2022-06-13 20:57:53 +02:00
< ? php
class rdc_wc_eclairage extends hook
{
public $hookName = " rdc_wc_eclairage " ;
public $active = true ; //enable/disable hook (true => enabled)
protected $devicelist = array (
RDC_SDB_WC_ECLAIRAGE => " state_l2 " ,
RDC_WC_MVMT => " occupancy "
);
2022-08-05 17:24:11 +02:00
public $delay = 3 ; // amount of time in $timeunit
2022-06-13 20:57:53 +02:00
public $delayManual = 10 ; // amount of time in $timeunit for manual mode
public $timeUnit = " minute " ; // unit of time for delay, second, minute, day, week, month, year
2022-08-12 10:41:55 +02:00
function installHooks ( & $indexDevices )
{
$this -> installHooksFunction ( $indexDevices );
}
2022-06-13 20:57:53 +02:00
// callback fonction. Is called with these 4 parameters
public function callBack ( & $device , $property , $value )
{
global $indexDevices ;
$targetDevice = & $indexDevices [ RDC_SDB_WC_ECLAIRAGE ]; //var_dump($value);
logger ( DEBUG , " Callback : " . $this -> hookName , __FILE__ . " : " . __LINE__ );
switch ( $property )
{
case " state_l2 " :
logger ( DEBUG , " CASE: state_l2 " , __FILE__ . " : " . __LINE__ );
if ( $value == " ON " )
{
2022-06-20 10:34:55 +02:00
logger ( DEBUG , " method = " . $targetDevice -> properties [ " state_l2 " ][ " method " ], __FILE__ . " : " . __LINE__ );
2022-06-13 20:57:53 +02:00
if ( $targetDevice -> properties [ " state_l2 " ][ " method " ] == IDLE )
{
$targetDevice -> properties [ " state_l2 " ][ " method " ] = MANUAL ;
2022-08-05 17:24:11 +02:00
setDelay ( $targetDevice , $this -> delayManual , $this -> timeUnit , " state_l2 " , " OFF " , true );
2022-06-13 20:57:53 +02:00
}
} elseif ( $value == " OFF " )
{
$targetDevice -> properties [ " state_l2 " ][ " method " ] = IDLE ;
2022-08-05 17:24:11 +02:00
removeEvent ( $targetDevice , " state_l2 " , " OFF " );
2022-06-13 20:57:53 +02:00
}
break ;
case " occupancy " :
2022-08-05 17:24:11 +02:00
logger ( DEBUG , " CASE: WC occupancy " , __FILE__ . " : " . __LINE__ );
2022-07-07 22:46:05 +02:00
logger ( DEBUG , " method = " . $targetDevice -> properties [ " state_l2 " ][ " method " ], __FILE__ . " : " . __LINE__ );
2022-06-13 20:57:53 +02:00
if ( $value === true and $targetDevice -> properties [ " state_l2 " ][ " method " ] == IDLE )
{
2022-07-07 22:46:05 +02:00
//$targetDevice->properties["state_l2"]["method"] = AUTO;
$this -> send ( $targetDevice , " ON " , AUTO );
2022-08-05 17:24:11 +02:00
removeEvent ( $targetDevice , " state_l2 " , " OFF " );
2022-06-20 10:34:55 +02:00
} elseif ( $value === false and $targetDevice -> properties [ " state_l2 " ][ " method " ] == AUTO )
2022-06-13 20:57:53 +02:00
{
//$targetDevice->properties["state_l2"]["method"] = IDLE;
//$this->send($targetDevice, "OFF");
2022-08-05 17:24:11 +02:00
//setDelay($targetDevice, $this->delay, $this->timeUnit, "state_l2", "OFF", true, IDLE);
$this -> send ( $targetDevice , " OFF " , IDLE );
2022-06-13 20:57:53 +02:00
}
}
logger ( INFO , sprintf ( _ ( " %s: notification received from MQTT from %s => parameter: %s value: %s " ), $this -> hookName , $device -> friendlyName , $property , bool2string ( $value )), __FILE__ . " : " . __LINE__ );
}
2022-07-07 22:46:05 +02:00
private function send ( $targetDevice , $state , $method = IDLE )
2022-06-13 20:57:53 +02:00
{
global $indexDevices ;
$msg = array ( " state_l2 " => $state );
logger ( INFO , sprintf ( _ ( " publishing message: %s to %s " ), json_encode ( $msg ), $targetDevice -> friendlyName ), __FILE__ . " : " . __LINE__ );
$targetDevice -> payload = $msg ;
2022-07-07 22:46:05 +02:00
$targetDevice -> set ( " state_l2 " , $method );
2022-06-13 20:57:53 +02:00
}
}
$hooks [ " rdc_wc_eclairage " ] = new rdc_wc_eclairage ();
?>