-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRunExample.php
124 lines (105 loc) · 3.48 KB
/
RunExample.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
require_once __DIR__ . '/vendor/autoload.php';
use RenaultZoeApi\Giya;
use RenaultZoeApi\Kamereon;
// Run example
run();
/**
* Run Example function
* To avoid to login to API each call, we save tokens in credentials.json
*
* @return void
*/
function run()
{
say('> Run started');
$arrTokens = []; // Will contains token from credentials.json
$strFile = dirname(__FILE__) . '/data/credentials.json';
if (file_exists($strFile)) {
say('> credentias.json exists, reading it');
$arrTokens = json_decode(file_get_contents($strFile), true);
// Check token validity
checkTokens($arrTokens);
} else {
say('> credentials.json not found, first login');
$arrGiyaTokens = Giya::login('my_renault_login', 'my_renault_password');
// get AccountId and save tokens in credentials.json file
$arrTokens = Kamereon::getAccounts($arrGiyaTokens);
Kamereon::getVehicles($arrTokens); // You can get VIN here
}
// Example via Kamereon class
say('> getBattery via Kamereon class');
$strJson = Kamereon::getBattery('my_vin', $arrTokens);
say($strJson);
say('> getCockpit via Kamereon class');
$strJson = Kamereon::getCockpit('my_vin', $arrTokens);
say($strJson);
say('> getLocation via Kamereon class');
$strJson = Kamereon::getLocation('my_vin', $arrTokens);
say($strJson);
say('> getChargingSettings via Kamereon class');
$strJson = Kamereon::getChargingSettings('my_vin', $arrTokens);
say($strJson);
say('> getChargeMode via Kamereon class');
$strJson = Kamereon::getChargeMode('my_vin', $arrTokens);
say($strJson);
/* Not implemented server side
say('> getLockStatus via Kamereon class');
$strJson = Kamereon::getLockStatus('my_vin', $arrTokens);
say($strJson);
*/
/* Not implemented server side
say('> getNotificationSettings via Kamereon class');
$strJson = Kamereon::getNotificationSettings('my_vin', $arrTokens);
say($strJson);
*/
/* Not implemented server side
say('> getHvacHistory via Kamereon class');
$strJson = Kamereon::getHvacHistory('my_vin',['type'=>'day','start'=>'20200701','end'=>'20200731'], $arrTokens);
say($strJson);
*/
/*
say('> getHvacHSessions via Kamereon class');
$strJson = Kamereon::getHvacSessions('my_vin',['start'=>'20200701','end'=>'20200731'], $arrTokens);
say($strJson);
*/
/*
say('> getHvacStatus via Kamereon class');
$strJson = Kamereon::getHvacStatus('my_vin', $arrTokens);
say($strJson);
*/
// Example via Vehicle class
// TODO
}
/**
* Check token validity and update them
*
* @param array $arrTokens
* @return void
*/
function checkTokens(&$arrTokens)
{
$objDate = new \DateTime($arrTokens['GiyaIdTokenTime']);
$objDateNow = new \DateTime("now");
$objDate->add(new \DateInterval('PT900S'));
if ($objDate < $objDateNow) {
// Refresh token
say('> Tokens needs refresh');
// Refresh tokens
$arrGiyaIdToken = Giya::getJwtToken($arrTokens['GiyaToken'], '', '');
$arrTokens['GiyaIdTokenTime'] = $arrGiyaIdToken['GiyaIdTokenTime'];
$arrTokens['GiyaIdToken'] = $arrGiyaIdToken['GiyaIdToken'];
Kamereon::saveTokens($arrTokens);
// From an update of Renault API in june 2020, kamereon-authorization token is no more required
}
}
/**
* Makes echo !
*
* @param string $strMessage
* @return void
*/
function say($strMessage)
{
echo $strMessage . "\n\r";
}