Skip to content

Commit

Permalink
Add vehicle data commands
Browse files Browse the repository at this point in the history
Vehicle Data commands are intended to work over BLE. The Fleet API
vehicle data endpoint is more efficient when using an Internet
connection.
  • Loading branch information
Seth Terashima authored and sethterashima committed Nov 18, 2024
1 parent 856a76e commit 7457011
Show file tree
Hide file tree
Showing 10 changed files with 15,839 additions and 1,719 deletions.
49 changes: 49 additions & 0 deletions cmd/tesla-control/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,35 @@ type Command struct {
domain protocol.Domain
}

var categoriesByName = map[string]vehicle.StateCategory{
"charge": vehicle.StateCategoryCharge,
"climate": vehicle.StateCategoryClimate,
"drive": vehicle.StateCategoryDrive,
"closures": vehicle.StateCategoryClosures,
"charge-schedule": vehicle.StateCategoryChargeSchedule,
"precondition-schedule": vehicle.StateCategoryPreconditioningSchedule,
"tire-pressure": vehicle.StateCategoryTirePressure,
"media": vehicle.StateCategoryMedia,
"media-detail": vehicle.StateCategoryMediaDetail,
"software-update": vehicle.StateCategorySoftwareUpdate,
"parental-controls": vehicle.StateCategoryParentalControls,
}

func categoryNames() []string {
var names []string
for name, _ := range categoriesByName {
names = append(names, name)
}
return names
}

func GetCategory(nameStr string) (vehicle.StateCategory, error) {
if category, ok := categoriesByName[strings.ToLower(nameStr)]; ok {
return category, nil
}
return 0, fmt.Errorf("unrecognized state category '%s'", nameStr)
}

func GetDegree(degStr string) (float32, error) {
deg, err := strconv.ParseFloat(degStr, 32)
if err != nil {
Expand Down Expand Up @@ -1135,4 +1164,24 @@ var commands = map[string]*Command{
return car.BatchRemovePreconditionSchedules(ctx, home, work, other)
},
},
"state": {
help: "Fetch vehicle state over BLE.",
requiresAuth: true,
requiresFleetAPI: false,
args: []Argument{
Argument{name: "CATEGORY", help: "One of " + strings.Join(categoryNames(), ", ")},
},
handler: func(ctx context.Context, acct *account.Account, car *vehicle.Vehicle, args map[string]string) error {
category, err := GetCategory(args["CATEGORY"])
if err != nil {
return err
}
data, err := car.GetState(ctx, category)
if err != nil {
return err
}
fmt.Println(protojson.Format(data))
return nil
},
},
}
51 changes: 51 additions & 0 deletions pkg/protocol/protobuf/car_server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ message VehicleAction {
reserved 60;
reserved 76;
oneof vehicle_action_msg {
GetVehicleData getVehicleData = 1;
ChargingSetLimitAction chargingSetLimitAction = 5;
ChargingStartStopAction chargingStartStopAction = 6;
DrivingClearSpeedLimitPinAction drivingClearSpeedLimitPinAction = 7;
Expand Down Expand Up @@ -75,13 +76,63 @@ message VehicleAction {
}
}

message GetVehicleData {
GetChargeState getChargeState = 2;
GetClimateState getClimateState = 3;
GetDriveState getDriveState = 4;
reserved 5, 6, 7;
GetClosuresState getClosuresState = 8;
GetChargeScheduleState getChargeScheduleState = 10;
GetPreconditioningScheduleState getPreconditioningScheduleState = 11;
reserved 12, 13;
GetTirePressureState getTirePressureState = 14;
GetMediaState getMediaState = 15;
GetMediaDetailState getMediaDetailState = 16;
GetSoftwareUpdateState getSoftwareUpdateState = 17;
GetParentalControlsState getParentalControlsState = 19;
}

message GetTirePressureState {
}

message GetMediaState {
}

message GetMediaDetailState {
}

message GetSoftwareUpdateState {
}

message GetChargeState {
}

message GetClimateState {
}

message GetDriveState {
}

message GetClosuresState {
}

message GetChargeScheduleState {
}

message GetPreconditioningScheduleState {
}

message GetParentalControlsState {
}

message EraseUserDataAction {
string reason = 1;
}

message Response {
ActionStatus actionStatus = 1;
oneof response_msg {
VehicleData vehicleData = 2;
Signatures.SessionInfo getSessionInfoResponse = 3;
NearbyChargingSites getNearbyChargingSites = 5;
Ping ping = 9;
Expand Down
Loading

0 comments on commit 7457011

Please sign in to comment.