Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/brianmay/fake_luxary_api

Fake API for testing
https://github.com/brianmay/fake_luxary_api

Last synced: 17 days ago
JSON representation

Fake API for testing

Awesome Lists containing this project

README

        

# Fake Luxury API

Tesla API client and simulator.

Uses older REST based API. Future of this API uncertain.

Should, be considered alpha quality, as desired functionality not
implemented yet and future refactoring may change APIs.

## Usage

Run the simulator server:

```sh
cargo-watch watch -x 'run --bin fla_server'
```

Run the tests (requires server be running):

```sh
cargo test
```

Note: Running tests will change the test mode on the server. Tests should not be run against Tesla servers.

Get data from the simulator (not streaming test uses `vehicle_id` not `id`):

```sh
cargo run --bin get_vehicles
cargo run --bin get_data 123456789
cargo run --bin streaming_test 999456789
```

Change the simulator mode (do not use this command on real Tesla server):

```sh
cargo run --bin simulate 123456789 driving
cargo run --bin simulate 123456789 charging
cargo run --bin simulate 123456789 idle
```

Get data from real Tesla server:

* Requires token, see [tesla_auth](https://github.com/adriankumpf/tesla_auth) for one way to get the token.
* This method uses [pass](https://www.passwordstore.org/) for keeping secrets, but should be easy to adopt to other methods.
* Don't get confused between `id` (for json requests) and `vehicle_id` (required for streaming).

```sh
pass insert tesla/access_token
pass insert tesla/refresh_token
./wrapper cargo run --bin get_vehicles
./wrapper cargo run --bin get_data
./wrapper cargo run --bin streaming_test
```

## Type Errors

The above commands might fail due to type errors. Because there doesn't appear to be anywhere I can find an official list of types. A type error looks like:

```sh
$
thread 'main' panicked at /home/brian/tree/personal/fake_luxury_api/fla_client/src/lib.rs:353:17:
Error deserializing vehicle: response.charge_state.charger_phases: invalid type: integer `1`, expected a string at line 1 column 984
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

In this case the problem is that charging_state has declared to require a String value, but we got an integer from Tesla instead.

This was the [fix](https://github.com/brianmay/fake_luxary_api/commit/7e269c764fd57d98bf6cd48a01754a3f277aca21) was simple.

```diff
From 7e269c764fd57d98bf6cd48a01754a3f277aca21 Mon Sep 17 00:00:00 2001
From: Brian May
Date: Thu, 23 Nov 2023 12:55:15 +1100
Subject: [PATCH] Fix type of charger_phases

---
fla_common/src/types.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fla_common/src/types.rs b/fla_common/src/types.rs
index f9544dc..a59ef3c 100644
--- a/fla_common/src/types.rs
+++ b/fla_common/src/types.rs
@@ -229,7 +229,7 @@ pub struct ChargeState {
pub charge_port_latch: String,
pub charge_rate: Option,
pub charger_actual_current: i64,
- pub charger_phases: Option,
+ pub charger_phases: Option,
pub charger_pilot_current: i64,
pub charger_power: i64,
pub charger_voltage: i64,
```