/** * getBattery * * @access private * @return array of battery status */ public function getBattery() { // Time? if (!empty($this->settings['timer'])) { $t = new LinfoTimerStart('Batteries'); } // Return values $return = array(); // Here they should be $bats = (array) @glob('/sys/class/power_supply/BAT*', GLOB_NOSORT); // Get vals for each battery foreach ($bats as $b) { foreach (array($b . '/manufacturer', $b . '/status') as $f) { if (!is_file($f)) { continue 2; } } // Get these from the simple text files switch (true) { case is_file($b . '/energy_full'): $charge_full = LinfoCommon::getIntFromFile($b . '/energy_full'); $charge_now = LinfoCommon::getIntFromFile($b . '/energy_now'); break; case is_file($b . '/charge_full'): $charge_full = LinfoCommon::getIntFromFile($b . '/charge_full'); $charge_now = LinfoCommon::getIntFromFile($b . '/charge_now'); break; default: continue; break; } // Alleged percentage $percentage = $charge_now != 0 && $charge_full != 0 ? round($charge_now / $charge_full, 4) * 100 : '?'; // Save result set $return[] = array('charge_full' => $charge_full, 'charge_now' => $charge_now, 'percentage' => is_numeric($percentage) && $percentage > 100 ? 100 : $percentage, 'device' => LinfoCommon::getContents($b . '/manufacturer') . ' ' . LinfoCommon::getContents($b . '/model_name', 'Unknown'), 'state' => LinfoCommon::getContents($b . '/status', 'Unknown')); } // Give it return $return; }
/** * @test */ public function getIntFromFile() { $file = LINFO_TESTDIR . '/files/intfile.txt'; $this->assertEquals(101, LinfoCommon::getIntFromFile($file)); }