2022-01-02 13:07:02 +01:00
< ? php
2022-01-28 23:05:58 +01:00
logger ( DEBUG , _ ( " Including class main.php " ), __FILE__ . " : " . __LINE__ );
2022-01-17 00:18:50 +01:00
2022-01-02 13:07:02 +01:00
class Message
{
public $id ;
public $state = false ;
public $msg ;
}
class topic {
public $mid ;
public $status ;
public $info ;
public $devices ;
public $groups ;
public $extensions ;
public $config ;
2022-01-08 11:51:50 +01:00
public $callback ;
2022-02-07 16:58:42 +01:00
public $getOnStart = false ;
2022-07-10 19:33:19 +02:00
public $lastSeen ;
public $timeOut = 5 ;
public $notificationSent = false ;
2022-01-02 13:07:02 +01:00
}
class device
{
public $topic ;
public $ieeeAddress ;
public $groupID ;
public $friendlyName ;
public $powerSource ;
public $description ;
public $functions ;
public $payload ;
2022-01-23 09:46:06 +01:00
public $toConfirm ;
2022-01-27 18:41:16 +01:00
public $triggerDevice ;
2022-02-12 15:23:58 +01:00
public $properties = array ();
2022-07-10 19:33:19 +02:00
public $lastSeen ;
2022-01-02 13:07:02 +01:00
2022-01-27 18:41:16 +01:00
public function __construct ()
2022-01-02 13:07:02 +01:00
{
2022-01-19 00:22:34 +01:00
$this -> availability = array ( " value " => null , " functions " => array ());
}
2022-06-20 10:34:55 +02:00
public function set ( $property , $method = IDLE ) //, $event = null)
2022-01-19 00:22:34 +01:00
{
2022-06-20 10:34:55 +02:00
publish ( $this -> topic . " / " . $this -> friendlyName , $this -> payload , " set " ); //, $event);
$this -> properties [ $property ][ " method " ] = $method ;
2022-01-02 13:07:02 +01:00
}
public function get ()
{
2022-02-07 16:58:42 +01:00
publish ( $this -> topic . " / " . $this -> friendlyName , $this -> payload , " get " ); //, $event);
2022-01-02 13:07:02 +01:00
}
}
class ranges
{
public $start ; //datetime
public $end ; //datetime
}
class event
{
public $ieeeAddress ;
public $topic ;
public $param ;
public $value ;
2022-03-15 22:49:13 +01:00
public $function ;
2022-01-02 13:07:02 +01:00
public $device ;
public $published ;
2022-08-28 00:06:24 +02:00
public $dateTimeEvent ; // recurrent event: datetime
2022-01-02 13:07:02 +01:00
public $startDatetime ;
public $stopDatetime ;
2022-08-28 00:06:24 +02:00
public $recurrence ; // recurrent event: interval or date to add
2022-01-02 13:07:02 +01:00
public $exceptionInterval ; // array of object ranges
2022-04-07 01:44:17 +02:00
public $method ; // cf: constants.php (IDLE, AUTO, MANUAL)
2022-08-28 00:06:24 +02:00
public $isInterval = false ; // 0 => recurence by date 1 => by interval
2022-01-02 13:07:02 +01:00
}
2022-01-30 00:21:50 +01:00
class watch
{
public $topic ;
public $property ;
2022-01-30 19:59:22 +01:00
public $PropertyValue ;
2022-01-30 00:21:50 +01:00
public $function ;
2022-02-02 21:18:44 +01:00
public $conditions = array (
2022-01-30 00:21:50 +01:00
" < " , " > " , " == " , " >= " , " <= "
);
2022-02-02 21:18:44 +01:00
public $acceptedValues = array (
" ON " , " OFF "
);
2022-01-30 19:59:22 +01:00
public $condition ;
2022-01-30 00:21:50 +01:00
public function __construct ( $topic , $fn , $property , $condition , $value )
{
2022-02-12 15:23:58 +01:00
global $conditions , $indexDevices ;
2022-02-02 21:18:44 +01:00
logger ( DEBUG , _ ( " New Notification " ), __FILE__ . " : " . __LINE__ );
if (( $device = getDevice ( $topic , $fn )) !== false )
2022-01-30 00:21:50 +01:00
{
$this -> topic = $topic ;
2022-02-12 15:23:58 +01:00
if ( array_key_exists ( $property , $device -> properties ))
2022-01-30 00:21:50 +01:00
{
$this -> property = $property ;
2022-02-12 15:23:58 +01:00
if ( ! is_numeric ( $value ) or array_search ( $value , $this -> acceptedValues ) === false )
2022-01-30 00:21:50 +01:00
{
2022-02-12 15:23:58 +01:00
logger ( ERROR , _ ( " Value is not numeric or not accepted " ), __FILE__ . " : " . __LINE__ );
2022-01-30 00:21:50 +01:00
return false ;
}
2022-02-02 21:18:44 +01:00
if ( array_search ( $condition , $this -> conditions ))
2022-01-30 00:21:50 +01:00
{
2022-02-02 21:18:44 +01:00
$this -> condition = $condition ;
$this -> function = '$value ' . $condition . " " . $value . " ; " ;
logger ( DEBUG , _ ( " Test function is " ) . $this -> function , __FILE__ . " : " . __LINE__ );
2022-01-30 00:21:50 +01:00
} else
{
2022-02-02 21:18:44 +01:00
logger ( ERROR , sprintf ( _ ( " Condition %s is not one of the permitted : " ), $condition ) . print_r ( $conditions , true ), __FILE__ . " : " . __LINE__ );
2022-01-30 00:21:50 +01:00
return false ;
}
2022-02-12 15:23:58 +01:00
$indexDevices [ $device -> ieeeAddress ] -> properties [ $property ][ " functions " ][] = array ( $this , " notifyCallback " );
2022-01-30 00:21:50 +01:00
} else
{
logger ( ERROR , _ ( " Property do not exists " ), __FILE__ . " : " . __LINE__ );
return false ;
}
} else
{
logger ( ERROR , _ ( " Device do not exists " ), __FILE__ . " : " . __LINE__ );
return false ;
}
2022-02-02 21:18:44 +01:00
logger ( DEBUG , var_export ( $this , true ), __FILE__ . " : " . __LINE__ );
2022-01-30 00:21:50 +01:00
return $this ;
}
2022-01-30 19:59:22 +01:00
2022-03-13 22:33:26 +01:00
public function notifyCallback ( $device , $property , $value )
2022-01-30 19:59:22 +01:00
{
if ( eval ( $this -> function ))
{
2022-02-02 21:18:44 +01:00
logger ( DEBUG , _ ( " notifyCallback " ));
2022-02-12 15:23:58 +01:00
$msg = sprintf ( _ ( " Device '%s' have property '%s' value %s %s %s " ), $device -> friendlyName , $property , bool2string ( $value ), $this -> condition , bool2string ( $this -> PropertyValue ) );
2022-01-30 19:59:22 +01:00
notify ( $msg );
}
}
2022-01-30 00:21:50 +01:00
}
2022-01-02 13:07:02 +01:00
class interval
{
public $startDate ;
public $endDate ;
}
?>