#命令行工具 #查询 #数据 #API #端点 #单元 #tesla

bin+lib teslatte

用于查询特斯拉API的命令行工具和Rust库

17次发布

0.1.15 2024年4月12日
0.1.14 2024年4月12日
0.1.13 2024年1月23日
0.1.11 2023年11月11日
0.0.1 2022年7月21日

#227 in Web编程

Download history

968每月下载量

MIT/Apache

100KB
2.5K SLoC

特斯拉 🚗🔋☀️☕

Crates.io docs.rs GitHub Workflow Status MIT or Apache-2.0

⚠️ Alpha警告!⚠️

此Rust库目前处于alpha阶段。这是我为了满足需求而快速构建的。我打算在需要更多功能时继续工作。

0.1.x 将会有破坏性的API更改。请勿依赖此项目进行任何重要操作。

使用Rust nightly直到 async_fn_in_trait 稳定。

特斯拉是CLI和Rust库,用于与特斯拉API交互。

如果你愿意创建PR,添加新端点相当简单,但请

  • 如果它依赖于新的或更改的数据结构,请编写一些单元测试。
  • 如果你的PR是重大更改,请在花费大量时间之前告诉我。

实现的API

此库仅部分支持所有者API,并计划支持车队API和命令模式SDK。

API.md 包含所有已知特斯拉API(官方和非官方)及其是否由Teslatte支持,以及API详细信息是从哪里抓取的。

参考文献

感谢 https://tesla-api.timdorr.com/ 提供的优秀参考。

特斯拉最近发布了其 "车队API" 的API文档,这似乎与特斯拉所有者API类似。

特斯拉还最近发布了一个 命令模式SDK,其中也包括车队API的代理。

CLI

有一个CLI可以用来与API交互。示例

$ teslatte --help
Usage: teslatte api [OPTIONS] <COMMAND>

Commands:
  vehicles      List of vehicles
  vehicle       Specific Vehicle
  energy-sites  List of energy sites
  energy-site   Specific energy site
  powerwall     Powerwall queries
  help          Print this message or the help of the given subcommand(s)

Options:
  -a, --access-token <ACCESS_TOKEN>  Access token. If not provided, will try to load from the cli.json file [env: TESLA_ACCESS_TOKEN=]
  -h, --help                         Print help
  
# Prints a URL to start the OAuth flow, then asks for the token URL, then saves the token to `cli.json`.
$ teslatte auth --save 

# Lists your vehicles:
$ teslatte api vehicles
{
  "response": [{
    "vehicle_id": 1234567890,
  }]
}

$ teslatte api vehicle 1234567890
Specific Vehicle

Usage: teslatte api vehicle <ID> <COMMAND>

Commands:
  vehicle-data             Get vehicle data
  charge-port-door-open    Open the charge port door or unlocks the cable
  charge-port-door-close   For vehicles with a motorized charge port, this closes it
  set-charge-limit         Set charge limit
  set-charging-amps        Set charge amps
  charge-standard          Set the charge limit to the standard %
  charge-max-range         Set the charge limit to the maximum %
  charge-start             Start charging
  charge-stop              Stop charging
  set-scheduled-charging   Set scheduled charging
  set-scheduled-departure  Set scheduled departure
  honk-horn                Honk!
  flash-lights             Flash the lights
  help                     Print this message or the help of the given subcommand(s)

Arguments:
  <ID>

Options:
  -h, --help  Print help
  
$ teslatte api vehicle 1234567890 vehicle_data
{ ... }

库示例

一个基本示例: examples/basic.rs

许可证

根据您的选择许可

贡献

除非您明确声明,否则根据Apache-2.0许可证定义,您有意提交并包含在作品中的任何贡献,应按上述方式双重许可,没有任何附加条款或条件。

依赖项

~18–31MB
~585K SLoC