sharee.bike-App/TINKLib/Model/Connector/Updater/DriveFactory.cs

46 lines
1.4 KiB
C#
Raw Normal View History

2022-08-30 15:42:25 +02:00
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
{
2022-09-06 16:08:19 +02:00
public static class DriveFactory
{
2023-08-31 12:31:38 +02:00
public static DriveMutable Create(this BikeType bikeType)
2022-09-06 16:08:19 +02:00
{
if (string.IsNullOrEmpty(bikeType?.engine?.manufacturer))
{
// Bike is has no engine
2023-08-31 12:31:38 +02:00
return new DriveMutable();
2022-09-06 16:08:19 +02:00
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
// Bike is a pedelec.
2023-08-31 12:31:38 +02:00
return new DriveMutable(
2022-09-06 16:08:19 +02:00
new Engine(bikeType?.engine?.manufacturer),
new Battery.Builder
{
CurrentChargePercent = double.TryParse(bikeType?.battery?.charge_current_percent, out double currentChargePercent)
? currentChargePercent
: double.NaN,
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
CurrentChargeBars = int.TryParse(bikeType?.battery?.charge_current_bars, out int currentChargeBars)
? (int?)currentChargeBars
: null,
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
MaxChargeBars = int.TryParse(bikeType?.battery?.charge_max_bars, out int maxChargeBars)
? (int?)maxChargeBars
: null,
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
IsBackendAccessible = bikeType?.battery?.backend_accessible != null && int.TryParse(bikeType.battery.backend_accessible, out int accessible)
? (bool?)(accessible > 0)
: null,
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
IsHidden = bikeType?.battery?.hidden != null && int.TryParse(bikeType.battery.hidden, out int hidden)
? (bool?)(hidden > 0)
: null
}.Build());
}
}
2022-08-30 15:42:25 +02:00
}