gillstrom / battery-level

Get current battery level

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't work under Ubuntu on a Toshiba Satellite laptop.

ed-davies opened this issue · comments

edavies@george:~/node_modules/battery-level$ node cli.js 
/home/edavies/node_modules/battery-level/index.js:24
        res = res.percentage.slice(0, res.percentage.length);
                            ^
TypeError: Cannot read property 'slice' of undefined
    at /home/edavies/node_modules/battery-level/index.js:24:23
    at /home/edavies/node_modules/battery-level/node_modules/linux-battery/index.js:29:3
    at ChildProcess.exithandler (child_process.js:742:7)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Socket.<anonymous> (child_process.js:1183:11)
    at Socket.emit (events.js:107:17)
    at Pipe.close (net.js:485:12)

Ubuntu 14.04 LTS.

$ uname -a
Linux george 3.16.0-44-generic #59~14.04.1-Ubuntu SMP Tue Jul 7 15:07:27 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

$ upower --version
UPower client version 0.9.23
UPower daemon version 0.9.23

Toshiba Satellite C50-B-189

The problem seems to be that the battery is called …BAT1 rather than …BAT0

$ upower -i /org/freedesktop/UPower/devices/battery_BAT0
failed to set path: cannot refresh: Cannot get device properties for /org/freedesktop/UPower/devices/battery_BAT0: Couldn't call GetAll() to get properties for /org/freedesktop/UPower/devices/battery_BAT0: Method "GetAll" with signature "s" on interface "org.freedesktop.DBus.Properties" doesn't exist

$ upower -i /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  vendor:               TOSHIBA
  model:                PABAS0241231
  serial:               000000000000D01B
  power supply:         yes
  updated:              Fri 24 Jul 2015 17:03:42 BST (1498 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               fully-charged
    energy:              45 Wh
    energy-empty:        0 Wh
    energy-full:         45 Wh
    energy-full-design:  45 Wh
    energy-rate:         1.905 W
    voltage:             16.988 V
    percentage:          100%
    capacity:            100%
    technology:          lithium-ion

It might be relevant that I'm using a wireless mouse with a battery:

edavies@george:~/node_modules/battery-level$ upower --dump
Device: /org/freedesktop/UPower/devices/line_power_ACAD
  native-path:          ACAD
  power supply:         yes
  updated:              Fri 24 Jul 2015 17:03:37 BST (1583 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    online:             yes

Device: /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  vendor:               TOSHIBA
  model:                PABAS0241231
  serial:               000000000000D01B
  power supply:         yes
  updated:              Fri 24 Jul 2015 17:03:42 BST (1578 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               fully-charged
    energy:              45 Wh
    energy-empty:        0 Wh
    energy-full:         45 Wh
    energy-full-design:  45 Wh
    energy-rate:         1.905 W
    voltage:             16.988 V
    percentage:          100%
    capacity:            100%
    technology:          lithium-ion

Device: /org/freedesktop/UPower/devices/mouse_0003o046DoC52Fx0002
  native-path:          /sys/devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4.2/1-4.2:1.1/0003:046D:C52F.0002
  vendor:               Logitech, Inc.
  model:                M185/M225
  serial:               0320E001
  power supply:         no
  updated:              Fri 24 Jul 2015 17:29:25 BST (35 seconds ago)
  has history:          yes
  has statistics:       no
  mouse
    present:             yes
    rechargeable:        yes
    state:               discharging
    percentage:          90%

Daemon:
  daemon-version:  0.9.23
  can-suspend:     yes
  can-hibernate:   no
  on-battery:      no
  on-low-battery:  no
  lid-is-closed:   no
  lid-is-present:  yes
  is-docked:       no

Any idea @kevva?

Need to make sure it's actually the computers battery.

@ed-davies, could you log what you get from res on line 23 or something? And I've published a new version (1.3.0), could you test that too?

Added “console.log(res);” on line 23 which gave output:

{ failedToSetPath: 'cannot refresh' }

Yes, 1.3.0 works. Reports “100%” when running off mains power and “99%” after I'd pulled the plug for a minute or so.