1 #pragma once
2 
3 #include "../../main/json_helper.h"
4 #include "VehicleApi.h"
5 
6 class CTeslaApi: public CVehicleApi
7 {
8 public:
9 	CTeslaApi(const std::string username, const std::string password, const std::string vin);
10 	~CTeslaApi();
11 
12 	bool Login() override;
13 	bool RefreshLogin() override;
14 	int GetSleepInterval() override;
15 	bool SendCommand(eCommandType command) override;
16 	bool GetAllData(tAllCarData& data) override;
17 	bool GetLocationData(tLocationData& data) override;
18 	bool GetChargeData(tChargeData& data) override;
19 	bool GetClimateData(tClimateData& data) override;
20 	bool IsAwake() override;
21 private:
22 	enum eApiMethod {
23 		Post,
24 		Get
25 	};
26 	bool GetData(std::string datatype, Json::Value& reply);
27 	bool SendCommand(std::string command, Json::Value& reply, std::string parameters = "");
28 	bool FindCarInAccount();
29 	void GetLocationData(Json::Value& jsondata, tLocationData& data);
30 	void GetChargeData(Json::Value& jsondata, tChargeData& data);
31 	void GetClimateData(Json::Value& jsondata, tClimateData& data);
32 	bool GetAuthToken(const std::string username, const std::string password, const bool refreshUsingToken = false);
33 	bool SendToApi(const eApiMethod eMethod, const std::string& sUrl, const std::string& sPostData, std::string& sResponse, const std::vector<std::string>& vExtraHeaders, Json::Value& jsDecodedResponse, const bool bSendAuthHeaders = true);
34 
35 	std::string m_username;
36 	std::string m_password;
37 	std::string m_VIN;
38 
39 	std::string m_authtoken;
40 	std::string m_refreshtoken;
41 	int64_t m_carid;
42 };
43 
44