Git Product home page Git Product logo

battery-level's Introduction


battery-level

Get current battery level

Install

$ npm install battery-level

Usage

const batteryLevel = require('battery-level');

(async () => {
	console.log(await batteryLevel());
	//=> 0.55
})();

API

batteryLevel()

Returns a Promise<number> with the battery level.

Related

battery-level's People

Contributors

amyli avatar bbuecherl avatar gillstrom avatar hafffe avatar kevva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

battery-level's Issues

Windows 10 return NaN

I'm trying to use your module as dependencies on an electron app. The code i run is very simple and the promise resolve a NaN value.

The os is Windows 10.

Cannot read property 'length' of undefined

when using the cli on lenovo laptop, it gives the following error

Cannot read property 'length' of undefined
on this file
battery-level/index.js:24
res = res.percentage.slice(0, res.percentage.length);

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

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

CLI: Gives error on Linux

Error: Command failed: upower -e

(upower:13207): libupower-glib-WARNING **: Couldn't enumerate devices: Message did not receive a reply (timeout by message bus)

(upower:13207): UPower-WARNING **: failed to enumerate: Message did not receive a reply (timeout by message bus)

    at ChildProcess.exithandler (child_process.js:202:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:850:16)
    at Socket.<anonymous> (internal/child_process.js:323:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:492:12)

Tested on Linux 3.16.0-71-generic x86_64

missing upower

Hi, this is great tool but I'd suggest you mention somewhere that it needs 'upower' to function on Linux. As that was not installed on my system by default.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.