diff --git a/types/teslajs/index.d.ts b/types/teslajs/index.d.ts new file mode 100644 index 0000000000..c9e6e79290 --- /dev/null +++ b/types/teslajs/index.d.ts @@ -0,0 +1,178 @@ +// Type definitions for teslajs 4.7 +// Project: https://github.com/mseminatore/TeslaJS#readme +// Definitions by: Felipe Castillo +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface Vehicle { + response: object; + id: string; + vehicleID: number; +} +export interface TokenResponse { + response: object; + body: object; + authToken: string; + refreshToken: string; +} +export type nodeBack = (error: Error, data: any) => any; +export interface optionsType { + authToken: string; + vehicleID: string; + carIndex?: number; +} +export interface Result { + reason: string; + result: boolean; +} + +export const streamingPortal: string; +export const portal: string; +export const API_LOG_ALWAYS: number; +export const API_ERR_LEVEL: number; +export const API_CALL_LEVEL: number; +export const API_RETURN_LEVEL: number; +export const API_BODY_LEVEL: number; +export const API_REQUEST_LEVEL: number; +export const API_RESPONSE_LEVEL: number; +export const API_LOG_ALL: number; +export const CHARGE_STORAGE: number; +export const CHARGE_DAILY: number; +export const CHARGE_STANDARD: number; +export const CHARGE_RANGE: number; +export const SUNROOF_VENT: string; +export const SUNROOF_CLOSED: string; +export const MIN_TEMP: number; +export const MAX_TEMP: number; +export const FRUNK: string; +export const TRUNK: string; +export const streamingColumns: string[]; + +export function setLogLevel(level: number): void; +export function getLogLevel(): number; +export function setPortalBaseURI(uri: string): void; +export function getPortalBaseURI(): string; +export function setStreamingBaseURI(uri: string): void; +export function getStreamingBaseURI(): string; +export function getModel(vehicle: Vehicle): string; +export function vinDecode(vehicle: Vehicle): object; +export function getPaintColor(vehicle: Vehicle): string; +export function getVin(vehicle: Vehicle): string; +export function getShortVin(vehicle: Vehicle): string; +export function login(username: string, password: string, callback: nodeBack): void; +export function loginAsync(username: string, password: string): Promise; +export function refreshToken(refresh_token: string, callback: nodeBack): void; +export function refreshTokenAsync(refresh_token: string): Promise; +export function logout(authToken: string, callback: nodeBack): void; +export function logoutAsync(authToken: string): Promise; +export function vehicle(options: optionsType, callback: nodeBack): Vehicle; +export function vehicleAsync(options: optionsType): Promise; +export function vehicles(options: optionsType, callback: nodeBack): void; +export function vehiclesAsync(options: optionsType): Promise; +export function get_command(options: optionsType, command: string, callback: nodeBack): void; +export function get_commandAsync(options: optionsType, command: string): Promise; +export function post_command(options: optionsType, command: string, body: object, callback: nodeBack): void; +export function post_commandAsync(options: optionsType, command: string, body: object): Promise; +export function vehicleData(options: optionsType, callback: nodeBack): void; +export function vehicleDataAsync(options: optionsType): Promise; +export function vehicleConfig(options: optionsType, callback: nodeBack): void; +export function vehicleConfigAsync(options: optionsType): Promise; +export function vehicleState(options: optionsType, callback: nodeBack): void; +export function vehicleStateAsync(options: optionsType): Promise; +export function climateState(options: optionsType, callback: nodeBack): void; +export function climateStateAsync(options: optionsType): Promise; +export function nearbyChargers(options: optionsType, callback: nodeBack): void; +export function nearbyChargersAsync(options: optionsType): Promise; +export function driveState(options: optionsType, callback: nodeBack): void; +export function driveStateAsync(options: optionsType): Promise; +export function chargeState(options: optionsType, callback: nodeBack): void; +export function chargeStateAsync(options: optionsType): Promise; +export function guiSettings(options: optionsType, callback: nodeBack): void; +export function guiSettingsAsync(options: optionsType): Promise; +export function mobileEnabled(options: optionsType, callback: nodeBack): void; +export function mobileEnabledAsync(options: optionsType): Promise<{ response: boolean }>; +export function honkHorn(options: optionsType, callback: nodeBack): void; +export function honkHornAsync(options: optionsType): Promise; +export function flashLights(options: optionsType, callback: nodeBack): void; +export function flashLightsAsync(options: optionsType): Promise; +export function startCharge(options: optionsType, callback: nodeBack): void; +export function startChargeAsync(options: optionsType): Promise; +export function stopCharge(options: optionsType, callback: nodeBack): void; +export function stopChargeAsync(options: optionsType): Promise; +export function openChargePort(options: optionsType, callback: nodeBack): void; +export function openChargePortAsync(options: optionsType): Promise; +export function closeChargePort(options: optionsType, callback: nodeBack): void; +export function closeChargePortAsync(options: optionsType): Promise; +export function scheduleSoftwareUpdate(options: optionsType, offset: number, callback: any): any; +export function scheduleSoftwareUpdateAsync(options: optionsType): Promise; +export function cancelSoftwareUpdate(options: optionsType, callback: any): any; +export function cancelSoftwareUpdateAsync(options: optionsType): Promise; +export function navigationRequest(options: optionsType, subject: string, text: string, locale: string, callback: any): any; +export function navigationRequestAsync(options: optionsType): Promise; +export function mediaTogglePlayback(options: optionsType, callback: any): any; +export function mediaTogglePlaybackAsync(options: optionsType): Promise; +export function mediaPlayNext(options: optionsType, callback: any): any; +export function mediaPlayNextAsync(options: optionsType): Promise; +export function mediaPlayPrevious(options: optionsType, callback: any): any; +export function mediaPlayPreviousAsync(options: optionsType): Promise; +export function mediaPlayNextFavorite(options: optionsType, callback: any): any; +export function mediaPlayNextFavoriteAsync(options: optionsType): Promise; +export function mediaPlayPreviousFavorite(options: optionsType, callback: any): any; +export function mediaPlayPreviousFavoriteAsync(options: optionsType): Promise; +export function mediaVolumeUp(options: optionsType, callback: any): any; +export function mediaVolumeUpAsync(options: optionsType): Promise; +export function mediaVolumeDown(options: optionsType, callback: any): any; +export function mediaVolumeDownAsync(options: optionsType): Promise; +export function speedLimitActivate(options: optionsType, pin: number, callback: any): any; +export function speedLimitActivateAsync(options: optionsType): Promise; +export function speedLimitDeactivate(options: optionsType, pin: number, callback: any): any; +export function speedLimitDeactivateAsync(options: optionsType): Promise; +export function speedLimitClearPin(options: optionsType, pin: number, callback: any): any; +export function speedLimitClearPinAsync(options: optionsType): Promise; +export function speedLimitSetLimit(options: optionsType, limit: number, callback: any): any; +export function speedLimitSetLimitAsync(options: optionsType): Promise; +export function setSentryMode(options: optionsType, onoff: boolean, callback: any): any; +export function setSentryModeAsync(options: optionsType): Promise; +export function seatHeater(options: optionsType, heater: number, level: number, callback: any): any; +export function seatHeaterAsync(options: optionsType): Promise; +export function steeringHeater(options: optionsType, level: number, callback: any): any; +export function steeringHeaterAsync(options: optionsType): Promise; +export function maxDefrost(options: optionsType, onoff: boolean, callback: any): any; +export function maxDefrostAsync(options: optionsType): Promise; +export function windowControl(options: optionsType, command: string, callback: any): any; +export function windowControlAsync(options: optionsType): Promise; +export function setChargeLimit(options: optionsType, amt: any, callback: nodeBack): void; +export function setChargeLimitAsync(options: optionsType): Promise; +export function chargeStandard(options: optionsType, callback: nodeBack): void; +export function chargeStandardAsync(options: optionsType): Promise; +export function chargeMaxRange(options: optionsType, callback: nodeBack): void; +export function chargeMaxRangeAsync(options: optionsType): Promise; +export function doorLock(options: optionsType, callback: nodeBack): void; +export function doorLockAsync(options: optionsType): Promise; +export function doorUnlock(options: optionsType, callback: nodeBack): void; +export function doorUnlockAsync(options: optionsType): Promise; +export function climateStart(options: optionsType, callback: nodeBack): void; +export function climateStartAsync(options: optionsType): Promise; +export function climateStop(options: optionsType, callback: nodeBack): void; +export function climateStopAsync(options: optionsType): Promise; +export function sunRoofControl(options: optionsType, state: string, callback: nodeBack): void; +export function sunRoofControlAsync(options: optionsType): Promise; +export function sunRoofMove(options: optionsType, percent: any, callback: nodeBack): void; +export function sunRoofMoveAsync(options: optionsType): Promise; +export function setTemps(options: optionsType, driver: number, pass: number, callback: nodeBack): void; +export function setTempsAsync(options: optionsType): Promise; +export function remoteStart(options: optionsType, password: string, callback: nodeBack): void; +export function remoteStartAsync(options: optionsType): Promise; +export function openTrunk(options: optionsType, which: string, callback: nodeBack): void; +export function openTrunkAsync(options: optionsType): Promise; +export function wakeUp(options: optionsType, callback: nodeBack): void; +export function wakeUpAsync(options: optionsType): Promise; +export function setValetMode(options: optionsType, onoff: boolean, pin: any, callback: nodeBack): void; +export function setValetModeAsync(options: optionsType): Promise; +export function resetValetPin(options: optionsType, callback: nodeBack): void; +export function resetValetPinAsync(options: optionsType): Promise; +export function calendar(options: optionsType, entry: any, callback: nodeBack): void; +export function calendarAsync(options: optionsType): Promise; +export function makeCalendarEntry(eventName: string, location: string, startTime: number, endTime: number, accountName: string, phoneName: string): object; +export function homelink(options: optionsType, lat: number, long: number, token: any, callback: nodeBack): void; +export function homelinkAsync(options: optionsType): Promise; +export function startStreaming(options: any, callback: nodeBack, onDataCb: nodeBack): any; diff --git a/types/teslajs/teslajs-tests.ts b/types/teslajs/teslajs-tests.ts new file mode 100644 index 0000000000..0f79c2d910 --- /dev/null +++ b/types/teslajs/teslajs-tests.ts @@ -0,0 +1,13 @@ +import * as tjs from 'teslajs'; + +const options = { authToken: 'token', vehicleID: 'id' }; + +async function main() { + tjs.login('username', 'password', (err, result) => { + const token = result.authToken; + }); + const vehicleData = await tjs.vehicleDataAsync(options); + const chargeState = await tjs.chargeStateAsync(options); +} + +main(); diff --git a/types/teslajs/tsconfig.json b/types/teslajs/tsconfig.json new file mode 100644 index 0000000000..a3f82cdc01 --- /dev/null +++ b/types/teslajs/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "teslajs-tests.ts" + ] +} diff --git a/types/teslajs/tslint.json b/types/teslajs/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/teslajs/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }