All Projects → HamblinSoft → TeslaKit

HamblinSoft / TeslaKit

Licence: MIT license
Elegant Tesla API in Swift

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to TeslaKit

teslaapi.io
Unofficial Tesla API Documentation
Stars: ✭ 29 (-38.3%)
Mutual labels:  tesla, teslaapi, tesla-api
TeslaPy
A Python module to use the Tesla Motors Owner API
Stars: ✭ 216 (+359.57%)
Mutual labels:  tesla, tesla-api, teslamotors
tesla.dart
Tesla Client Library for Dart
Stars: ✭ 28 (-40.43%)
Mutual labels:  tesla, tesla-api, teslamotors
tesla api
Lightweight Python API client for the Tesla API.
Stars: ✭ 73 (+55.32%)
Mutual labels:  tesla, teslamotors
Tesla-API
A iOS, macOS, watchOS and tvOS framework written in Swift to communicate with Teslas vehicle API
Stars: ✭ 32 (-31.91%)
Mutual labels:  tesla, tesla-api
tesla-api
Unofficial API Wrapper for Tesla Model S and X. #follows-javascript-conventions #es6 #es7
Stars: ✭ 24 (-48.94%)
Mutual labels:  tesla, tesla-api
tesla auth
Securely generate API tokens for third-party access to your Tesla.
Stars: ✭ 114 (+142.55%)
Mutual labels:  tesla, tesla-api
godmt
Tool that can parse Go files into an abstract syntax tree and translate it to several programming languages.
Stars: ✭ 42 (-10.64%)
Mutual labels:  model, models
Coolie
Coolie(苦力) helps you to create models (& their constructors) from a JSON file.
Stars: ✭ 508 (+980.85%)
Mutual labels:  model, models
Torch Models
Stars: ✭ 65 (+38.3%)
Mutual labels:  model, models
Cv Pretrained Model
A collection of computer vision pre-trained models.
Stars: ✭ 995 (+2017.02%)
Mutual labels:  model, models
Typegoose
Typegoose - Define Mongoose models using TypeScript classes.
Stars: ✭ 1,189 (+2429.79%)
Mutual labels:  model, models
tesla-usb-drive
Tesla DashCam & Music USB drive maker tool
Stars: ✭ 17 (-63.83%)
Mutual labels:  tesla, teslamotors
Awesome Coreml Models
Largest list of models for Core ML (for iOS 11+)
Stars: ✭ 5,192 (+10946.81%)
Mutual labels:  model, models
Open model zoo
Pre-trained Deep Learning models and demos (high quality and extremely fast)
Stars: ✭ 2,925 (+6123.4%)
Mutual labels:  model, models
Django Colorfield
color field for django models with a nice color-picker in the admin. 🎨
Stars: ✭ 238 (+406.38%)
Mutual labels:  model, models
sdkmesh-to-obj
sdkmesh decoder
Stars: ✭ 17 (-63.83%)
Mutual labels:  model
sym
A Mathematica package for generating symbolic models from data
Stars: ✭ 46 (-2.13%)
Mutual labels:  model
MaskRCNN-Modanet-Fashion-Segmentation-and-Classification
Using modanet fashion dataset, the clothes images were classified under 5 season (summer,winter,spring,autumn,all).
Stars: ✭ 55 (+17.02%)
Mutual labels:  model
SPWaterWaveProgressIndicatorView
An iOS Custom Water Wave Progress Indicator View with Demo
Stars: ✭ 24 (-48.94%)
Mutual labels:  ios-lib

TeslaKit

Platform Cocoapods compatible Version License Language Twitter

TeslaKit is a framework written in Swift that makes it easy for you to interface with Tesla's mobile API and communicate with your Tesla automobiles.

Features

  • Authenticate with Tesla's API to obtain an access token
  • Retrieve a list of vehicles associated with your Tesla account
  • Obtain all data on your vehicle
  • Send commands to your vehicle
  • Utilizes ObjectMapper for JSON mapping
  • Uses Structures to maintain thread safe operations
  • VIN Decoder
  • Summon and Homelink - Coming soon

Inspiration

I have been a long time fan of Tesla ever since the original Roadster. When the Model 3 was announced, I actually camped out overnight so I could place my reservation. I am also a big Apple fan and really enjoy my Apple Watch, although wish there were more interesting complications I could add to my watch faces. So I decided to make my own app while I wait for my Model 3.

Fast foward to mid-2018, I have officially released my app, called AutoMate for Tesla, on the App Store and have also received my Model 3! During development of AutoMate, I decided to separate the core Tesla API interactions into a separate project and open source it so others could also build really cool apps too.

I am looking forward to seeing what people do with TeslaKit and if you're anything like me and thoroughly enjoy your car and own an Apple Watch, I think you will also enjoy AutoMate so please give it a try!

Installation

TeslaKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'TeslaKit'

Usage

Add an ATS exception domain for owner-api.teslamotors.com in your info.plist

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>owner-api.teslamotors.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionMinimumTLSVersion</key>
            <string>TLSv1.0</string>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

Add an import statement for TeslaKit into your file

import TeslaKit

TeslaAPI

Create a new TeslaAPI instance

let teslaAPI = TeslaAPI()

Also see other initialization configuration options

Access Token

Obtain an Access Token by logging in with your Tesla account credentials

let email = "[email protected]"
let password = "M@R$R0X!"

teslaAPI.getAccessToken(email: email, password: password) { (httpResponse, dataOrNil, errorOrNil) in

    guard let accessToken = dataOrNil?.accessToken else { return }

    // Set the accessToken for use with future requests
    teslaAPI.setAccessToken(accessToken)
}

Vehicle List

Obtain a list of vehicles associated with your account

teslaAPI.getVehicles { (httpResponse, dataOrNil, errorOrNil) in

    guard let vehicle = dataOrNil?.vehicles.first else { return }

    print("Hello, \(vehicle.displayName)")
}

Vehicle Data

Obtain all data for a vehicle

teslaAPI.getData(vehicle.id) { (httpResponse, dataOrNil, errorOrNil) in

    guard let vehicle = dataOrNil else { return }

    print("Battery is at \(vehicle.chargeState.batteryLevel)%")
}

Send Command

Send a command to a vehicle

let command = Command.unlockDoors

teslaAPI.send(command, to: vehicle) { response in
    if response.result {
        print("Command sent successfully!")
    }
}

Send a command to a vehicle with request parameters

let parameters = SetTemperature(driverTemp: 21.0, passengerTemp: 21.0)

teslaAPI.send(.setTemperature, to: vehicle, parameters: parameters) { response in
    if response.result {
        print("Command sent successfully!")
    }
}

Configuration

Default

let teslaAPI = TeslaAPI(configuration: .default) // same as TeslaAPI()

The default configuration points to Tesla's production owner API

Mock

let teslaAPI = TeslaAPI(configuration: .mock)

The mock configuration directs all requests to a custom server that returns a predefined responses for each of the owner API endpoints allowing you to work with some real-looking data to work with without having to own a Tesla vehicle or without having a Tesla account at all.

Note: Because this is a free service, requests are occasionally throttled.

Custom

let customConfig = TeslaAPI.Configuration(baseURL: URL(string: "SOME_URL")!,
                                          clientId: "SOME_CLIENT_ID",
                                          clientSecret: "SOME_CLIENT_SECRET",
                                          requestTimeout: 30)

let teslaAPI = TeslaAPI(configuration: customConfig)

The custom configuration allows you to specify your own baseURL. This is convenient if you would like to point to your own environment. You can also specify an alternate clientId and clientSecret value. You can also specify a different request timeout interval (default: 30)

Debug Mode

let teslaAPI = TeslaAPI(debugMode: true)

Enabling debug mode will print all the raw request and response information to the console (default: false)

VIN Decoder

let vin = VIN(vinString: "5YJSA1E2XHF999999")!
print(vin.make)         // Model S
print(vin.driveUnit)    // Dual Motor
print(vin.modelYear)    // 2017
print(vin.serialNo)     // 999999
print(vin.vinString)    // 5YJSA1E2XHF999999

Apps Built With TeslaKit

Is your app using TeslaKit? Let me know and I'll feature it here too!

Tesla Referral Program

Buying a new Tesla? Use my referral code and receive 1,000 free Supercharger miles!

Author

jjjjaren, [email protected]

License

This project is licensed under the terms of the MIT license. See the LICENSE file.

This project is in no way affiliated with Tesla Inc. This project is open source under the MIT license, which means you have full access to the source code and can modify it to fit your own needs.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].