@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 .= '
Gestion des relais radios