npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@andysmithfal/polestar.js

v1.0.4

Published

This a barebones Node.js module to facilitate access to the Polestar API. It has been reverse engineered based on the browser based functionality that became availavle on Polestar.com in December 2023. It is currently in development and I make no promises

Downloads

3

Readme

polestar.js

This a barebones Node.js module to facilitate access to the Polestar API. It has been reverse engineered based on the browser based functionality that became availavle on Polestar.com in December 2023. It is currently in development and I make no promises as to its reliability!

Using the module

To install the module:

npm install @andysmithfal/polestar.js

In your code, you can require it as so:

const Polestar = require("@andysmithfal/polestar.js")

Provide your Polestar username and password to the constructor:

const polestar = new Polestar("email", "password")

To use the module, first log in. The module will obtain and store an authentication token which is valid for 1 hour. The module will automatically refresh this token when necessary. I am not currently sure how long the refresh token is valid for, but presumably it will not be invalidated if it is continued to be used.

await polestar.login()

You will then need to select a vehicle. getVehicles() will return an array of vehicles on the account.

const vehicles = await polestar.getVehicles()

You can then call setVehicle() to select a vehicle for the below methods. You can call this without any arguments to automatically select the first/only vehicle on the account, or you can specify a VIN as an argument.

polestar.setVehicle()

polestar.setVehicle("LPSAAAAAAAA000000")

Once logged in and a vehicle has been set, you can call getBattery() and getOdometer() to return vehcile information.

console.log(await polestar.getBattery())

Returns this:

{
  averageEnergyConsumptionKwhPer100Km: 23,
  batteryChargeLevelPercentage: 83,
  chargerConnectionStatus: 'CHARGER_CONNECTION_STATUS_DISCONNECTED',
  chargingCurrentAmps: null,
  chargingPowerWatts: null,
  chargingStatus: 'CHARGING_STATUS_IDLE',
  estimatedChargingTimeMinutesToTargetDistance: null,
  estimatedChargingTimeToFullMinutes: 0,
  estimatedDistanceToEmptyKm: 320,
  estimatedDistanceToEmptyMiles: 190,
  eventUpdatedTimestamp: {
    iso: '2023-12-18T00:00:00.000Z',
    unix: '1702857600',
    __typename: 'EventUpdatedTimestamp'
  },
  __typename: 'Battery'
}

console.log(await polestar.getOdometer())

Will return:

{
  averageSpeedKmPerHour: 30,
  eventUpdatedTimestamp: {
    iso: '2023-12-18T00:00:00.000Z',
    unix: '1702857600',
    __typename: 'EventUpdatedTimestamp'
  },
  odometerMeters: 12345678,
  tripMeterAutomaticKm: 10,
  tripMeterManualKm: 1000,
  __typename: 'Odometer'
}

Full Example

const Polestar = require("@andysmithfal/polestar.js")

const polestar = new Polestar("email", "password")

async function main(){
    await polestar.login()
    await polestar.setVehicle()

    console.log(await polestar.getBattery())
    console.log(await polestar.getOdometer())
}

main()