class BattStatus():
  def __init__(self, prefs):
    self.prefs = prefs
    self.battBalance = BattBalance(prefs, self)
    self.last_acpi = None
  def getBattInfo(self, batt_id):
    if batt_id == 0:
      return self.batt0
    elif batt_id == 1:
      return self.batt1
    else:
      return None
  def getPowerDisplay(self):
    disp = self.prefs.display_power_usage.lower()
    if disp == 'average' or (disp == 'now' and self.prefs.use_acpi):
      p0 = int(float(self.batt0.power_avg))
      p1 = int(float(self.batt1.power_avg))
    elif disp == 'now':
      p0 = int(float(self.batt0.power_now))
      p1 = int(float(self.batt1.power_now))
    else:
      return ''

    if p0 != 0:
      p = p0
    else:
      p = p1
    return "%.1fW" % (p/1000.0)
  def update(self, prefs):
    if self.last_acpi != self.prefs.use_acpi:
      if self.prefs.use_acpi:
        self.last_acpi = True
        self.ac = ACInfoAcpi()
        self.batt0 = BattInfoAcpi(0)
        self.batt1 = BattInfoAcpi(1)
      else:
        self.last_acpi = False
        self.ac = ACInfoSmapi()
        self.batt0 = BattInfoSmapi(0)
        self.batt1 = BattInfoSmapi(1)

    self.ac.update(prefs)
    self.batt0.update(prefs)
    self.batt1.update(prefs)
    self.battBalance.update()
  def isEitherInstalled(self):
    return self.batt0.isInstalled() or self.batt1.isInstalled()
  def isEitherCharging(self):
    return self.batt0.isCharging() or self.batt1.isCharging()
  def isEitherDischarging(self):
    return self.batt0.isDischarging() or self.batt1.isDischarging()
  def getTotalRemainingPercent(self):
    rem_cap = 0
    max_cap = 0
    if self.batt0.isInstalled():
      rem_cap = rem_cap + int(float(self.batt0.remaining_capacity))
      max_cap = max_cap + int(float(self.batt0.last_full_capacity))
    if self.batt1.isInstalled():
      rem_cap = rem_cap + int(float(self.batt1.remaining_capacity))
      max_cap = max_cap + int(float(self.batt1.last_full_capacity))
    if max_cap == 0:
      return 0
    return int(100 * (float(rem_cap) / float(max_cap)))
 def __init__(self, prefs):
   self.prefs = prefs
   self.battBalance = BattBalance(prefs, self)
   self.last_acpi = None
Exemple #3
0
class BattStatus():
  def __init__(self, prefs):
    self.prefs = prefs
    self.battBalance = BattBalance(prefs, self)
    self.last_interface = None
  def getBattInfo(self, batt_id):
    if batt_id == 0:
      return self.batt0
    elif batt_id == 1:
      return self.batt1
    else:
      return None
  def getPowerDisplay(self):
    disp = self.prefs['displayPowerUsage'].lower()
    if disp == 'now' and self.prefs['interface'] != Interface.SMAPI:
      disp = 'average'

    if disp == 'average':
      p0 = int(float(self.batt0.power_avg))
      p1 = int(float(self.batt1.power_avg))
    elif disp == 'now':
      p0 = int(float(self.batt0.power_now))
      p1 = int(float(self.batt1.power_now))
    else:
      return ''

    if p0 != 0:
      p = p0
    else:
      p = p1
    return "%.1fW" % (p/1000.0)
  def update(self, prefs):
    if self.last_interface != self.prefs['interface']:
      self.last_interface = self.prefs['interface']
      if self.prefs['interface'] == Interface.SMAPI:
        self.ac = ACInfoSmapi()
        self.batt0 = BattInfoSmapi(0)
        self.batt1 = BattInfoSmapi(1)
      elif self.prefs['interface'] == Interface.ACPI:
        self.ac = ACInfoAcpi()
        self.batt0 = BattInfoAcpi(0)
        self.batt1 = BattInfoAcpi(1)
      elif self.prefs['interface'] == Interface.ACPI_OLD:
        self.ac = ACInfoAcpiOld()
        self.batt0 = BattInfoAcpiOld(0)
        self.batt1 = BattInfoAcpiOld(1)

    self.ac.update(prefs)
    self.batt0.update(prefs)
    self.batt1.update(prefs)
    self.battBalance.update()
  def isEitherInstalled(self):
    return self.batt0.isInstalled() or self.batt1.isInstalled()
  def isEitherCharging(self):
    return self.batt0.isCharging() or self.batt1.isCharging()
  def isEitherDischarging(self):
    return self.batt0.isDischarging() or self.batt1.isDischarging()
  def getTotalRemainingPercent(self):
    rem_cap = 0
    max_cap = 0
    if self.batt0.isInstalled():
      rem_cap = rem_cap + int(float(self.batt0.remaining_capacity))
      max_cap = max_cap + int(float(self.batt0.last_full_capacity))
    if self.batt1.isInstalled():
      rem_cap = rem_cap + int(float(self.batt1.remaining_capacity))
      max_cap = max_cap + int(float(self.batt1.last_full_capacity))
    if max_cap == 0:
      return 0
    return int(100 * (float(rem_cap) / float(max_cap)))