sharee.bike-App/TINKLib/Model/Connector/Updater/DriveFactory.cs
2023-08-31 12:31:38 +02:00

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 DriveMutable Create(this BikeType bikeType)
{
if (string.IsNullOrEmpty(bikeType?.engine?.manufacturer))
{
// Bike is has no engine
return new DriveMutable();
}
// Bike is a pedelec.
return new DriveMutable(
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());
}
}
}