mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-23 07:36:31 +01:00
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
|
|
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
|
|
using TINK.Model.Bikes.BikeInfoNS.DriveNS.EngineNS;
|
|
using TINK.Repository.Response;
|
|
|
|
namespace TINK.Model.Connector.Updater
|
|
{
|
|
public static class DriveFactory
|
|
{
|
|
public static Drive Create(this BikeType bikeType)
|
|
{
|
|
if (string.IsNullOrEmpty(bikeType?.engine?.manufacturer))
|
|
{
|
|
// Bike is has no engine
|
|
return new Drive();
|
|
}
|
|
|
|
// Bike is a pedelec.
|
|
return new Drive(
|
|
new Engine(bikeType?.engine?.manufacturer),
|
|
new Battery.Builder
|
|
{
|
|
CurrentChargePercent = double.TryParse(bikeType?.battery?.charge_current_percent, out double currentChargePercent)
|
|
? currentChargePercent
|
|
: double.NaN,
|
|
|
|
CurrentChargeBars = int.TryParse(bikeType?.battery?.charge_current_bars, out int currentChargeBars)
|
|
? (int?)currentChargeBars
|
|
: null,
|
|
|
|
MaxChargeBars = int.TryParse(bikeType?.battery?.charge_max_bars, out int maxChargeBars)
|
|
? (int?)maxChargeBars
|
|
: null,
|
|
|
|
IsBackendAccessible = bikeType?.battery?.backend_accessible != null && int.TryParse(bikeType.battery.backend_accessible, out int accessible)
|
|
? (bool?)(accessible > 0)
|
|
: null,
|
|
|
|
IsHidden = bikeType?.battery?.hidden != null && int.TryParse(bikeType.battery.hidden, out int hidden)
|
|
? (bool?)(hidden > 0)
|
|
: null
|
|
}.Build());
|
|
}
|
|
}
|
|
}
|