コード例 #1
0
ファイル: H2HALDevice.php プロジェクト: bangnaga/HomeOverlord
 function state($value = null, $reason = 'unknown')
 {
     if (!approveAction(array('type' => 'deviceCommand', 'device' => $this->deviceDS['d_key'], 'deviceType' => $this->type, 'ds' => $this->deviceDS, 'command' => $commandType, 'value' => $value, 'by' => $by))) {
         return;
     }
     if ($this->deviceDS['d_auto'] != 'A' && $GLOBALS['command-mode'] == 'trigger') {
         return;
     }
     if ($value != null) {
         return $this->handler->setState($value, $reason);
     } else {
         return $this->handler->getState();
     }
 }
コード例 #2
0
ファイル: h2ha.php プロジェクト: bangnaga/HomeOverlord
function deviceCommand($deviceKey, $commandType, $value, $by = 'API', $fireEvent = false)
{
    $device = getDeviceDS($deviceKey);
    if (!approveAction(array('type' => 'deviceCommand', 'device' => $deviceKey, 'deviceType' => $device['d_type'], 'ds' => $device, 'command' => $commandType, 'value' => $value, 'by' => $by))) {
        return;
    }
    if ($device['d_auto'] != 'A' && $GLOBALS['command-mode'] == 'trigger') {
        return;
    }
    $GLOBALS['log'][$device['d_key']] = array('type' => 'deviceCommand', 'device' => $deviceKey, 'param' => $commandType, 'value' => $value);
    $config = json_decode($device['d_config'], true);
    if (sizeof($device) > 0 && $device['d_state'] != $value) {
        if ($device['d_bus'] == 'HE') {
            $pv = $value + 0;
            $pv = reviewParams($device, $commandType, $pv);
            $reqUrl = 'http://localhost:1080/?cmd=update&bus=' . $device['d_bus'] . '&param=' . $commandType . '&key=' . $device['d_key'] . '&stxt=' . urlencode(first($GLOBALS['command-source'], $by)) . '&id=' . $device['d_id'] . '&value=' . $pv;
            cqrequest(array(array('url' => $reqUrl)));
        } else {
            if ($device['d_bus'] == 'HM') {
                sendHMCommand($device, $commandType, $value, first($GLOBALS['command-source'], $by), $config, $fireEvent);
                return;
            }
        }
        $sds = array('si_bus' => $device['d_bus'], 'si_name' => $device['d_id'], 'si_param' => $commandType, 'si_value' => $pv, 'si_time' => time(), 'si_devicekey' => $device['d_key'], 'si_by' => $by, 'si_event' => $GLOBALS['command-source'], 'si_mode' => 'TX', 'si_uid' => $_SESSION['uid'] + 0, 'si_ip' => first($_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR']));
        o(db)->commit('stateinfo', $sds);
        /*WriteToFile('log/stats.'.gmdate('Y-m').'.log', 
          json_encode(array(
            'type' => 'dp', 'key' => $device['d_key'], 'id' => $device['d_id'], 'bus' => $device['d_bus'], 'param' => $commandType, 'value' => $pv, 'tr' => 'tx')).
          chr(10)
          );*/
        $device['d_state'] = $value;
        $device['d_statustext'] = first($GLOBALS['command-source'], $by);
        $device['d_statuschanged'] = time();
        o(db)->commit('devices', $device);
    }
}