Class: Battman::SmapiBattery

Inherits:
Battery
  • Object
show all
Defined in:
lib/battman/smapi_battery.rb

Constant Summary

Constants inherited from Battery

Battery::CONVERSIONS

Instance Method Summary collapse

Methods inherited from Battery

#full_energy_in, #initialize, #power_in, #remaining_charging_time_in, #remaining_energy_in, #remaining_running_time_in

Constructor Details

This class inherits a constructor from Battman::Battery

Instance Method Details

#full_energyObject



52
53
54
55
56
# File 'lib/battman/smapi_battery.rb', line 52

def full_energy
  energy_file = File.join(path, 'last_full_capacity')

  File.read(energy_file).to_f / 1000
end

#pathObject



6
7
8
# File 'lib/battman/smapi_battery.rb', line 6

def path
  @path ||= "/sys/devices/platform/smapi/BAT#{@index}"
end

#powerObject



34
35
36
37
38
# File 'lib/battman/smapi_battery.rb', line 34

def power
  power_file = File.join(path, 'power_avg')

  File.read(power_file).to_f / 1000
end

#remaining_charging_timeObject

Raises:



25
26
27
28
29
30
31
32
# File 'lib/battman/smapi_battery.rb', line 25

def remaining_charging_time
  charging_time_file = File.join(path, 'remaining_charging_time')

  file_content = File.read(charging_time_file)

  raise WrongStateError if file_content == "not_charging\n"
  file_content.to_i * 60
end

#remaining_energyObject



46
47
48
49
50
# File 'lib/battman/smapi_battery.rb', line 46

def remaining_energy
  energy_file = File.join(path, 'remaining_capacity')

  File.read(energy_file).to_f / 1000
end

#remaining_percentObject



10
11
12
13
14
# File 'lib/battman/smapi_battery.rb', line 10

def remaining_percent
  percent_file = File.join(path, 'remaining_percent')

  File.read(percent_file).to_i
end

#remaining_running_timeObject

Raises:



16
17
18
19
20
21
22
23
# File 'lib/battman/smapi_battery.rb', line 16

def remaining_running_time
  running_time_file = File.join(path, 'remaining_running_time')

  file_content = File.read(running_time_file)

  raise WrongStateError if file_content == "not_discharging\n"
  file_content.to_i * 60
end

#stateObject



40
41
42
43
44
# File 'lib/battman/smapi_battery.rb', line 40

def state
  state_file = File.join(path, 'state')

  File.read(state_file).chomp.to_sym
end