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;
public $delay = 3 ; // amount of time in $timeunit
2022-01-20 00:26:57 +01:00
public $delayManual = 15 ; // 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-01-19 00:22:34 +01:00
RDC_SDB_DOUCHE_MVMT => array ( " occupancy " , false ),
RDC_SDB_PLAFOND_MVMT => array ( " occupancy " , false ),
RDC_SDB_MVMT => array ( " occupancy " , false ),
2022-01-17 00:18:50 +01:00
RDC_SDB_WC_ECLAIRAGE => array ( " state_l1 " , false )
);
2022-01-03 21:11:52 +01:00
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
{
global $devices , $indexDevices ;
2022-01-23 09:46:06 +01:00
//var_dump($value);
2022-01-06 13:03:26 +01:00
switch ( $property )
2022-01-03 21:11:52 +01:00
{
case " occupancy " :
if ( $value == ON )
{
2022-01-29 19:58:01 +01:00
if ( getValue ( RDC_SDB_WC_ECLAIRAGE , " state_l1 " ) != " ON " )
{
$this -> send ( " ON " );
}
//setDelay($indexDevices[RDC_SDB_WC_ECLAIRAGE], $this->delay, $this->timeUnit, "state_l1", "OFF", true);
2022-01-03 21:11:52 +01:00
$device -> method = AUTO ;
}
break ;
case " state_l1 " :
if ( $value == ON )
{
2022-01-29 19:58:01 +01:00
setDelay ( $indexDevices [ RDC_SDB_WC_ECLAIRAGE ], $this -> delayManual , $this -> timeUnit , " state_l1 " , " OFF " , true );
2022-01-03 21:11:52 +01:00
$device -> method = MANUAL ;
} elseif ( $value = OFF )
{
2022-01-29 19:58:01 +01:00
removeEvent ( $indexDevices [ RDC_SDB_WC_ECLAIRAGE ], " state_l1 " , " OFF " );
2022-01-03 21:11:52 +01:00
}
break ;
}
2022-01-28 23:05:58 +01:00
logger ( INFO , sprintf ( _ ( " %s: notification received from MQTT from %s => parameter: %s value: %s " ), $this -> hookName , $device -> friendlyName , $property , ( $value == 0 ? " OFF " : " ON " )), __FILE__ . " : " . __LINE__ );
2022-01-03 21:11:52 +01:00
}
private function send ( $state )
{
global $devices , $indexDevices ;
$msg = array ( " state_l1 " => $state );
2022-01-20 00:26:57 +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 ;
$device -> set ( null );
2022-01-23 09:46:06 +01:00
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
?>