2022-01-06 13:03:26 +01:00
< ? php
2022-01-17 00:18:50 +01:00
class rdc_wc_eclairage extends hook
2022-01-06 13:03:26 +01:00
{
public $hookName = " rdc_wc_eclairage " ;
2022-06-13 20:57:53 +02:00
public $active = true ; //enable/disable hook (true => enabled)
2022-01-06 13:03:26 +01:00
2022-03-13 22:33:26 +01:00
protected $devicelist = array (
RDC_SDB_WC_ECLAIRAGE => " state_l2 " ,
RDC_WC_MVMT => " occupancy "
);
2022-01-06 13:03:26 +01:00
2022-06-13 20:57:53 +02:00
public $delay = 1 ; // amount of time in $timeunit
public $delayManual = 10 ; // amount of time in $timeunit for manual mode
2022-01-06 13:03:26 +01:00
public $timeUnit = " minute " ; // unit of time for delay, second, minute, day, week, month, year
// callback fonction. Is called with these 4 parameters
2022-03-13 22:33:26 +01:00
public function callBack ( & $device , $property , $value )
2022-01-06 13:03:26 +01:00
{
2022-02-23 10:23:16 +01:00
global $indexDevices ;
2022-04-07 01:44:17 +02:00
$targetDevice = & $indexDevices [ RDC_SDB_WC_ECLAIRAGE ]; //var_dump($value);
2022-03-28 00:40:34 +02:00
logger ( DEBUG , " Callback : " . $this -> hookName , __FILE__ . " : " . __LINE__ );
2022-01-06 13:03:26 +01:00
switch ( $property )
{
case " state_l2 " :
2022-03-28 00:40:34 +02:00
logger ( DEBUG , " CASE: state_l2 " , __FILE__ . " : " . __LINE__ );
2022-01-20 00:26:57 +01:00
if ( $value == " ON " )
2022-01-06 13:03:26 +01:00
{
2022-06-13 20:57:53 +02:00
if ( $targetDevice -> properties [ " state_l2 " ][ " method " ] == IDLE )
2022-03-28 00:40:34 +02:00
{
2022-06-10 12:44:09 +02:00
$targetDevice -> properties [ " state_l2 " ][ " method " ] = MANUAL ;
setDelay ( $device , $this -> delayManual , $this -> timeUnit , " state_l2 " , " OFF " , true );
2022-03-28 00:40:34 +02:00
}
2022-03-04 22:30:16 +01:00
} elseif ( $value == " OFF " )
2022-01-06 13:03:26 +01:00
{
2022-06-10 12:44:09 +02:00
$targetDevice -> properties [ " state_l2 " ][ " method " ] = IDLE ;
removeEvent ( $device , " state_l2 " , " OFF " );
2022-01-06 13:03:26 +01:00
}
break ;
2022-03-13 22:33:26 +01:00
case " occupancy " :
2022-03-28 00:40:34 +02:00
logger ( DEBUG , " CASE: occupancy " , __FILE__ . " : " . __LINE__ );
2022-06-13 20:57:53 +02:00
if ( $value === true and $targetDevice -> properties [ " state_l2 " ][ " method " ] == IDLE )
2022-03-13 22:33:26 +01:00
{
2022-04-07 01:44:17 +02:00
$targetDevice -> properties [ " state_l2 " ][ " method " ] = AUTO ;
$this -> send ( $targetDevice , " ON " );
2022-06-13 20:57:53 +02:00
} elseif ( $value === false and $targetDevice -> properties [ " state_l2 " ][ " method " ] == AUTO )
2022-04-07 01:44:17 +02:00
{
2022-06-10 12:44:09 +02:00
//$targetDevice->properties["state_l2"]["method"] = IDLE;
//$this->send($targetDevice, "OFF");
setDelay ( $device , $this -> delay , $this -> timeUnit , " state_l2 " , " OFF " , true , IDLE );
2022-03-13 22:33:26 +01:00
}
2022-01-06 13:03:26 +01:00
}
2022-02-12 15:23:58 +01: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-01-06 13:03:26 +01:00
}
2022-04-07 01:44:17 +02:00
private function send ( $targetDevice , $state )
2022-03-13 22:33:26 +01:00
{
global $indexDevices ;
2022-04-07 01:44:17 +02:00
2022-03-13 22:33:26 +01:00
$msg = array ( " state_l2 " => $state );
2022-04-07 01:44:17 +02:00
logger ( INFO , sprintf ( _ ( " publishing message: %s to %s " ), json_encode ( $msg ), $targetDevice -> friendlyName ), __FILE__ . " : " . __LINE__ );
$targetDevice -> payload = $msg ;
$targetDevice -> set ( null );
2022-03-13 22:33:26 +01:00
}
2022-01-06 13:03:26 +01:00
}
$hooks [ " rdc_wc_eclairage " ] = new rdc_wc_eclairage ();
?>