@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 = ' '; } $response['content'] = $content; } ); break; case 'wireRelay_edit_widget': require_once(dirname(__FILE__).'/../dashboard/Widget.class.php'); $widget = new Widget(); $widget = $widget->getById($_['id']); $data = $widget->data(); $relayManager = new WireRelay(); $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 'wireRelay_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 wirerelay_plugin_change_state($engine,$state){ $wireRelay = new WireRelay(); $wireRelay = $wireRelay->getById($engine); Gpio::mode($wireRelay->pin,'out'); //Permet l'inversion des commandes en cas de relais inversé $state = $state - $wireRelay->reverse; if($wireRelay->pulse==0){ Gpio::write($wireRelay->pin,$state); }else{ Gpio::pulse($wireRelay->pin,$wireRelay->pulse,1); } //Reference device state change for other plugins $device = new Device(); $device = $device->load(array('plugin'=>'wireRelay','uid'=>$wireRelay->id)); if(is_object($device)){ $device->setValue('value',$state); $device->save(); } } function wireRelay_plugin_setting_page(){ global $_,$myUser,$conf; if(isset($_['section']) && $_['section']=='wireRelay' ){ if(!$myUser) throw new Exception('Vous devez être connecté pour effectuer cette action'); $wireRelayManager = new WireRelay(); $wireRelays = $wireRelayManager->populate(); $roomManager = new Room(); $rooms = $roomManager->loadAll(array('state'=>'0')); $selected = new WireRelay(); $selected->pulse = 0; $selected->icon = 'fa fa-flash'; //Si on est en mode modification if (isset($_['id'])) $selected = $wireRelayManager->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 filaires

Ajouter/Modifier un relais filaire
$icon){ if($i%6==0) echo '
'; ?>
get('VOCAL_ENTITY_NAME') ?>, get('VOCAL_ENTITY_NAME') ?>, laisser à zéro pour désactiver le mode impulsion reverse?'checked="checked"':''; ?> id="reverseWireRelay" /> Cocher si votre relais fonctionne dans le mauvais sens


Consulter les relais filaires existants load(array('id'=>$wireRelay->room)); ?>
Nom Description Pin GPIO Pièce Impulsion
name; ?> description; ?> pin; ?> getName():'Pièce supprimée'); ?> pulse; ?>
Relais filaires'; } function wireRelay_plugin_listen($command,$text,$confidence){ //echo 'diction de la commande : '.$command; } function wireRelay_plugin_widget(&$widgets){ $widgets[] = array( 'uid' => 'dash_wirerelay', 'icon' => 'fa fa-flash', 'label' => 'Relais', 'background' => '#50597b', 'color' => '#fffffff', 'onLoad' => 'action.php?action=wireRelay_load_widget', 'onEdit' => 'action.php?action=wireRelay_edit_widget', 'onSave' => 'action.php?action=wireRelay_save_widget', ); } Plugin::addCss("/css/main.css"); Plugin::addJs("/js/main.js"); //Lie wireRelay_plugin_setting_page a la zone réglages Plugin::addHook("setting_bloc", "wireRelay_plugin_setting_page"); //Lie wireRelay_plugin_setting_menu au menu de réglages Plugin::addHook("setting_menu", "wireRelay_plugin_setting_menu"); //Lie wirerelay_plugin_action a la page d'action qui perme d'effecuer des actionx ajax ou ne demdnant pas de retour visuels Plugin::addHook("action_post_case", "wirerelay_plugin_action"); //Lie wirerelay_plugin_vocal_command a la gestion de commandes vocales proposées par yana Plugin::addHook("vocal_command", "wirerelay_plugin_vocal_command"); //Lie wireRelay_plugin_widget aux widgets de la dashboard Plugin::addHook("widgets", "wireRelay_plugin_widget"); Plugin::addHook("listen", "wireRelay_plugin_listen"); ?>