@link Http://blog.idleman.fr @licence Cc -by-nc-sa @version 1.1 @description Plugin de gestion des relais radio 433mhz au protocole home easy (compatible chacon et prises "maison" du blog.idleman.fr) */ //On appelle les entités de base de données require_once(dirname(__FILE__).'/RadioRelay.class.php'); //Cette fonction ajoute une commande vocale function radiorelay_plugin_vocal_command(&$response,$actionUrl){ global $conf; $radioRelayManager = new RadioRelay(); $radioRelays = $radioRelayManager->populate(); foreach($radioRelays as $radioRelay){ if(!empty($radioRelay->onCommand)) $response['commands'][] = array('command'=>$conf->get('VOCAL_ENTITY_NAME').', '.$radioRelay->onCommand,'url'=>$actionUrl.'?action=radioRelay_vocal_change_state&engine='.$radioRelay->id.'&state=1','confidence'=>('0.90'+$conf->get('VOCAL_SENSITIVITY'))); if(!empty($radioRelay->offCommand)) $response['commands'][] = array('command'=>$conf->get('VOCAL_ENTITY_NAME').', '.$radioRelay->offCommand,'url'=>$actionUrl.'?action=radioRelay_vocal_change_state&engine='.$radioRelay->id.'&state=0','confidence'=>('0.90'+$conf->get('VOCAL_SENSITIVITY'))); } } //cette fonction comprends toutes les actions du plugin qui ne nécessitent pas de vue html function radiorelay_plugin_action(){ global $_,$conf,$myUser; //Action de réponse à la commande vocale "Yana, commande de test" switch($_['action']){ case 'radioRelay_save_radioRelay': Action::write( function($_,&$response){ $radioRelayManager = new RadioRelay(); if(empty($_['nameRadioRelay'])) throw new Exception("Le nom est obligatoire"); if(!is_numeric($_['radioCodeRadioRelay'])) throw new Exception("Le code radio est obligatoire et doit être numerique"); $radioRelay = !empty($_['id']) ? $radioRelayManager->getById($_['id']): new RadioRelay(); $radioRelay->name = $_['nameRadioRelay']; $radioRelay->description = $_['descriptionRadioRelay']; $radioRelay->room = $_['roomRadioRelay']; $radioRelay->pulse = $_['pulseRadioRelay']; $radioRelay->onCommand = $_['onRadioRelay']; $radioRelay->offCommand = $_['offRadioRelay']; $radioRelay->icon = $_['iconRadioRelay']; $radioRelay->radiocode = $_['radioCodeRadioRelay']; $radioRelay->save(); $response['message'] = 'Relais enregistré avec succès'; }, array('plugin_radiorelay'=>'c') ); break; case 'radioRelay_delete_radioRelay': Action::write( function($_,$response){ $radioRelayManager = new RadioRelay(); $radioRelayManager->delete(array('id'=>$_['id'])); }, array('plugin_radiorelay'=>'d') ); break; case 'radioRelay_plugin_setting': Action::write( function($_,&$response){ global $conf; $conf->put('plugin_radioRelay_emitter_pin',$_['emiterPin']); $conf->put('plugin_radioRelay_emitter_code',$_['emiterCode']); $response['message'] = 'Configuration enregistrée'; }, array('plugin_radiorelay'=>'c') ); break; case 'radioRelay_manual_change_state': Action::write( function($_,&$response){ radiorelay_plugin_change_state($_['engine'],$_['state']); }, array('plugin_radiorelay'=>'c') ); break; case 'radioRelay_vocal_change_state': global $_,$myUser; try{ $response['responses'][0]['type'] = 'talk'; if(!$myUser->can('plugin_radiorelay','u')) throw new Exception ('Je ne vous connais pas, ou alors vous n\'avez pas le droit, je refuse de faire ça!'); radiorelay_plugin_change_state($_['engine'],$_['state']); $response['responses'][0]['sentence'] = Personality::response('ORDER_CONFIRMATION'); }catch(Exception $e){ $response['responses'][0]['sentence'] = Personality::response('WORRY_EMOTION').'! '.$e->getMessage(); } $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'radioRelay_plugin_setting': Action::write( function($_,&$response){ global $conf; $conf->put('plugin_radioRelay_emitter_pin',$_['emiterPin']); $conf->put('plugin_radioRelay_emitter_code',$_['emiterCode']); $response['message'] = 'Configuration modifiée avec succès'; }, array('plugin_radiorelay'=>'u') ); break; case 'radioRelay_load_widget': require_once(dirname(__FILE__).'/../dashboard/Widget.class.php'); Action::write( function($_,&$response){ $widget = new Widget(); $widget = $widget->getById($_['id']); $data = $widget->data(); $content = ''; if(empty($data['relay'])){ $content = 'Choisissez un relais en cliquant sur l \'icone de la barre du widget'; }else{ $radioPermission = fileperms(Plugin::path().'radioEmission')!='36333'; if(($radioPermission !='36333') && ($radioPermission !='35913')) $content .= '
Attention, les droits vers le fichier
radioEmission sont mal réglés.
Référez vous à la doc pour les régler
'; $relay = new RadioRelay(); $relay = $relay->getById($data['relay']); $response['title'] = $relay->name; $content .= ' '; } $response['content'] = $content; } ); break; case 'radioRelay_edit_widget': require_once(dirname(__FILE__).'/../dashboard/Widget.class.php'); $widget = new Widget(); $widget = $widget->getById($_['id']); $data = $widget->data(); $relayManager = new RadioRelay(); $relays = $relayManager->populate(); $content = '

Relais ciblé

'; if(count($relays) == 0){ $content = 'Aucun relais existant dans yana, Créer un relais ?'; }else{ $content .= ''; } echo $content; break; case 'radioRelay_save_widget': require_once(dirname(__FILE__).'/../dashboard/Widget.class.php'); $widget = new Widget(); $widget = $widget->getById($_['id']); $data = $widget->data(); $data['relay'] = $_['relay']; $widget->data($data); $widget->save(); echo $content; break; } } function radiorelay_plugin_change_state($engine,$state){ global $conf; $radioRelay = new RadioRelay(); $radioRelay = $radioRelay->getById($engine); $cmd = dirname(__FILE__).'/radioEmission '.$conf->get('plugin_radioRelay_emitter_pin').' '.$conf->get('plugin_radioRelay_emitter_code').' '.$radioRelay->radiocode.' '; $cmd .= $radioRelay->pulse ==0 ? ($state==1?'on':'off') : 'pulse '.$radioRelay->pulse; $radioRelay->state = $state; Functions::log('Launch system command : '.$cmd); system($cmd,$out); $radioRelay->save(); } function radioRelay_plugin_setting_page(){ global $_,$myUser,$conf; if(isset($_['section']) && $_['section']=='radioRelay' ){ if(!$myUser) throw new Exception('Vous devez être connecté pour effectuer cette action'); $radioRelayManager = new RadioRelay(); $radioRelays = $radioRelayManager->populate(); $roomManager = new Room(); $rooms = $roomManager->loadAll(array('state'=>'0')); $selected = new RadioRelay(); $selected->pulse = 0; $selected->icon = 'fa fa-flash'; //Si on est en mode modification if (isset($_['id'])) $selected = $radioRelayManager->getById($_['id']); $icons = array( 'fa fa-lightbulb-o', 'fa fa-power-off', 'fa fa-flash', 'fa fa-gears', 'fa fa-align-justify', 'fa fa-adjust', 'fa fa-arrow-circle-o-right', 'fa fa-desktop', 'fa fa-music', 'fa fa-bell-o', 'fa fa-beer', 'fa fa-bullseye', 'fa fa-automobile', 'fa fa-book', 'fa fa-bomb', 'fa fa-clock-o', 'fa fa-cutlery', 'fa fa-microphone', 'fa fa-tint' ); ?>

Relais

Gestion des relais radios

Ajouter/Modifier un relais radio
$icon){ if($i%6==0) echo '
'; ?>
get('VOCAL_ENTITY_NAME') ?>, get('VOCAL_ENTITY_NAME') ?>, laisser à zéro pour désactiver le mode impulsion


Consulter les relais radios existants load(array('id'=>$radioRelay->room)); ?>
Nom Description Code Pièce Impulsion
name; ?> description; ?> radiocode; ?> getName(); ?> pulse; ?>
Relais radio'; } function radioRelay_plugin_widget(&$widgets){ $widgets[] = array( 'uid' => 'dash_radiorelay', 'icon' => 'fa fa-bullseye', 'label' => 'Relais Radio', 'background' => '#50597b', 'color' => '#fffffff', 'onLoad' => 'action.php?action=radioRelay_load_widget', 'onEdit' => 'action.php?action=radioRelay_edit_widget', 'onSave' => 'action.php?action=radioRelay_save_widget', ); } function radioRelay_plugin_preference_menu(){ global $_; echo '
  • Radio Relais
  • '; } function radioRelay_plugin_preference_page(){ global $myUser,$_,$conf; if((isset($_['section']) && $_['section']=='preference' && @$_['block']=='radioRelay' ) ){ if($myUser!=false){ ?>

    Vous devez être connecté