Tidy up

parent a0db66d1
......@@ -8,4 +8,4 @@ export 'src/carwings_stats_daily.dart';
export 'src/carwings_stats_monthly.dart';
export 'src/carwings_stats_trips.dart';
export 'src/carwings_cabin_temperature.dart';
export 'src/carwings_vehicle.dart';
\ No newline at end of file
export 'src/carwings_vehicle.dart';
import 'package:intl/intl.dart';
class CarwingsBattery {
NumberFormat numberFormat = new NumberFormat('0');
NumberFormat numberFormat = NumberFormat('0');
DateTime dateTime;
double batteryLevelCapacity;
......@@ -11,7 +11,8 @@ class CarwingsBattery {
bool isQuickCharging = false;
bool isConnectedToQuickCharging = false;
String batteryPercentage;
String battery12thBar; // Leaf using 12th bar system; present as 12ths; 5/12 etc.
String
battery12thBar; // Leaf using 12th bar system; present as 12ths; 5/12 etc.
String cruisingRangeAcOffKm;
String cruisingRangeAcOffMiles;
String cruisingRangeAcOnKm;
......@@ -24,7 +25,7 @@ class CarwingsBattery {
CarwingsBattery(Map params) {
//this.timeStamp = new DateFormat('yyyy-MM-dd H:m:s').parse(params['timeStamp']);
this.dateTime = new DateTime.now(); // Always now
this.dateTime = DateTime.now(); // Always now
this.batteryLevelCapacity = double.parse(params['batteryCapacity']);
this.batteryLevel = double.parse(params['batteryDegradation']);
this.isConnected = params['pluginState'] != 'NOT_CONNECTED';
......@@ -38,24 +39,24 @@ class CarwingsBattery {
numberFormat.format(double.parse(params['cruisingRangeAcOff']) / 1000) +
' km';
this.cruisingRangeAcOffMiles = numberFormat
.format(double.parse(params['cruisingRangeAcOff']) * 0.0006213712) +
.format(double.parse(params['cruisingRangeAcOff']) * 0.0006213712) +
' mi';
this.cruisingRangeAcOnKm =
numberFormat.format(double.parse(params['cruisingRangeAcOn']) / 1000) +
' km';
this.cruisingRangeAcOnMiles = numberFormat
.format(double.parse(params['cruisingRangeAcOn']) * 0.0006213712) +
.format(double.parse(params['cruisingRangeAcOn']) * 0.0006213712) +
' mi';
this.timeToFullTrickle =
new Duration(minutes: _timeRemaining(params['TimeRequiredToFull']));
Duration(minutes: _timeRemaining(params['TimeRequiredToFull']));
this.timeToFullL2 =
new Duration(minutes: _timeRemaining(params['TimeRequiredToFull200']));
this.timeToFullL2_6kw = new Duration(
minutes: _timeRemaining(params['TimeRequiredToFull200_6kW']));
Duration(minutes: _timeRemaining(params['TimeRequiredToFull200']));
this.timeToFullL2_6kw =
Duration(minutes: _timeRemaining(params['TimeRequiredToFull200_6kW']));
}
CarwingsBattery.batteryLatest(Map params) {
var recs = params["BatteryStatusRecords"];
var recs = params['BatteryStatusRecords'];
var bs = recs['BatteryStatus'];
// TargetDate or NotificationDateAndTime needs to be used in the future
......@@ -63,23 +64,25 @@ class CarwingsBattery {
// Until better timezone support has been added to Dart this will do
try {
this.dateTime =
new DateFormat('d-M-yyyy H:m').parse(recs['OperationDateAndTime']);
DateFormat('d-M-yyyy H:m').parse(recs['OperationDateAndTime']);
} catch (e) {
try {
this.dateTime = new DateFormat('dd-MMM-yyyy H:m')
.parse(recs['OperationDateAndTime']);
this.dateTime =
DateFormat('dd-MMM-yyyy H:m').parse(recs['OperationDateAndTime']);
} catch (e) {
try {
this.dateTime = new DateFormat('DD.MMM yyyy HH:mm')
this.dateTime = DateFormat('DD.MMM yyyy HH:mm')
.parse(recs['OperationDateAndTime']);
} catch (e) {
try {
this.dateTime = new DateFormat('MMM DD, yyyy HH:mm a').parse(recs['OperationDateAndTime']);
this.dateTime = DateFormat('MMM DD, yyyy HH:mm a')
.parse(recs['OperationDateAndTime']);
} catch (e) {
try {
this.dateTime = new DateFormat('d-MMM-yyyy HH:mm').parse(recs['OperationDateAndTime']);
this.dateTime = DateFormat('d-MMM-yyyy HH:mm')
.parse(recs['OperationDateAndTime']);
} catch (e) {
this.dateTime = new DateTime.now(); // Just use now
this.dateTime = DateTime.now(); // Just use now
}
}
}
......@@ -91,63 +94,58 @@ class CarwingsBattery {
this.isCharging = bs['BatteryChargingStatus'] != 'NOT_CHARGING';
this.isQuickCharging = bs['BatteryChargingStatus'] == 'RAPIDLY_CHARGING';
this.isConnectedToQuickCharging = recs['PluginState'] == 'QC_CONNECTED';
this.batteryPercentage = new NumberFormat('0.0')
.format((this.batteryLevel * 100) / this.batteryLevelCapacity)
.toString() +
this.batteryPercentage = NumberFormat('0.0')
.format((this.batteryLevel * 100) / this.batteryLevelCapacity)
.toString() +
'%';
// If SOC is available; use it
if (bs['SOC'] != null && bs['SOC']['Value'] != null) {
double SOC = double.parse(bs['SOC']['Value']);
this.batteryPercentage =
new NumberFormat('0.0').format(SOC).toString() + '%';
this.batteryPercentage = NumberFormat('0.0').format(SOC).toString() + '%';
}
if (batteryLevelCapacity >= 0.0 && batteryLevelCapacity <= 12.0) {
// Leaf using 12th bar system; present as 12ths; 5/12 etc.
// batteryLevelCapacity can be lower than 12 because of degradation
// we explicitly use 12 instead of batteryLevelCapacity
this.battery12thBar =
"${numberFormat.format(batteryLevel)} / 12";
this.batteryPercentage = new NumberFormat('0.0')
.format((this.batteryLevel * 100) / 12)
.toString() +
'%';
this.battery12thBar = '${numberFormat.format(batteryLevel)} / 12';
this.batteryPercentage = NumberFormat('0.0')
.format((this.batteryLevel * 100) / 12)
.toString() +
'%';
}
this.cruisingRangeAcOffKm =
numberFormat.format(double.parse(recs['CruisingRangeAcOff']) / 1000) +
' km';
this.cruisingRangeAcOffMiles = numberFormat
.format(double.parse(recs['CruisingRangeAcOff']) * 0.0006213712) +
.format(double.parse(recs['CruisingRangeAcOff']) * 0.0006213712) +
' mi';
this.cruisingRangeAcOnKm =
numberFormat.format(double.parse(recs['CruisingRangeAcOn']) / 1000) +
' km';
this.cruisingRangeAcOnMiles = numberFormat
.format(double.parse(recs['CruisingRangeAcOn']) * 0.0006213712) +
.format(double.parse(recs['CruisingRangeAcOn']) * 0.0006213712) +
' mi';
this.timeToFullTrickle =
new Duration(minutes: _timeRemaining(recs['TimeRequiredToFull']));
Duration(minutes: _timeRemaining(recs['TimeRequiredToFull']));
this.timeToFullL2 =
new Duration(minutes: _timeRemaining(recs['TimeRequiredToFull200']));
this.timeToFullL2_6kw = new Duration(
minutes: _timeRemaining(recs['TimeRequiredToFull200_6kW']));
Duration(minutes: _timeRemaining(recs['TimeRequiredToFull200']));
this.timeToFullL2_6kw =
Duration(minutes: _timeRemaining(recs['TimeRequiredToFull200_6kW']));
if (isQuickCharging) {
chargingkWLevelText = "left to charge at ~40kW";
chargingRemainingText = "usually 50 mins";
chargingkWLevelText = 'left to charge at ~40kW';
chargingRemainingText = 'usually 50 mins';
} else if (timeToFullTrickle.inHours != 0) {
chargingkWLevelText = "left to charge at ~1kW";
chargingkWLevelText = 'left to charge at ~1kW';
chargingRemainingText =
"${(timeToFullTrickle.inMinutes / 60).floor()} hrs ${timeToFullTrickle
.inMinutes % 60} mins";
'${(timeToFullTrickle.inMinutes / 60).floor()} hrs ${timeToFullTrickle.inMinutes % 60} mins';
} else if (timeToFullL2.inHours != 0) {
chargingkWLevelText = "left to charge at ~3kW";
chargingkWLevelText = 'left to charge at ~3kW';
chargingRemainingText =
"${(timeToFullL2.inMinutes / 60).floor()} hrs ${timeToFullL2.inMinutes %
60} mins";
'${(timeToFullL2.inMinutes / 60).floor()} hrs ${timeToFullL2.inMinutes % 60} mins';
} else if (timeToFullL2_6kw.inHours != 0) {
chargingkWLevelText = "left to charge at ~6kW";
chargingkWLevelText = 'left to charge at ~6kW';
chargingRemainingText =
"${(timeToFullL2_6kw.inMinutes / 60).floor()} hrs ${timeToFullL2_6kw
.inMinutes % 60} mins";
'${(timeToFullL2_6kw.inMinutes / 60).floor()} hrs ${timeToFullL2_6kw.inMinutes % 60} mins';
}
}
......
......@@ -8,11 +8,10 @@ class CarwingsCabinTemperature {
}
CarwingsCabinTemperature.latest(Map params) {
var data = params["CabinTemp"];
var data = params['CabinTemp'];
//this.timeStamp = new DateFormat('yyyy/M/d H:m').parse(data['DateAndTime']);
this.timeStamp = DateTime.now();
this.temperature = data['Inc_temp'];
}
}
......@@ -9,10 +9,11 @@ class CarwingsHVAC {
// Sometimes racr is simply empty
// If it is empty HVAC is not on (an assumption)
this.isRunning = racr.length > 0 && racr['OperationResult'] != null &&
this.isRunning = racr.length > 0 &&
racr['OperationResult'] != null &&
racr['OperationResult'].toString().startsWith('START') &&
racr['RemoteACOperation'] == 'START';
if(racr.length > 0) {
if (racr.length > 0) {
this.preACTemp = racr['PreAC_temp'];
this.preACTempUnit = racr['PreAC_unit'];
this.incTemp = racr['Inc_temp'];
......
......@@ -3,4 +3,4 @@ class CarwingsLocation {
var longitude;
CarwingsLocation(this.latitude, this.longitude);
}
\ No newline at end of file
}
......@@ -6,18 +6,18 @@ import 'package:dartcarwings/src/carwings_vehicle.dart';
enum CarwingsRegion { USA, Europe, Canada, Australia, Japan }
class CarwingsSession {
final String baseUrl = "https://gdcportalgw.its-mo.com/api_v190426_NE/gdc/";
final String baseUrl = 'https://gdcportalgw.its-mo.com/api_v190426_NE/gdc/';
// Result of the call to InitialApp.php, which appears to
// always be the same. It'll probably break at some point but
// for now... skip it.
final String blowfishKey = "uyI5Dj9g8VCOFDnBRUbr3g";
final String blowfishKey = 'uyI5Dj9g8VCOFDnBRUbr3g';
// Extracted from the NissanConnect EV app
final String initialAppStrings = "9s5rfKVuMrT03RtzajWNcA";
final String initialAppStrings = '9s5rfKVuMrT03RtzajWNcA';
bool debug;
List<String> debugLog = new List<String>();
List<String> debugLog = List<String>();
// If this is set it will override the time zone returned from Carwings API
var timeZoneOverride;
......@@ -69,7 +69,7 @@ class CarwingsSession {
_print('Params: $params');
http.Response response =
await http.post("${baseUrl}${endpoint}", body: params);
await http.post('${baseUrl}${endpoint}', body: params);
dynamic jsonData = json.decode(response.body);
......@@ -91,54 +91,54 @@ class CarwingsSession {
loggedIn = false;
var response = await request("InitialApp_v2.php",
{"RegionCode": _getRegionName(region), "lg": "en-US"});
var response = await request('InitialApp_v2.php',
{'RegionCode': _getRegionName(region), 'lg': 'en-US'});
var encodedPassword =
await blowfishEncryptCallback(response['baseprm'], password);
response = await request("UserLoginRequest.php", {
"RegionCode": _getRegionName(region),
"UserId": username,
"Password": encodedPassword
response = await request('UserLoginRequest.php', {
'RegionCode': _getRegionName(region),
'UserId': username,
'Password': encodedPassword
});
if (response['status'] != 200) {
throw 'Login error';
}
language = response['CustomerInfo']["Language"];
gdcUserId = response["vehicle"]["profile"]["gdcUserId"];
dcmId = response["vehicle"]["profile"]["dcmId"];
timeZoneProvided = response["CustomerInfo"]["Timezone"];
language = response['CustomerInfo']['Language'];
gdcUserId = response['vehicle']['profile']['gdcUserId'];
dcmId = response['vehicle']['profile']['dcmId'];
timeZoneProvided = response['CustomerInfo']['Timezone'];
// With more than one vehicle this value makes little sense
try {
modelYear = int.parse(response["vehicle"]["profile"]["modelyear"]);
modelYear = int.parse(response['vehicle']['profile']['modelyear']);
} catch (e) {}
loggedIn = true;
vehicles = new List<CarwingsVehicle>();
vehicles = List<CarwingsVehicle>();
// For some odd reason VehicleInfoList is not present on 1th gen Leafs
// It is only there for 2nd gen Leafs
if (response["VehicleInfoList"] != null) {
for (Map vehicleInfo in response["VehicleInfoList"]["vehicleInfo"]) {
vehicles.add(new CarwingsVehicle(
if (response['VehicleInfoList'] != null) {
for (Map vehicleInfo in response['VehicleInfoList']['vehicleInfo']) {
vehicles.add(CarwingsVehicle(
this,
vehicleInfo['custom_sessionid'],
vehicleInfo['vin'],
vehicleInfo['nickname'],
response["CustomerInfo"]["VehicleInfo"]["UserVehicleBoundTime"],
response['CustomerInfo']['VehicleInfo']['UserVehicleBoundTime'],
response['CustomerInfo']['VehicleInfo']['CarName']));
}
} else {
for (Map vehicleInfo in response["vehicleInfo"]) {
vehicles.add(new CarwingsVehicle(
for (Map vehicleInfo in response['vehicleInfo']) {
vehicles.add(CarwingsVehicle(
this,
vehicleInfo['custom_sessionid'],
vehicleInfo['vin'],
vehicleInfo['nickname'],
response["CustomerInfo"]["VehicleInfo"]["UserVehicleBoundTime"],
response['CustomerInfo']['VehicleInfo']['UserVehicleBoundTime'],
response['CustomerInfo']['VehicleInfo']['CarName']));
}
}
......@@ -164,17 +164,17 @@ class CarwingsSession {
String _getRegionName(CarwingsRegion region) {
switch (region) {
case CarwingsRegion.USA:
return "NNA";
return 'NNA';
case CarwingsRegion.Europe:
return "NE";
return 'NE';
case CarwingsRegion.Canada:
return "NCI";
return 'NCI';
case CarwingsRegion.Australia:
return "NMA";
return 'NMA';
case CarwingsRegion.Japan:
return "NML";
return 'NML';
default:
return "NE";
return 'NE';
}
}
......
......@@ -17,12 +17,12 @@ class CarwingsStatsDaily {
var summary =
params['DriveAnalysisBasicScreenResponsePersonalData']['DateSummary'];
NumberFormat numberFormat = new NumberFormat('0.00');
NumberFormat numberFormat = NumberFormat('0.00');
this.dateTime = new DateFormat('yyyy-MM-dd').parse(summary['TargetDate']);
this.dateTime = DateFormat('yyyy-MM-dd').parse(summary['TargetDate']);
this.electricCostScale =
params["DriveAnalysisBasicScreenResponsePersonalData"]
["ElectricCostScale"];
params['DriveAnalysisBasicScreenResponsePersonalData']
['ElectricCostScale'];
// For some reason electricCostScale can vary from country to country
if (electricCostScale == 'kWh/km') {
this.KWhPerMileage =
......@@ -49,9 +49,9 @@ class CarwingsStatsDaily {
this.KWhPerMileage =
numberFormat.format(1 / double.parse(summary['ElectricMileage'])) +
' kWh/mi';
this.mileagePerKWh = numberFormat
.format(double.parse(summary['ElectricMileage'])) +
' mi/kWh';
this.mileagePerKWh =
numberFormat.format(double.parse(summary['ElectricMileage'])) +
' mi/kWh';
} else {
this.KWhPerMileage =
numberFormat.format(double.parse(summary['ElectricMileage'])) +
......@@ -60,17 +60,17 @@ class CarwingsStatsDaily {
numberFormat.format((1 / double.parse(summary['ElectricMileage']))) +
' mi/kWh';
}
this.mileageLevel = summary['ElectricMileageLevel'] ?? "0";
this.mileageLevel = summary['ElectricMileageLevel'] ?? '0';
this.accelerationWh =
numberFormat.format(double.parse(summary['PowerConsumptMoter'])) +
' Wh';
this.accelerationLevel = summary['PowerConsumptMoterLevel'] ?? "0";
this.accelerationLevel = summary['PowerConsumptMoterLevel'] ?? '0';
this.regenerativeWh =
numberFormat.format(double.parse(summary['PowerConsumptMinus'])) +
' Wh';
this.regenerativeLevel = summary['PowerConsumptMinusLevel'] ?? "0";
this.regenerativeLevel = summary['PowerConsumptMinusLevel'] ?? '0';
this.auxWh =
numberFormat.format(double.parse(summary['PowerConsumptAUX'])) + ' Wh';
this.auxLevel = summary['PowerConsumptAUXLevel'] ?? "0";
this.auxLevel = summary['PowerConsumptAUXLevel'] ?? '0';
}
}
......@@ -15,13 +15,13 @@ class CarwingsStatsMonthly {
var r = params['PriceSimulatorDetailInfoResponsePersonalData'];
var t = r['PriceSimulatorTotalInfo'];
NumberFormat numberFormat = new NumberFormat('0.00');
NumberFormat numberFormat = NumberFormat('0.00');
this.electricCostScale =
params["PriceSimulatorDetailInfoResponsePersonalData"]
params['PriceSimulatorDetailInfoResponsePersonalData']
['ElectricCostScale'];
this.dateTime = new DateFormat('MMM/y').parse(r['DisplayMonth']);
this.dateTime = DateFormat('MMM/y').parse(r['DisplayMonth']);
this.totalNumberOfTrips = t['TotalNumberOfTrips'];
this.totalConsumptionKWh =
numberFormat.format(double.parse(t['TotalPowerConsumptTotal'])) +
......@@ -29,7 +29,7 @@ class CarwingsStatsMonthly {
// For some reason electricCostScale can vary from country to country
if (electricCostScale == 'kWh/km') {
this.mileageUnit = 'km';
this.totalTravelDistanceMileage = new NumberFormat('0')
this.totalTravelDistanceMileage = NumberFormat('0')
.format(double.parse(t['TotalTravelDistance']) / 1000) +
' ' +
mileageUnit;
......@@ -46,7 +46,7 @@ class CarwingsStatsMonthly {
'/kWh';
} else if (electricCostScale == 'km/kWh') {
this.mileageUnit = 'km';
this.totalTravelDistanceMileage = new NumberFormat('0')
this.totalTravelDistanceMileage = NumberFormat('0')
.format(double.parse(t['TotalTravelDistance']) / 1000) +
' ' +
mileageUnit;
......@@ -63,7 +63,7 @@ class CarwingsStatsMonthly {
'/kWh';
} else if (electricCostScale == 'kWh/100km') {
this.mileageUnit = 'km';
this.totalTravelDistanceMileage = new NumberFormat('0')
this.totalTravelDistanceMileage = NumberFormat('0')
.format(double.parse(t['TotalTravelDistance']) / 1000) +
' ' +
mileageUnit;
......@@ -80,7 +80,7 @@ class CarwingsStatsMonthly {
'/kWh';
} else if (electricCostScale == 'miles/kWh') {
this.mileageUnit = 'mi';
this.totalTravelDistanceMileage = new NumberFormat('0')
this.totalTravelDistanceMileage = NumberFormat('0')
.format(double.parse(t['TotalTravelDistance']) * 0.0006213712) +
' ' +
mileageUnit;
......@@ -99,7 +99,7 @@ class CarwingsStatsMonthly {
'/kWh';
} else /*if(electricCostScale == 'kWh/miles')*/ {
this.mileageUnit = 'mi';
this.totalTravelDistanceMileage = new NumberFormat('0')
this.totalTravelDistanceMileage = NumberFormat('0')
.format(double.parse(t['TotalTravelDistance']) * 0.0006213712) +
' ' +
mileageUnit;
......
......@@ -10,7 +10,7 @@ class CarwingsStatsTrips {
CarwingsUnitCalculator carwingsUnitCalculator = CarwingsUnitCalculator();
var electricCostScale =
params["PriceSimulatorDetailInfoResponsePersonalData"]
params['PriceSimulatorDetailInfoResponsePersonalData']
['ElectricCostScale'];
List statsPerDate = params['PriceSimulatorDetailInfoResponsePersonalData']
......
import 'package:intl/intl.dart';
class CarwingsUnitCalculator {
NumberFormat numberFormat00 = new NumberFormat('0.00');
NumberFormat numberFormat0 = new NumberFormat('0');
NumberFormat numberFormat00 = NumberFormat('0.00');
NumberFormat numberFormat0 = NumberFormat('0');
String mileagePerKwh(
double distanceInMeters, double consumption, String electricCostScale) {
......@@ -15,7 +15,8 @@ class CarwingsUnitCalculator {
.format(1 / (consumption / toKilometers(distanceInMeters))) +
' km/kWh';
} else if (electricCostScale == 'kWh/100km') {
numberFormat00.format(1 / (consumption / toKilometers(distanceInMeters))) +
numberFormat00
.format(1 / (consumption / toKilometers(distanceInMeters))) +
' km/kWh';
} else if (electricCostScale == 'miles/kWh') {
return numberFormat00
......@@ -32,13 +33,16 @@ class CarwingsUnitCalculator {
String kWhPerMileage(
double distanceInMeters, double consumption, String electricCostScale) {
if (electricCostScale == 'kWh/km') {
return numberFormat00.format(consumption / toKilometers(distanceInMeters)) +
return numberFormat00
.format(consumption / toKilometers(distanceInMeters)) +
' kWh/km';
} else if (electricCostScale == 'km/kWh') {
return numberFormat00.format(consumption / toKilometers(distanceInMeters)) +
return numberFormat00
.format(consumption / toKilometers(distanceInMeters)) +
' kWh/km';
} else if (electricCostScale == 'kWh/100km') {
return numberFormat00.format(consumption / toKilometers(distanceInMeters)) +
return numberFormat00
.format(consumption / toKilometers(distanceInMeters)) +
' kWh/km';
} else if (electricCostScale == 'miles/kWh') {
return numberFormat00.format(consumption / toMiles(distanceInMeters)) +
......@@ -52,21 +56,16 @@ class CarwingsUnitCalculator {
String distance(double distanceInMeters, String electricCostScale) {
if (electricCostScale == 'kWh/km') {
return numberFormat0.format(toKilometers(distanceInMeters)) +
' km';
return numberFormat0.format(toKilometers(distanceInMeters)) + ' km';
} else if (electricCostScale == 'km/kWh') {
return numberFormat0.format(toKilometers(distanceInMeters)) +
' km';
return numberFormat0.format(toKilometers(distanceInMeters)) + ' km';
} else if (electricCostScale == 'kWh/100km') {
return numberFormat0.format(toKilometers(distanceInMeters)) +
' km';
return numberFormat0.format(toKilometers(distanceInMeters)) + ' km';
} else if (electricCostScale == 'miles/kWh') {
return numberFormat0.format(toMiles(distanceInMeters)) +
' mi';
return numberFormat0.format(toMiles(distanceInMeters)) + ' mi';
} else
/*if(electricCostScale == 'kWh/miles')*/ {
return numberFormat0.format(toMiles(distanceInMeters)) +
' mi';
/*if(electricCostScale == 'kWh/miles')*/ {
return numberFormat0.format(toMiles(distanceInMeters)) + ' mi';
}
}
......
This diff is collapsed.
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