@link http://blog.idleman.fr @licence CC by nc sa @version 1.0.0 @description Permet la récuperations d'informations de temperatures, humidités, lumière, mouvement et sons dans une pièce a travers la sonde yana "poolp" */ function propise_vocal_command(&$response,$actionUrl){ global $conf; $response['commands'][] = array( 'command'=>$conf->get('VOCAL_ENTITY_NAME').' diagnostique de la pièce', 'callback'=>'propise_diagnostic', 'confidence'=>0.8); } function propise_diagnostic($text,$confidence,$parameters,$myUser){ global $conf; require_once('Sensor.class.php'); require_once('Data.class.php'); $data = new Data(); $sensor = Sensor::load(array('location'=>$text)); $data = Data::load(array('sensor'=>$sensor->id)); $cli = new Client(); $cli->connect(); $cli->talk("Diagnostique pièce : ".$text); $cli->talk("Humidité : ".$data->humidity .", température : ".$data->temperature .", Luminosité : ".$data->temperature ."%, mouvement : ".$data->mouvment ); $cli->disconnect(); } function propise_action(){ global $_,$conf; switch($_['action']){ case 'propise_save_sensor': Action::write( function($_,&$response){ require_once('Sensor.class.php'); if(empty($_['labelSensor'])) throw new Exception("Le nom est obligatoire"); $sensor = !empty($_['id']) ? Sensor::getById($_['id']): new Sensor(); $sensor->label = $_['labelSensor']; $sensor->location = $_['locationSensor']; $sensor->save(); //Reference device for other plugins $device = new Device(); $device->label = $sensor->label; $device->plugin = 'propise'; $device->type = Device::CAPTOR; $device->location = $sensor->location; $device->icon = 'fa-heartbeat'; $device->setValue('humidity',0); $device->setValue('temperature',0); $device->setValue('light',0); $device->setValue('mouvment',0); $device->setValue('sound',0); $device->state = 1; $device->uid = $sensor->id; $device->save(); $response['message'] = 'Sonde enregistrée avec succès'; }, array('propise'=>'c') ); break; case 'propise_delete_sensor': Action::write( function($_,$response){ require_once('Sensor.class.php'); Data::delete(array('sensor'=>$_['id'])); Sensor::deleteById($_['id']); }, array('propise'=>'d') ); break; case 'propise_get_data': Action::write( function($_,&$response){ require_once('Sensor.class.php'); require_once('Data.class.php'); $datas = Data::loadAll(array('sensor'=>$_['id']),'time DESC'); $response['light'] = propise_convert_light($datas[0]->light); $response['humidity'] = $datas[0]->humidity; $response['temperature'] = $datas[0]->temperature; $response['mouvment'] = $datas[0]->mouvment; }, array('propise'=>'r') ); break; case 'propise_add_data': require_once('Sensor.class.php'); require_once('Data.class.php'); $sensor = Sensor::getById($_['id']); if($sensor == null || $sensor->id==0) return; $sensor->ip = $_['ip']; $sensor->save(); $data = new Data(); $data->time = time(); $data->humidity = $_['humidity']; $data->temperature = $_['temperature']; $data->light = $_['light']; $data->mouvment = $_['mouvment']; $data->sensor = $sensor->id; $data->save(); echo '1'; break; case 'propise_select_widget_menu': require_once(__DIR__.'/../dashboard/Widget.class.php'); Action::write( function($_,&$response){ $widget = new Widget(); $widget = $widget->getById($_['id']); $data = $widget->data(); $data['menu'] = $_['menu']; $widget->data($data); $widget->save(); }); break; case 'propise_load_widget': require_once(__DIR__.'/../dashboard/Widget.class.php'); Action::write( function($_,&$response){ $widget = new Widget(); $widget = $widget->getById($_['id']); $parameters = $widget->data(); if(empty($parameters['sensor'])){ $content = 'Choisissez une localisation en cliquant sur l \'icone de la barre du widget'; }else{ global $conf; require_once('Data.class.php'); require_once('Sensor.class.php'); $sensor = Sensor::getById($parameters['sensor']); $datas = Data::loadAll(array('sensor'=>$sensor->id),'time DESC',1); $response['title'] = $sensor->label; $content = ' '; $content .= '
'; $content .= ' '; } $response['content'] = $content; } ); break; case 'propise_edit_widget': require_once(dirname(__FILE__).'/../dashboard/Widget.class.php'); require_once(dirname(__FILE__).'/Sensor.class.php'); $widget = new Widget(); $widget = $widget->getById($_['id']); $data = $widget->data(); $sensor = new Sensor(); $sensors = $sensor->populate(); $content = 'Gestion des multi-sondes