private function _call()
    {

        // Time this
        $t = new Timer('apcaccess Extension');

        // Deal with calling it
        try {
            $result = $this->_CallExt->exec('apcaccess');
        } catch (Exception $e) {
            // messed up somehow
            Errors::add('apcaccess Extension', $e->getMessage());
            $this->_res = false;

            // Don't bother going any further
            return false;
        }

        // Store them here
        $this->_res = [];

        // Get name
        if (preg_match('/^UPSNAME\s+:\s+(.+)$/m', $result, $m)) {
            $this->_res['name'] = $m[1];
        }

        // Get model
        if (preg_match('/^MODEL\s+:\s+(.+)$/m', $result, $m)) {
            $this->_res['model'] = $m[1];
        }

        // Get battery voltage
        if (preg_match('/^BATTV\s+:\s+(\d+\.\d+)/m', $result, $m)) {
            $this->_res['volts'] = $m[1];
        }

        // Get charge percentage, and get it cool
        if (preg_match('/^BCHARGE\s+:\s+(\d+(?:\.\d+)?)/m', $result, $m)) {
            $charge = (int) $m[1];
            $this->_res['charge'] = '
					<div class="bar_chart">
						<div class="bar_inner" style="width: '.(int) $charge.'%;">
							<div class="bar_text">
								'.($charge ? $charge.'%' : '?').'
							</div>
						</div>
					</div>
			';
        }

        // Get time remaning
        if (preg_match('/^TIMELEFT\s+:\s+([\d\.]+)/m', $result, $m)) {
            $this->_res['time_left'] = Common::secondsConvert($m[1] * 60);
        }

        // Get status
        if (preg_match('/^STATUS\s+:\s+([A-Z]+)/m', $result, $m)) {
            $this->_res['status'] = $m[1] == 'ONBATT' ? 'On Battery' : ucfirst(strtolower($m[1]));
        }

        // Load percentage looking cool
        if (preg_match('/^LOADPCT\s+:\s+(\d+\.\d+)/m', $result, $m)) {
            $load = (int) $m[1];
            $this->_res['load'] = '
					<div class="bar_chart">
						<div class="bar_inner" style="width: '.(int) $load.'%;">
							<div class="bar_text">
								'.($load ? $load.'%' : '?').'
							</div>
						</div>
					</div>
			';
        }

        // Attempt getting wattage
        if (isset($load) && preg_match('/^NOMPOWER\s+:\s+(\d+)/m', $result, $m)) {
            $watts = (int) $m['1'];
            $this->_res['watts_used'] = $load * round($watts / 100);
        } else {
            $this->_res['watts_used'] = false;
        }

        // Apparent success
        return true;
    }
private function _call()
    {

        // Time this
        $t = new Timer('apcaccess Extension');

        // Deal with calling it
        try {
            $result = $this->_CallExt->exec('apcaccess');
        } catch (Exception $e) {
            // messed up somehow
            Errors::add('apcaccess Extension', $e->getMessage());
            $this->_res = false;

            // Don't bother going any further
            return false;
        }

        // Store them here
        $this->_res = [];

        // Get name
        if (preg_match('/^UPSNAME\s+:\s+(.+)$/m', $result, $m)) {
            $this->_res['name'] = $m[1];
        }

        // Get model
        if (preg_match('/^MODEL\s+:\s+(.+)$/m', $result, $m)) {
            $this->_res['model'] = $m[1];
        }

        // Get battery voltage
        if (preg_match('/^BATTV\s+:\s+(\d+\.\d+)/m', $result, $m)) {
            $this->_res['volts'] = $m[1];
        }

        // Get charge percentage, and get it cool
        if (preg_match('/^BCHARGE\s+:\s+(\d+(?:\.\d+)?)/m', $result, $m)) {
            $charge = (int) $m[1];
            $this->_res['charge'] = '
					<div class="bar_chart">
						<div class="bar_inner" style="width: '.(int) $charge.'%;">
							<div class="bar_text">
								'.($charge ? $charge.'%' : '?').'
							</div>
						</div>
					</div>
			';
        }

        // Get time remaning
        if (preg_match('/^TIMELEFT\s+:\s+([\d\.]+)/m', $result, $m)) {
            $this->_res['time_left'] = Common::secondsConvert($m[1] * 60);
        }

        // Get status
        if (preg_match('/^STATUS\s+:\s+([A-Z]+)/m', $result, $m)) {
            $this->_res['status'] = $m[1] == 'ONBATT' ? 'On Battery' : ucfirst(strtolower($m[1]));
        }

        // Load percentage looking cool
        if (preg_match('/^LOADPCT\s+:\s+(\d+\.\d+)/m', $result, $m)) {
            $load = (int) $m[1];
            $this->_res['load'] = '
					<div class="bar_chart">
						<div class="bar_inner" style="width: '.(int) $load.'%;">
							<div class="bar_text">
								'.($load ? $load.'%' : '?').'
							</div>
						</div>
					</div>
			';
        }

        // Attempt getting wattage
        if (isset($load) && preg_match('/^NOMPOWER\s+:\s+(\d+)/m', $result, $m)) {
            $watts = (int) $m['1'];
            $this->_res['watts_used'] = $load * round($watts / 100);
        } else {
            $this->_res['watts_used'] = false;
        }

        // Apparent success
        return true;
    }
private function _call ( ) { // Time this $ t = new Timer ( 'apcaccess Extension' ) ; // Deal with calling it try { $ result = $ this -> _CallExt -> exec ( 'apcaccess' ) ; } catch ( Exception $ e ) { // messed up somehow Errors :: add ( 'apcaccess Extension' , $ e -> getMessage ( ) ) ; $ this -> _res = false ; // Don't bother going any further return false ; } // Store them here $ this -> _res = [ ] ; // Get name if ( preg_match ( '/^UPSNAME\s+:\s+(.+)$/m' , $ result , $ m ) ) { $ this -> _res [ 'name' ] = $ m [ 1 ] ; } // Get model if ( preg_match ( '/^MODEL\s+:\s+(.+)$/m' , $ result , $ m ) ) { $ this -> _res [ 'model' ] = $ m [ 1 ] ; } // Get battery voltage if ( preg_match ( '/^BATTV\s+:\s+(\d+\.\d+)/m' , $ result , $ m ) ) { $ this -> _res [ 'volts' ] = $ m [ 1 ] ; } // Get charge percentage, and get it cool if ( preg_match ( '/^BCHARGE\s+:\s+(\d+(?:\.\d+)?)/m' , $ result , $ m ) ) { $ charge = ( int ) $ m [ 1 ] ; $ this -> _res [ 'charge' ] = '
					<div class="bar_chart">
						<div class="bar_inner" style="width: ' . ( int ) $ charge . '%;">
							<div class="bar_text">
								' . ( $ charge ? $ charge . '%' : '?' ) . '
							</div>
						</div>
					</div>
			' ; } // Get time remaning if ( preg_match ( '/^TIMELEFT\s+:\s+([\d\.]+)/m' , $ result , $ m ) ) { $ this -> _res [ 'time_left' ] = Common :: secondsConvert ( $ m [ 1 ] * 60 ) ; } // Get status if ( preg_match ( '/^STATUS\s+:\s+([A-Z]+)/m' , $ result , $ m ) ) { $ this -> _res [ 'status' ] = $ m [ 1 ] == 'ONBATT' ? 'On Battery' : ucfirst ( strtolower ( $ m [ 1 ] ) ) ; } // Load percentage looking cool if ( preg_match ( '/^LOADPCT\s+:\s+(\d+\.\d+)/m' , $ result , $ m ) ) { $ load = ( int ) $ m [ 1 ] ; $ this -> _res [ 'load' ] = '
					<div class="bar_chart">
						<div class="bar_inner" style="width: ' . ( int ) $ load . '%;">
							<div class="bar_text">
								' . ( $ load ? $ load . '%' : '?' ) . '
							</div>
						</div>
					</div>
			' ; } // Attempt getting wattage if ( isset ( $ load ) && preg_match ( '/^NOMPOWER\s+:\s+(\d+)/m' , $ result , $ m ) ) { $ watts = ( int ) $ m [ '1' ] ; $ this -> _res [ 'watts_used' ] = $ load * round ( $ watts / 100 ) ; } else { $ this -> _res [ 'watts_used' ] = false ; } // Apparent success return true ; }
call apcaccess and parse it
call apcaccess and parse it