@link http://blog.idleman.fr
@licence CC by nc sa
@version 1.0.0
@description Plugin de gestion des portes avec gache éléctrique + detection ouverture/fermeture (capteur a effet de hall)
*/
include('Door.class.php');
function door_plugin_setting_page(){
global $_,$myUser;
if(isset($_['section']) && $_['section']=='door' ){
if($myUser!=false){
$doorManager = new Door();
$doors = $doorManager->populate();
$roomManager = new Room();
$rooms = $roomManager->loadAll(array('state'=>'0'));
?>
Porte
Gestion des portes
Nom |
Description |
Pin GPIO verouillage |
Pin GPIO etat |
Pièce |
load(array('id'=>$door->getRoom()));
?>
getName(); ?> |
getDescription(); ?> |
getPinRelay(); ?> |
getPinCaptor(); ?> |
getName(); ?> |
|
Porte';
}
function door_display($room){
global $_;
$doorManager = new Door();
$doors = $doorManager->loadAll(array('room'=>$room->getId()));
foreach ($doors as $door) {
?>
getName() ?>
getDescription() ?>
- PIN GPIO verouillage :
getPinRelay() ?>
- PIN GPIO état :
getPinCaptor() ?>
- Type :
Verrou
- Emplacement :
getName() ?>
populate();
foreach($doors as $door){
$response['commands'][] = array('command'=>VOCAL_ENTITY_NAME.', ouvre '.$door->getName(),'url'=>$actionUrl.'?action=door_change_state&engine='.$door->getId().'&state=1&webservice=true','confidence'=>'0.9');
$response['commands'][] = array('command'=>VOCAL_ENTITY_NAME.', ferme '.$door->getName(),'url'=>$actionUrl.'?action=door_change_state&engine='.$door->getId().'&state=0&webservice=true','confidence'=>'0.9');
$response['commands'][] = array('command'=>VOCAL_ENTITY_NAME.', etat '.$door->getName(),'url'=>$actionUrl.'?action=door_get_state&engine='.$door->getId().'&webservice=true','confidence'=>'0.9');
}
}
function door_action_door(){
global $_,$conf,$myUser;
switch($_['action']){
case 'door_delete_door':
if($myUser->can('porte','d')){
$doorManager = new Door();
$doorManager->delete(array('id'=>$_['id']));
}
header('location:setting.php?section=door');
break;
case 'door_add_door':
if($myUser->can('porte','c')){
$door = new Door();
$door->setName($_['nameDoor']);
$door->setDescription($_['descriptionDoor']);
$door->setPinRelay($_['pinDoorRelay']);
$door->setPinCaptor($_['pinDoorCaptor']);
$door->setRoom($_['roomDoor']);
$door->save();
}
header('location:setting.php?section=door');
break;
case 'door_get_state':
if($myUser->can('porte','r')){
$door = new Door();
$door = $door->getById($_['engine']);
$cmd = '/usr/local/bin/gpio mode '.$door->getPinCaptor().' in';
system($cmd,$out);
$cmd = '/usr/local/bin/gpio read '.$door->getPinCaptor();
exec($cmd,$out);
if(!isset($_['webservice'])){
echo $out[0];
}else{
$affirmation = (trim($out[0])?'Ouvert':'Fermé');
$response = array('responses'=>array(
array('type'=>'talk','sentence'=>$affirmation)
)
);
$json = json_encode($response);
echo ($json=='[]'?'{}':$json);
}
}
break;
case 'door_change_state':
global $_,$myUser;
if($myUser->can('porte','u')){
$door = new Door();
$door = $door->getById($_['engine']);
$cmd = '/usr/local/bin/gpio mode '.$door->getPinRelay().' out';
system($cmd,$out);
$cmd = '/usr/local/bin/gpio write '.$door->getPinRelay().' '.$_['state'];
system($cmd,$out);
//TODO change bdd state
if(!isset($_['webservice'])){
header('location:index.php?module=room&id='.$door->getRoom());
}else{
$affirmations = array( 'A vos ordres!',
'Bien!',
'Oui commandant!',
'Avec plaisir!',
'J\'aime vous obéir!',
'Avec plaisir!',
'Certainement!',
'Je fais ça sans tarder!',
'Avec plaisir!',
'Oui chef!');
$affirmation = $affirmations[rand(0,count($affirmations)-1)];
$response = array('responses'=>array(
array('type'=>'talk','sentence'=>$affirmation)
)
);
$json = json_encode($response);
echo ($json=='[]'?'{}':$json);
}
}else{
$response = array('responses'=>array(
array('type'=>'talk','sentence'=>'Je ne vous connais pas, je refuse de faire ça!')
)
);
echo json_encode($response);
}
break;
}
}
Plugin::addJs("/js/main.js");
Plugin::addCss("/css/style.css");
Plugin::addHook("action_post_case", "door_action_door");
Plugin::addHook("node_display", "door_display");
Plugin::addHook("setting_bloc", "door_plugin_setting_page");
Plugin::addHook("setting_menu", "door_plugin_setting_menu");
Plugin::addHook("vocal_command", "door_vocal_command");
?>