tesla

提供了一个 API 封装,可轻松查询和指挥 Telsa 汽车。目前已在 Model S、Model X 和 Model 3 上使用。「Provides a wrapper around the API to easily query and command a Telsa car. As of now this has been used with a Model S, a Model X, and a Model 3.」

Github星跟踪图

tesla

wercker status

This library provides a wrapper around the API to easily query and command the a Tesla Model S remotely in Go.

Library Documentation

https://godoc.org/github.com/jsgoecke/tesla

API Documentation

View Tesla JSON API Documentation

This is unofficial documentation of the Tesla JSON API used by the iOS and Android apps. The API provides functionality to monitor and control the Model S (and future Tesla vehicles) remotely. The project provides both a documention of the API and a Go library for accessing it.

Installation

go get github.com/jsgoecke/tesla

Tokens

You may get your tokens to use as client_id and client_secret here.

Usage

Here's an example (more in the /examples project directory):

func main() {
	client, err := tesla.NewClient(
		&tesla.Auth{
			ClientID:     os.Getenv("TESLA_CLIENT_ID"),
			ClientSecret: os.Getenv("TESLA_CLIENT_SECRET"),
			Email:        os.Getenv("TESLA_USERNAME"),
			Password:     os.Getenv("TESLA_PASSWORD"),
		})
	if err != nil {
		panic(err)
	}

	vehicles, err := client.Vehicles()
	if err != nil {
		panic(err)
	}

	vehicle := vehicles[0]
	status, err := vehicle.MobileEnabled()
	if err != nil {
		panic(err)
	}

	fmt.Println(status)
	fmt.Println(vehicle.HonkHorn())

	// Autopark
	// Use with care, as this will move your car
	vehicle.AutoparkForward()
	vehicle.AutoparkReverse()
	// Use with care, as this will move your car

	// Stream vehicle events
	eventChan, errChan, err := vehicle.Stream()
	if err != nil {
		fmt.Println(err)
		return
	} else {
		for {
			select {
			case event := <-eventChan:
				eventJSON, _ := json.Marshal(event)
				fmt.Println(string(eventJSON))
			case err = <-errChan:
				fmt.Println(err)
				if err.Error() == "HTTP stream closed" {
					fmt.Println("Reconnecting!")
					eventChan, errChan, err := vehicle.Stream()
					if err != nil {
						fmt.Println(err)
						return
					}
				}
			}
		}
	}
}

Examples

Credits

Thank you to Tim Dorr who did the heavy lifting to document the Tesla API and also created the model-s-api Ruby Gem.

Current Issues

Right now Tesla appears to have broken the Autopark and Homelink commands of their API in a recent cloud API update. I have started a thread here and will update as information becomes available. And fix if/when the community discovers the fix. Keep an eye on these two issues for resolution:

Copyright (c) 2016-Present Jason Goecke. Released under the terms of the MIT license. See LICENSE for details.

主要指标

概览
名称与所有者jsgoecke/tesla
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2016-04-12 18:20:30
推送于2024-12-01 08:41:00
最后一次提交2024-12-01 00:41:00
发布数0
用户参与
星数325
关注者数28
派生数73
提交数119
已启用问题?
问题数26
打开的问题数7
拉请求数7
打开的拉请求数3
关闭的拉请求数9
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?