@link Http://blog.idleman.fr @licence Cc -by-nc-sa @version 1.1 @description Prise relais filaire */ //On appelle les entités de base de données include('WireRelay.class.php'); //Cette fonction ajoute une commande vocale function wirerelay_plugin_vocal_command(&$response,$actionUrl){ global $conf; $wireRelayManager = new WireRelay(); $wireRelays = $wireRelayManager->populate(); foreach($wireRelays as $wireRelay){ if(!empty($wireRelay->oncommand)) $response['commands'][] = array('command'=>$conf->get('VOCAL_ENTITY_NAME').', '.$wireRelay->oncommand,'url'=>$actionUrl.'?action=wireRelay_vocal_change_state&engine='.$wireRelay->id.'&state=1','confidence'=>('0.90'+$conf->get('VOCAL_SENSITIVITY'))); if(!empty($wireRelay->offcommand)) $response['commands'][] = array('command'=>$conf->get('VOCAL_ENTITY_NAME').', '.$wireRelay->offcommand,'url'=>$actionUrl.'?action=wireRelay_vocal_change_state&engine='.$wireRelay->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 wirerelay_plugin_action(){ global $_,$conf,$myUser; //Action de réponse à la commande vocale "Yana, commande de test" switch($_['action']){ case 'wireRelay_save_wireRelay': Action::write( function($_,&$response){ $wireRelayManager = new WireRelay(); if(empty($_['nameWireRelay'])) throw new Exception("Le nom est obligatoire"); if(!is_numeric($_['pinWireRelay'])) throw new Exception("Le PIN GPIO est obligatoire et doit être numerique"); $wireRelay = !empty($_['id']) ? $wireRelayManager->getById($_['id']): new WireRelay(); $wireRelay->name = $_['nameWireRelay']; $wireRelay->description = $_['descriptionWireRelay']; $wireRelay->pin = $_['pinWireRelay']; $wireRelay->room = $_['roomWireRelay']; $wireRelay->pulse = $_['pulseWireRelay']; $wireRelay->oncommand = $_['onWireRelay']; $wireRelay->offcommand = $_['offWireRelay']; $wireRelay->reverse = $_['reverseWireRelay']; $wireRelay->icon = $_['iconWireRelay']; $wireRelay->save(); //Reference device for other plugins $device = new Device(); $device->label = $wireRelay->name; $device->plugin = 'wireRelay'; $device->type = Device::ACTUATOR; $device->location = $wireRelay->room; $device->icon = $wireRelay->icon; $device->setValue('value',0); $device->state = 1; $device->uid = $wireRelay->id; $device->save(); $response['message'] = 'Relais enregistré avec succès'; }, array('plugin_wirerelay'=>'c') ); break; case 'wireRelay_delete_wireRelay': Action::write( function($_,$response){ $wireRelayManager = new WireRelay(); $wireRelayManager->delete(array('id'=>$_['id'])); }, array('plugin_wirerelay'=>'d') ); break; case 'wireRelay_plugin_setting': Action::write( function($_,$response){ $conf->put('plugin_wireRelay_emitter_pin',$_['emiterPin']); $conf->put('plugin_wireRelay_emitter_code',$_['emiterCode']); }, array('plugin_wirerelay'=>'c') ); break; case 'wireRelay_manual_change_state': Action::write( function($_,&$response){ wirerelay_plugin_change_state($_['engine'],$_['state']); }, array('plugin_wirerelay'=>'c') ); break; case 'wireRelay_vocal_change_state': global $_,$myUser; try{ $response['responses'][0]['type'] = 'talk'; if(!$myUser->can('plugin_wirerelay','u')) throw new Exception ('Je ne vous connais pas, ou alors vous n\'avez pas le droit, je refuse de faire ça!'); wirerelay_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 'wireRelay_load_widget': require_once(dirname(__FILE__).'/../dashboard/Widget.class.php'); Action::write( function($_,&$response){ $widget = new Widget(); $widget = $widget->getById($_['id']); if(!is_object($widget)) return; $data = $widget->data(); if(empty($data['relay'])){ $content = 'Choisissez un relais en cliquant sur l \'icone de la barre du widget'; }else{ $relay = new WireRelay(); $relay = $relay->getById($data['relay']); $response['title'] = $relay->name; $content = '
Gestion des relais filaires