2022-01-03 21:11:52 +01:00
< ? php
2022-01-17 00:18:50 +01:00
class rdc_sdb_eclairage extends hook
2022-01-03 21:11:52 +01:00
{
public $hookName = " rdc_sdb_eclairage " ;
2022-01-23 09:46:06 +01:00
public $active = true ;
2022-01-03 21:11:52 +01:00
2022-01-17 00:18:50 +01:00
/* already defined in hook class */
// public $active = true;
//public $initlialized = false;
2022-07-07 22:46:05 +02:00
public $delay = 3 ; // amount of time in $timeunit
2022-06-10 12:44:09 +02:00
public $delayManual = 20 ; // amount of time in $timeunit for manual mode
2022-01-17 00:18:50 +01:00
public $timeUnit = " minute " ; // unit of time for delay, second, minute, day, week, month, year
2022-01-03 21:11:52 +01:00
// list of devices we are listening to
2022-01-17 00:18:50 +01:00
// devicelist[$ieeAddress][0] => property to watch
// devicelist[$ieeAddress][1] => initialized = true
protected $devicelist = array (
2022-06-20 10:34:55 +02:00
RDC_SDB_DOUCHE_MVMT => " occupancy " ,
2022-03-13 22:33:26 +01:00
RDC_SDB_PLAFOND_MVMT => " occupancy " ,
RDC_SDB_MVMT => " occupancy " ,
RDC_SDB_WC_ECLAIRAGE => " state_l1 "
2022-01-17 00:18:50 +01:00
);
2022-06-20 10:34:55 +02:00
protected $actionneurs = array (
array ( RDC_SDB_DOUCHE_MVMT , " occupancy " , 1 ),
array ( RDC_SDB_PLAFOND_MVMT , " occupancy " , 1 ),
array ( RDC_SDB_MVMT , " occupancy " , 1 )
);
2022-08-12 10:41:55 +02:00
function installHooks ( & $indexDevices )
{
return $this -> installHooksFunction ( $indexDevices );
}
2022-01-29 19:58:01 +01:00
// callback fonction. Is called with these 3 parameters
2022-01-06 13:03:26 +01:00
public function callBack ( & $device , $property , $value )
2022-01-03 21:11:52 +01:00
{
2022-02-23 10:23:16 +01:00
global $indexDevices ;
2022-01-23 09:46:06 +01:00
//var_dump($value);
2022-04-07 01:44:17 +02:00
$deviceTarget = & $indexDevices [ RDC_SDB_WC_ECLAIRAGE ];
if ( $deviceTarget !== null )
2022-01-03 21:11:52 +01:00
{
2022-04-07 01:44:17 +02:00
logger ( DEBUG , " Callback : " . $this -> hookName , __FILE__ . " : " . __LINE__ );
switch ( $property )
{
case " occupancy " :
2022-08-27 00:02:24 +02:00
$method = $deviceTarget -> properties [ " state_l1 " ][ " method " ];
2022-04-07 01:44:17 +02:00
logger ( DEBUG , _ ( " CASE: occupancy " ), __FILE__ . " : " . __LINE__ );
2022-06-20 10:34:55 +02:00
if ( $value == ON )
2022-03-28 00:40:34 +02:00
{
2022-08-27 00:02:24 +02:00
if ( $method == IDLE )
2022-04-07 01:44:17 +02:00
{
2022-06-20 10:34:55 +02:00
logger ( DEBUG , _ ( " lighting with method auto " ), __FILE__ . " : " . __LINE__ );
//$deviceTarget->properties["state_l1"]["method"] = AUTO;
$this -> send ( " ON " , AUTO );
2022-08-27 00:02:24 +02:00
removeEvent ( $deviceTarget , " state " , " OFF " );
2022-04-07 01:44:17 +02:00
}
2022-08-27 00:02:24 +02:00
} elseif ( ! testActionneurs ( $this -> actionneurs ))
2022-06-20 10:34:55 +02:00
{
logger ( DEBUG , _ ( " Actionneurs are all false " ), __FILE__ . " : " . __LINE__ );
2022-08-05 17:24:11 +02:00
$this -> send ( " OFF " , IDLE );
2022-06-10 12:44:09 +02:00
}
break ;
case " state_l1 " :
2022-08-27 00:02:24 +02:00
$method = $deviceTarget -> properties [ " state_l1 " ][ " method " ];
2022-06-10 12:44:09 +02:00
logger ( DEBUG , _ ( " CASE: state_l1 " ), __FILE__ . " : " . __LINE__ );
2022-06-20 10:34:55 +02:00
if ( $value == " ON " )
2022-06-10 12:44:09 +02:00
{
2022-08-27 00:02:24 +02:00
if ( $method == IDLE )
2022-06-20 10:34:55 +02:00
{
logger ( DEBUG , _ ( " State_l1 is IDLE " ), __FILE__ . " : " . __LINE__ );
2022-08-27 00:02:24 +02:00
removeEvent ( $deviceTarget , " state_l1 " , " OFF " , MANUAL );
//setDelay($deviceTarget, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true, IDLE);
2022-06-20 10:34:55 +02:00
}
} elseif ( $value == " OFF " )
2022-03-28 00:40:34 +02:00
{
2022-06-20 10:34:55 +02:00
removeEvent ( $deviceTarget , " state_l1 " , " OFF " , IDLE );
2022-08-27 00:02:24 +02:00
//$deviceTarget->properties["state_l1"]["method"] = IDLE;
logger ( DEBUG , _ ( " State_l1 is false light is off and method is " ) . $method , __FILE__ . " : " . __LINE__ );
2022-03-28 00:40:34 +02:00
}
2022-04-07 01:44:17 +02:00
break ;
}
2022-06-20 10:34:55 +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-04-07 01:44:17 +02:00
} else
{
logger ( ERROR , RDC_SDB_WC_ECLAIRAGE . _ ( " does not exists " ), __FILE__ . " : " . __LINE__ );
2022-01-03 21:11:52 +01:00
}
2022-04-07 01:44:17 +02:00
2022-01-03 21:11:52 +01:00
}
2022-06-20 10:34:55 +02:00
private function send ( $state , $method )
2022-01-03 21:11:52 +01:00
{
2022-02-23 10:23:16 +01:00
global $indexDevices ;
2022-01-03 21:11:52 +01:00
$msg = array ( " state_l1 " => $state );
2022-02-23 10:23:16 +01:00
$device = & $indexDevices [ RDC_SDB_WC_ECLAIRAGE ];
2022-01-28 23:05:58 +01:00
logger ( INFO , sprintf ( _ ( " publishing message: %s to %s " ), $state , $device -> friendlyName ), __FILE__ . " : " . __LINE__ );
2022-01-03 21:11:52 +01:00
$device -> payload = $msg ;
2022-06-20 10:34:55 +02:00
$device -> set ( " state_l1 " , $method );
2022-01-03 21:11:52 +01:00
}
}
2022-01-04 08:54:06 +01:00
$hooks [ " rdc_sdb_eclairage " ] = new rdc_sdb_eclairage ();
2022-01-17 00:18:50 +01:00
2022-01-03 21:11:52 +01:00
?>