当前位置: 首页>>代码示例>>PHP>>正文


PHP Device::setValue方法代码示例

本文整理汇总了PHP中Device::setValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Device::setValue方法的具体用法?PHP Device::setValue怎么用?PHP Device::setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Device的用法示例。


在下文中一共展示了Device::setValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: wirerelay_plugin_action

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->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']);
                $data = $widget->data();
                if (empty($data['relay'])) {
                    $content = 'Choisissez un relais en cliquant sur l \'icone <i class="fa fa-wrench"></i> de la barre du widget';
                } else {
                    $relay = new WireRelay();
                    $relay = $relay->getById($data['relay']);
                    $response['title'] = $relay->name;
                    $content = '
						<!-- CSS -->
						<style>
							
							.relay_pane {
							    background: none repeat scroll 0 0 #50597b;
							    list-style-type: none;
							    margin: 0;
							    cursor:default;
							    width: 100%;
							}
							.relay_pane li {
							    background: none repeat scroll 0 0 #50597b;
							    display: inline-block;
							    margin: 0 1px 0 0;
							    padding: 10px;
							    cursor:default;
							    vertical-align: top;
//.........这里部分代码省略.........
开发者ID:kofeve,项目名称:yana-server,代码行数:101,代码来源:wireRelay.plugin.php

示例2: propise_action

function propise_action()
{
    global $_, $conf;
    switch ($_['action']) {
        case 'propise_save_sensor':
            Action::write(function ($_, &$response) {
                require_once 'Sensor.class.php';
                $sensor = new Sensor();
                if (empty($_['labelSensor'])) {
                    throw new Exception("Le nom est obligatoire");
                }
                if (empty($_['uidSensor'])) {
                    throw new Exception("L'UID est obligatoire");
                }
                $sensor = !empty($_['id']) ? $sensor->getById($_['id']) : new Sensor();
                $sensor->label = $_['labelSensor'];
                $sensor->location = $_['locationSensor'];
                $sensor->uid = $_['uidSensor'];
                $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';
                $sensor = new Sensor();
                $sensor->delete(array('id' => $_['id']));
            }, array('propise' => 'd'));
            break;
        case 'propise_add_data':
            /*for($i=0;$i<60;$i++){
            		$_ = array(
            		'uid'=>'sensor-2',
            		'humidity'=>rand(0,100),
            		'temperature'=>rand(0,100),
            		'light'=>rand(0,100),
            		'mouvment'=>rand(0,1),
            		'sound'=>rand(0,1)
            		);*/
            require_once 'Sensor.class.php';
            require_once 'Data.class.php';
            $sensor = new Sensor();
            $data = new Data();
            $sensor = $sensor->load(array('uid' => $_['uid']));
            if ($sensor == null || $sensor->id == 0) {
                return;
            }
            $data->time = time();
            //$data->time = strtotime(date('Ymd H:').$i.':00');
            $data->humidity = $_['humidity'];
            $data->temperature = $_['temperature'];
            $data->light = $_['light'];
            $data->mouvment = $_['mouvment'];
            $data->sound = $_['sound'];
            $data->sensor = $sensor->id;
            $data->save();
            //}
            break;
        case 'propise_load_widget':
            require_once dirname(__FILE__) . '/../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 <i class="fa fa-wrench"></i> de la barre du widget';
                } else {
                    global $conf;
                    require_once 'Data.class.php';
                    require_once 'Sensor.class.php';
                    $sensor = new Sensor();
                    $data = new Data();
                    $sensor = $sensor->getById($parameters['sensor']);
                    $datas = $data->loadAll(array('sensor' => $sensor->id), 'time DESC', 1);
                    $response['title'] = 'Sonde ' . $sensor->label . ' (' . $sensor->uid . ')';
                    $content = '
						<!-- CSS -->
						<style>
							.propise_view{
								background:#36B3E1;
								color:#ffffff;
								margin:0px;
								padding:10px;
								width:100%;
								list-style-type:none;
//.........这里部分代码省略.........
开发者ID:rikimaruneo,项目名称:yana-server,代码行数:101,代码来源:propise.plugin.php


注:本文中的Device::setValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。