Update README.

Update README.

Update README.

Throw errors were possible.

Sometimes racr is simply empty. If it is empty HVAC is not on (an assumption).

Change homepage to Gitlab.

For some odd reason VehicleInfoList is not present on 1th gen Leafs. It is only there for 2nd gen Leafs. Should fix problems for people with 1th gen Leaf.

For some reason electricCostScale can vary from country to country.

.
parent 140959f1
# dartcarwings
A library for the Nissan Leaf Carwings API.
A Dart library for the Nissan Leaf Carwings API.
Through the Carwings API you can ask your vehicle for the latest data, see current battery and charging statuses, see the current climate control state, start or stop climate control remotely, remotely start charging, and retrieve the last known location of the vehicle.
......@@ -17,7 +17,7 @@ A simple usage example:
.login(
username: "username",
password: "password",
blowfishEncryptCallback: (String key, password) async {
blowfishEncryptCallback: (String key, String password) async {
// No native support for Blowfish encryption with Dart
// Use external service
})
......@@ -26,6 +26,6 @@ A simple usage example:
print(battery.batteryPercentage);
print(battery.cruisingRangeAcOffKm);
print(battery.cruisingRangeAcOnKm);
});
});
});
}
......@@ -25,7 +25,7 @@ main() {
print(battery.cruisingRangeAcOffKm);
print(battery.cruisingRangeAcOnKm);
});*/
vehicle.requestStatisticsDaily().then((stats) {
/* vehicle.requestStatisticsDaily().then((stats) {
print(stats.KWhPerMileage);
print(stats.mileagePerKWh);
print(stats.accelerationWh);
......@@ -33,14 +33,14 @@ main() {
print(stats.auxWh);
print(stats.mileageLevel);
print(stats.date);
});
/* vehicle.requestBatteryStatusLatest().then((battery) {
});*/
vehicle.requestBatteryStatusLatest().then((battery) {
print(battery.batteryPercentage);
print(battery.cruisingRangeAcOffKm);
print(battery.cruisingRangeAcOnKm);
print(battery.timeToFullTrickle.inHours);
print(battery.timeToFullL2_6kw.inHours);
});*/
});
//leaf.requestClimateControlOff().then((_) => print('climate control off'));
/* vehicle.requestStatisticsMonthly(new DateTime(2018, 7)).then((stats) {
if(stats != null) {
......
......@@ -7,11 +7,15 @@ class CarwingsHVAC {
CarwingsHVAC(Map params) {
var racr = params['RemoteACRecords'];
this.isRunning = racr['OperationResult'] != null &&
// Sometimes racr is simply empty
// If it is empty HVAC is not on (an assumption)
this.isRunning = racr.length > 0 && racr['OperationResult'] != null &&
racr['OperationResult'].toString().startsWith('START') &&
racr['RemoteACOperation'] == 'START';
this.preACTemp = racr['PreAC_temp'];
this.preACTempUnit = racr['PreAC_unit'];
this.incTemp = racr['Inc_temp'];
if(racr.length > 0) {
this.preACTemp = racr['PreAC_temp'];
this.preACTempUnit = racr['PreAC_unit'];
this.incTemp = racr['Inc_temp'];
}
}
}
......@@ -23,6 +23,7 @@ class CarwingsStatsDaily {
this.electricCostScale =
params["DriveAnalysisBasicScreenResponsePersonalData"]
["ElectricCostScale"];
// For some reason electricCostScale can vary from country to country
if (electricCostScale == 'kWh/km') {
this.KWhPerMileage =
numberFormat.format(double.parse(summary['ElectricMileage'])) +
......@@ -30,6 +31,13 @@ class CarwingsStatsDaily {
this.mileagePerKWh =
numberFormat.format((1 / double.parse(summary['ElectricMileage']))) +
' km/kWh';
} else if (electricCostScale == 'km/kWh') {
this.KWhPerMileage =
numberFormat.format(1 / (double.parse(summary['ElectricMileage']))) +
' kWh/km';
this.mileagePerKWh =
numberFormat.format(double.parse(summary['ElectricMileage'])) +
' km/kWh';
} else {
this.KWhPerMileage =
numberFormat.format(double.parse(summary['ElectricMileage'])) +
......
......@@ -26,6 +26,7 @@ class CarwingsStatsMonthly {
this.totalConsumptionKWh =
numberFormat.format(double.parse(t['TotalPowerConsumptTotal'])) +
' kWh';
// For some reason electricCostScale can vary from country to country
if (electricCostScale == 'kWh/km') {
this.mileageUnit = 'km';
this.totalTravelDistanceMileage = new NumberFormat('0')
......@@ -43,6 +44,22 @@ class CarwingsStatsMonthly {
' ' +
mileageUnit +
'/kWh';
} else if (electricCostScale == 'km/kWh') {
this.mileageUnit = 'km';
this.totalTravelDistanceMileage = new NumberFormat('0')
.format(double.parse(t['TotalTravelDistance']) / 1000) +
' ' +
mileageUnit;
this.totalkWhPerMileage = numberFormat.format( 1 /
(double.parse(t['TotalPowerConsumptTotal']) /
(double.parse(t['TotalTravelDistance']) / 1000))) +
' kWh/'+ mileageUnit;
this.totalMileagePerKWh = numberFormat.format(
double.parse(t['TotalPowerConsumptTotal']) /
(double.parse(t['TotalTravelDistance']) / 1000)) +
' ' +
mileageUnit +
'/kWh';
} else {
this.mileageUnit = 'mi';
this.totalTravelDistanceMileage = new NumberFormat('0')
......
......@@ -22,8 +22,14 @@ class CarwingsVehicle {
CarwingsVehicle(CarwingsSession session, Map params) {
this._session = session;
this.vin = params["VehicleInfoList"]["vehicleInfo"][0]["vin"];
this.nickname = params["VehicleInfoList"]["vehicleInfo"][0]["nickname"];
this.vin = params["vehicle"]["profile"]["vin"];
// For some odd reason VehicleInfoList is not present on 1th gen Leafs
// It is only there for 2nd gen Leafs
if (params["VehicleInfoList"] != null) {
this.nickname = params["VehicleInfoList"]["vehicleInfo"][0]["nickname"];
} else {
this.nickname = params["vehicleInfo"][0]['nickname'];
}
this._boundTime =
params["CustomerInfo"]["VehicleInfo"]["UserVehicleBoundTime"];
this.model = params['CustomerInfo']['VehicleInfo']['CarName'];
......@@ -139,7 +145,7 @@ class CarwingsVehicle {
// For some weird reason ExecuteTime is always in UTC/GMT
// regardless of tz
Future<bool> requestClimateControlSchedule(DateTime startTime) async {
Future<Null> requestClimateControlSchedule(DateTime startTime) async {
var response =
await _session.requestWithRetry("ACRemoteUpdateRequest.php", {
"RegionCode": _session.getRegion(),
......@@ -150,12 +156,12 @@ class CarwingsVehicle {
"ExecuteTime": _executeTimeFormatter.format(startTime.toUtc())
});
if (response['status'] == 200) {
return true;
return;
}
return false;
throw 'Error';
}
Future<bool> requestClimateControlScheduleCancel() async {
Future<Null> requestClimateControlScheduleCancel() async {
var response =
await _session.requestWithRetry("ACRemoteCancelRequest.php", {
"RegionCode": _session.getRegion(),
......@@ -165,9 +171,9 @@ class CarwingsVehicle {
"tz": _session.tz
});
if (response['status'] == 200) {
return true;
return;
}
return false;
throw 'Error';
}
// For some weird reason DisplayExecuteTime returns time in local time zone
......@@ -187,12 +193,12 @@ class CarwingsVehicle {
.parse(response['DisplayExecuteTime']);
}
}
return null;
throw 'Error';
}
// For some weird reason ExecuteTime is always in UTC/GMT
// regardless of tz
Future<bool> requestChargingStart(DateTime startTime) async {
Future<Null> requestChargingStart(DateTime startTime) async {
var response =
await _session.requestWithRetry("BatteryRemoteChargingRequest.php", {
"RegionCode": _session.getRegion(),
......@@ -203,9 +209,9 @@ class CarwingsVehicle {
"ExecuteTime": _executeTimeFormatter.format(startTime.toUtc())
});
if (response['status'] == 200) {
return true;
return;
}
return false;
throw 'Error';
}
Future<CarwingsStatsMonthly> requestStatisticsMonthly(DateTime month) async {
......@@ -221,7 +227,7 @@ class CarwingsVehicle {
if (response['status'] == 200) {
return new CarwingsStatsMonthly(response);
}
return null;
throw 'Error';
}
Future<CarwingsStatsDaily> requestStatisticsDaily() async {
......@@ -236,7 +242,7 @@ class CarwingsVehicle {
if (response['status'] == 200) {
return new CarwingsStatsDaily(response);
}
return null;
throw 'Error';
}
Future<CarwingsHVAC> requestHVACStatus() async {
......@@ -252,7 +258,7 @@ class CarwingsVehicle {
if (response['status'] == 200) {
return new CarwingsHVAC(response);
}
return null;
throw 'Error';
}
Future<CarwingsBattery> requestBatteryStatusLatest() async {
......@@ -268,7 +274,7 @@ class CarwingsVehicle {
if (response['status'] == 200) {
return new CarwingsBattery.batteryLatest(response);
}
return null;
throw 'Error';
}
Future<CarwingsLocation> requestLocation() async {
......
name: dartcarwings
description: A library for the Nissan Leaf Carwings API.
version: 0.0.1
homepage: https://bitbucket.org/Tobiaswk/dartcarwings
homepage: https://gitlab.com/tobiaswkjeldsen/dartcarwings
author: Tobias Westergaard Kjeldsen <[email protected]>
environment:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment