leaf

package module
v0.0.0-...-ec06213 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2022 License: MIT Imports: 13 Imported by: 2

README

Leaf

GoDoc

leaf is a Go package and command-line tool providing access to the Nissan Leaf North American NissanConnect EV API.

Through this API you can ask your vehicle for the latest battery status, start charging remotely, start or stop climate control remotely, and retrieve the last known location of the vehicle.

This repo replaces my Carwings project, which implemented an older but global API. This API only works for North American vehicles (and I've only tested on a vehicle in the US, so it may not work in Canada).

Command-line tool

The leaf tool can be installed with:

go get github.com/joeshaw/leaf/cmd/leaf

Run leaf by itself to see full usage information.

To update vehicle information:

leaf -username <username> -password <password> update

To get latest battery status:

leaf -username <username> -password <password> battery

This will print something like:

Getting last updated battery status...
Battery status as of 2020-12-26 11:35:58 -0500 EST:
  Battery remaining: 91%
  Cruising range: 88 miles (83 miles with heat/AC)
  Plug-in state: connected
  Charging status: yes
  Time to full:
    Level 1 charge: 8h30m
    Level 2 charge: 3h0m
    Level 2 at 6 kW: 2h0m

For some people the username is an email address. For others it's a distinct username.

Config values can be provided through environment variables (such as LEAF_USERNAME) or in a ~/.leaf file in the format:

username <username>
password <password>
country US

NissanConnect North America protocol

Ben Woodford put together the first protocol reference, and several people have added onto that Gist.

Tobias Westergaard Kjeldsen has created a Dart library for this API which he uses in his My Leaf app for Android and iOS.

Contributing

Issues and pull requests are welcome. When filing a PR, please make sure the code has been run through gofmt.

License

Copyright 2017-2020 Joe Shaw

leaf is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatteryRecords

type BatteryRecords struct {
	LastUpdatedDateAndTime time.Time `json:"lastUpdatedDateAndTime"`
	BatteryStatus          struct {
		BatteryChargingStatus  ChargingStatus `json:"batteryChargingStatus"`
		BatteryCapacity        int            `json:"batteryCapacity"`
		BatteryRemainingAmount int            `json:"batteryRemainingAmount"`
		SOC                    struct {
			Value int `json:"value"`
		} `json:"soc"`
	} `json:"batteryStatus"`
	PluginState         PluginState  `json:"pluginState"`
	CruisingRangeACOn   float64      `json:"cruisingRangeAcOn"`
	CruisingRangeACOff  float64      `json:"cruisingRangeAcOff"`
	TimeRequired        TimeRequired `json:"timeRequired"`
	TimeRequired200     TimeRequired `json:"timeRequired200"`
	TimeRequired200_6kW TimeRequired `json:"timeRequired200_6kW"`
}

BatteryRecords represents all known information about the vehicle's battery and charging state.

type ChargingStatus

type ChargingStatus string

ChargingStatus represents the current charging status.

func (ChargingStatus) IsCharging

func (cs ChargingStatus) IsCharging() bool

IsCharging returns true if the vehicle is charging.

func (ChargingStatus) String

func (cs ChargingStatus) String() string

String converts the charging status to "yes" or "no".

type Location

type Location struct {
	Latitude     string
	Longitude    string
	ReceivedDate time.Time
}

Location represents the GPS position of the vehicle.

type PluginState

type PluginState string

PluginState represents whether the vehicle is plugged in (not necessarily charging).

func (PluginState) String

func (ps PluginState) String() string

String converts the plugin state to "connected" or "not connected".

type Session

type Session struct {
	Username string
	Password string
	Country  string
	Debug    bool
	Filename string
	VIN      string
	PIN      string
	// contains filtered or unexported fields
}

Session represents a connection to the Nissan API server.

func (*Session) ChargingStatus

func (s *Session) ChargingStatus() (*BatteryRecords, *TemperatureRecords, error)

ChargingStatus returns the current battery and temperature records.

func (*Session) ClimateOff

func (s *Session) ClimateOff() error

ClimateOff turns off the HVAC system.

func (*Session) ClimateOn

func (s *Session) ClimateOn() error

ClimateOn turns on the HVAC system.

func (*Session) FlashLights

func (s *Session) FlashLights() error

FlashLights flashes the vehicle lights.

func (*Session) Honk

func (s *Session) Honk() error

Honk honks the vehicle horn and flashes the lights.

func (*Session) Load

func (s *Session) Load() error

Load reads existing session data from the state file.

func (*Session) LocateVehicle

func (s *Session) LocateVehicle() (*Location, error)

LocateVehicle returns the current vehicle location.

func (*Session) LockDoors

func (s *Session) LockDoors() error

LockDoors locks the vehicle doors.

func (*Session) Login

Login sets up a new session with the Nissan API and retrieves the last known vehicle, battery and temperature records.

func (*Session) StartCharging

func (s *Session) StartCharging() error

StartCharging turns on the vehicle charger.

func (*Session) UnlockDoors

func (s *Session) UnlockDoors() error

UnlockDoors unlocks the vehicle doors.

func (*Session) VehicleInfo

func (s *Session) VehicleInfo() *VehicleInfo

type TemperatureRecords

type TemperatureRecords struct {
	Temperature string `json:"inc_temp"`
}

TemperatureRecords represent the current interior temperature.

type TimeRequired

type TimeRequired struct {
	HourRequiredToFull    int `json:"hourRequiredToFull"`
	MinutesRequiredToFull int `json:"minutesRequiredToFull"`
}

TimeRequired represents the time needed until fully charged.

func (TimeRequired) IsZero

func (tr TimeRequired) IsZero() bool

IsZero checks if the charge time is 0.

func (TimeRequired) String

func (tr TimeRequired) String() string

String returns a human readable duration in minutes or hours and minutes.

type VehicleInfo

type VehicleInfo struct {
	VIN       string `json:"uvi"`
	ModelName string `json:"modelname"`
	ModelYear string `json:"modelyear"`
	ExtColor  string `json:"extcolor"`
	Nickname  string `json:"nickname"`
}

VehicleInfo reprents the model, year and appearance of the vehicle.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL