Skip to content

Commit

Permalink
Allow setting a max config or a 'basic'
Browse files Browse the repository at this point in the history
  • Loading branch information
elffjs committed Jan 21, 2025
1 parent 40eb1a5 commit 50d1aa0
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cmd/devices-api/enable_telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (p *enableTelemetryCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...in
}

const teslaAllFields = `{"ACChargingEnergyIn":{"interval_seconds":1},"ACChargingPower":{"interval_seconds":1},"AutoSeatClimateLeft":{"interval_seconds":1},"AutoSeatClimateRight":{"interval_seconds":1},"AutomaticBlindSpotCamera":{"interval_seconds":1},"AutomaticEmergencyBrakingOff":{"interval_seconds":1},"BMSState":{"interval_seconds":1},"BatteryHeaterOn":{"interval_seconds":1},"BatteryLevel":{"interval_seconds":1},"BlindSpotCollisionWarningChime":{"interval_seconds":1},"BmsFullchargecomplete":{"interval_seconds":1},"BrakePedal":{"interval_seconds":1},"BrakePedalPos":{"interval_seconds":1},"BrickVoltageMax":{"interval_seconds":1},"BrickVoltageMin":{"interval_seconds":1},"CabinOverheatProtectionMode":{"interval_seconds":1},"CabinOverheatProtectionTemperatureLimit":{"interval_seconds":1},"CarType":{"interval_seconds":1},"CenterDisplay":{"interval_seconds":1},"ChargeAmps":{"interval_seconds":1},"ChargeCurrentRequest":{"interval_seconds":1},"ChargeCurrentRequestMax":{"interval_seconds":1},"ChargeEnableRequest":{"interval_seconds":1},"ChargeLimitSoc":{"interval_seconds":1},"ChargePort":{"interval_seconds":1},"ChargePortColdWeatherMode":{"interval_seconds":1},"ChargePortDoorOpen":{"interval_seconds":1},"ChargePortLatch":{"interval_seconds":1},"ChargeState":{"interval_seconds":1},"ChargerPhases":{"interval_seconds":1},"ChargingCableType":{"interval_seconds":1},"ClimateKeeperMode":{"interval_seconds":1},"CruiseFollowDistance":{"interval_seconds":1},"CruiseSetSpeed":{"interval_seconds":1},"CurrentLimitMph":{"interval_seconds":1},"DCChargingEnergyIn":{"interval_seconds":1},"DCChargingPower":{"interval_seconds":1},"DCDCEnable":{"interval_seconds":1},"DefrostForPreconditioning":{"interval_seconds":1},"DefrostMode":{"interval_seconds":1},"DestinationLocation":{"interval_seconds":1},"DestinationName":{"interval_seconds":1},"DetailedChargeState":{"interval_seconds":1},"DiAxleSpeedF":{"interval_seconds":1},"DiAxleSpeedR":{"interval_seconds":1},"DiAxleSpeedREL":{"interval_seconds":1},"DiAxleSpeedRER":{"interval_seconds":1},"DiHeatsinkTF":{"interval_seconds":1},"DiHeatsinkTR":{"interval_seconds":1},"DiHeatsinkTREL":{"interval_seconds":1},"DiHeatsinkTRER":{"interval_seconds":1},"DiInverterTF":{"interval_seconds":1},"DiInverterTR":{"interval_seconds":1},"DiInverterTREL":{"interval_seconds":1},"DiInverterTRER":{"interval_seconds":1},"DiMotorCurrentF":{"interval_seconds":1},"DiMotorCurrentR":{"interval_seconds":1},"DiMotorCurrentREL":{"interval_seconds":1},"DiMotorCurrentRER":{"interval_seconds":1},"DiSlaveTorqueCmd":{"interval_seconds":1},"DiStateF":{"interval_seconds":1},"DiStateR":{"interval_seconds":1},"DiStateREL":{"interval_seconds":1},"DiStateRER":{"interval_seconds":1},"DiStatorTempF":{"interval_seconds":1},"DiStatorTempR":{"interval_seconds":1},"DiStatorTempREL":{"interval_seconds":1},"DiStatorTempRER":{"interval_seconds":1},"DiTorqueActualF":{"interval_seconds":1},"DiTorqueActualR":{"interval_seconds":1},"DiTorqueActualREL":{"interval_seconds":1},"DiTorqueActualRER":{"interval_seconds":1},"DiTorquemotor":{"interval_seconds":1},"DiVBatF":{"interval_seconds":1},"DiVBatR":{"interval_seconds":1},"DiVBatREL":{"interval_seconds":1},"DiVBatRER":{"interval_seconds":1},"DoorState":{"interval_seconds":1},"DriveRail":{"interval_seconds":1},"DriverSeatBelt":{"interval_seconds":1},"DriverSeatOccupied":{"interval_seconds":1},"EfficiencyPackage":{"interval_seconds":1},"EmergencyLaneDepartureAvoidance":{"interval_seconds":1},"EnergyRemaining":{"interval_seconds":1},"EstBatteryRange":{"interval_seconds":1},"EstimatedHoursToChargeTermination":{"interval_seconds":1},"EuropeVehicle":{"interval_seconds":1},"ExpectedEnergyPercentAtTripArrival":{"interval_seconds":1},"ExteriorColor":{"interval_seconds":1},"FastChargerPresent":{"interval_seconds":1},"FastChargerType":{"interval_seconds":1},"FdWindow":{"interval_seconds":1},"ForwardCollisionWarning":{"interval_seconds":1},"FpWindow":{"interval_seconds":1},"Gear":{"interval_seconds":1},"GpsHeading":{"interval_seconds":1},"GpsState":{"interval_seconds":1},"GuestModeEnabled":{"interval_seconds":1},"GuestModeMobileAccessState":{"interval_seconds":1},"HomelinkDeviceCount":{"interval_seconds":1},"HomelinkNearby":{"interval_seconds":1},"HvacACEnabled":{"interval_seconds":1},"HvacAutoMode":{"interval_seconds":1},"HvacFanSpeed":{"interval_seconds":1},"HvacFanStatus":{"interval_seconds":1},"HvacLeftTemperatureRequest":{"interval_seconds":1},"HvacPower":{"interval_seconds":1},"HvacRightTemperatureRequest":{"interval_seconds":1},"HvacSteeringWheelHeatAuto":{"interval_seconds":1},"HvacSteeringWheelHeatLevel":{"interval_seconds":1},"Hvil":{"interval_seconds":1},"IdealBatteryRange":{"interval_seconds":1},"InsideTemp":{"interval_seconds":1},"IsolationResistance":{"interval_seconds":1},"LaneDepartureAvoidance":{"interval_seconds":1},"LateralAcceleration":{"interval_seconds":1},"LifetimeEnergyGainedRegen":{"interval_seconds":1},"LifetimeEnergyUsed":{"interval_seconds":1},"LifetimeEnergyUsedDrive":{"interval_seconds":1},"Location":{"interval_seconds":1},"Locked":{"interval_seconds":1},"LongitudinalAcceleration":{"interval_seconds":1},"MilesToArrival":{"interval_seconds":1},"MinutesToArrival":{"interval_seconds":1},"ModuleTempMax":{"interval_seconds":1},"ModuleTempMin":{"interval_seconds":1},"NotEnoughPowerToHeat":{"interval_seconds":1},"NumBrickVoltageMax":{"interval_seconds":1},"NumBrickVoltageMin":{"interval_seconds":1},"NumModuleTempMax":{"interval_seconds":1},"NumModuleTempMin":{"interval_seconds":1},"Odometer":{"interval_seconds":1},"OffroadLightbarPresent":{"interval_seconds":1},"OriginLocation":{"interval_seconds":1},"OutsideTemp":{"interval_seconds":1},"PackCurrent":{"interval_seconds":1},"PackVoltage":{"interval_seconds":1},"PairedPhoneKeyAndKeyFobQty":{"interval_seconds":1},"PassengerSeatBelt":{"interval_seconds":1},"PedalPosition":{"interval_seconds":1},"PinToDriveEnabled":{"interval_seconds":1},"PowershareHoursLeft":{"interval_seconds":1},"PowershareInstantaneousPowerKW":{"interval_seconds":1},"PowershareStatus":{"interval_seconds":1},"PowershareStopReason":{"interval_seconds":1},"PowershareType":{"interval_seconds":1},"PreconditioningEnabled":{"interval_seconds":1},"RatedRange":{"interval_seconds":1},"RdWindow":{"interval_seconds":1},"RearDisplayHvacEnabled":{"interval_seconds":1},"RearSeatHeaters":{"interval_seconds":1},"RemoteStartEnabled":{"interval_seconds":1},"RightHandDrive":{"interval_seconds":1},"RoofColor":{"interval_seconds":1},"RouteLastUpdated":{"interval_seconds":1},"RouteLine":{"interval_seconds":1},"RouteTrafficMinutesDelay":{"interval_seconds":1},"RpWindow":{"interval_seconds":1},"ScheduledChargingMode":{"interval_seconds":1},"ScheduledChargingPending":{"interval_seconds":1},"ScheduledChargingStartTime":{"interval_seconds":1},"ScheduledDepartureTime":{"interval_seconds":1},"SeatHeaterLeft":{"interval_seconds":1},"SeatHeaterRearCenter":{"interval_seconds":1},"SeatHeaterRearLeft":{"interval_seconds":1},"SeatHeaterRearRight":{"interval_seconds":1},"SeatHeaterRight":{"interval_seconds":1},"SentryMode":{"interval_seconds":1},"ServiceMode":{"interval_seconds":1},"Soc":{"interval_seconds":1},"SoftwareUpdateDownloadPercentComplete":{"interval_seconds":1},"SoftwareUpdateExpectedDurationMinutes":{"interval_seconds":1},"SoftwareUpdateInstallationPercentComplete":{"interval_seconds":1},"SoftwareUpdateScheduledStartTime":{"interval_seconds":1},"SoftwareUpdateVersion":{"interval_seconds":1},"SpeedLimitMode":{"interval_seconds":1},"SpeedLimitWarning":{"interval_seconds":1},"SuperchargerSessionTripPlanner":{"interval_seconds":1},"TimeToFullCharge":{"interval_seconds":1},"TonneauOpenPercent":{"interval_seconds":1},"TonneauPosition":{"interval_seconds":1},"TonneauTentMode":{"interval_seconds":1},"TpmsHardWarnings":{"interval_seconds":1},"TpmsLastSeenPressureTimeFl":{"interval_seconds":1},"TpmsLastSeenPressureTimeFr":{"interval_seconds":1},"TpmsLastSeenPressureTimeRl":{"interval_seconds":1},"TpmsLastSeenPressureTimeRr":{"interval_seconds":1},"TpmsPressureFl":{"interval_seconds":1},"TpmsPressureFr":{"interval_seconds":1},"TpmsPressureRl":{"interval_seconds":1},"TpmsPressureRr":{"interval_seconds":1},"TpmsSoftWarnings":{"interval_seconds":1},"Trim":{"interval_seconds":1},"ValetModeEnabled":{"interval_seconds":1},"VehicleName":{"interval_seconds":1},"VehicleSpeed":{"interval_seconds":1},"Version":{"interval_seconds":1},"WheelType":{"interval_seconds":1},"WiperHeatEnabled":{"interval_seconds":1}}`
const teslaBasicFields = `{"ACChargingEnergyIn":{"interval_seconds":60},"ACChargingPower":{"interval_seconds":60},"BatteryLevel":{"interval_seconds":300},"ChargeLimitSoc":{"interval_seconds":3600},"ChargeState":{"interval_seconds":60},"DCChargingEnergyIn":{"interval_seconds":60},"DCChargingPower":{"interval_seconds":60},"EnergyRemaining":{"interval_seconds":60},"EstBatteryRange":{"interval_seconds":300},"Location":{"interval_seconds":20},"Odometer":{"interval_seconds":300},"OutsideTemp":{"interval_seconds":60},"Soc":{"interval_seconds":60},"TpmsPressureFl":{"interval_seconds":300},"TpmsPressureFr":{"interval_seconds":300},"TpmsPressureRl":{"interval_seconds":300},"TpmsPressureRr":{"interval_seconds":300},"VehicleSpeed":{"interval_seconds":20}}`

type teslaFleetConfigReq struct {
VINs []string `json:"vins"`
Expand All @@ -78,9 +79,18 @@ type fleetConfigResp struct {
}

func enableTelemetry(settings *config.Settings, pdb db.Store, logger *zerolog.Logger, cipher shared.Cipher) error {
logger.Info().Msgf("Checking virtual key status.")

userDeviceID := os.Args[2]
configName := os.Args[2]
userDeviceID := os.Args[3]

var fieldsPayload []byte
switch configName {
case "basic":
fieldsPayload = []byte(teslaBasicFields)
case "max":
fieldsPayload = []byte(teslaAllFields)
default:
return fmt.Errorf("unrecognized type %q", os.Args[3])
}

ctx := context.Background()

Expand Down Expand Up @@ -122,7 +132,7 @@ func enableTelemetry(settings *config.Settings, pdb db.Store, logger *zerolog.Lo
Hostname: settings.TeslaTelemetryHostName,
CA: settings.TeslaTelemetryCACertificate,
Port: settings.TeslaTelemetryPort,
Fields: []byte(teslaAllFields),
Fields: fieldsPayload,
},
}

Expand Down Expand Up @@ -161,7 +171,7 @@ func enableTelemetry(settings *config.Settings, pdb db.Store, logger *zerolog.Lo
var xs string
switch {
case resBody.Response.UpdatedVehicles != 0:
xs = "Set successfully."
xs = fmt.Sprintf("Set config %s successfully.", configName)
case len(resBody.Response.SkippedVehicles.MissingKey) != 0:
xs = "Virtual key missing."
case len(resBody.Response.SkippedVehicles.UnsupportedHardware) != 0:
Expand Down

0 comments on commit 50d1aa0

Please sign in to comment.