mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-23 05:16:29 +02:00
Version 3.0.381
This commit is contained in:
parent
f963c0a219
commit
3a363acf3a
1525 changed files with 60589 additions and 125098 deletions
|
@ -0,0 +1,113 @@
|
|||
using Serilog;
|
||||
|
||||
namespace ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the state of a chargeable battery.
|
||||
/// </summary>
|
||||
public class Battery : IBattery
|
||||
{
|
||||
private Battery() { }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current charging level of the battery in percent, double.NaN if unknown.
|
||||
/// </summary>
|
||||
public double CurrentChargePercent { get; private set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current charging level of the battery in bars, null if unknown.
|
||||
/// </summary>
|
||||
public int? CurrentChargeBars { get; private set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum charging level of the battery in bars, null if unknown.
|
||||
/// </summary>
|
||||
public int? MaxChargeBars { get; private set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether backend is aware of battery charging level.
|
||||
/// </summary>
|
||||
public bool? IsBackendAccessible { get; private set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether to display battery level or not.
|
||||
/// </summary>
|
||||
public bool? IsHidden { get; private set; } = null;
|
||||
|
||||
public class Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the current charging level of the battery in bars.
|
||||
/// </summary>
|
||||
public int? CurrentChargeBars { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Holds the maximum charging level of the battery in bars.
|
||||
/// </summary>
|
||||
public int? MaxChargeBars { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Holds the current charging level of the battery in percent.
|
||||
/// </summary>
|
||||
public double CurrentChargePercent { get; set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// Holds whether backend is aware of battery charging level.
|
||||
/// </summary>
|
||||
public bool? IsBackendAccessible { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Holds whether to display battery level or not.
|
||||
/// </summary>
|
||||
public bool? IsHidden { get; set; } = null;
|
||||
|
||||
public Battery Build()
|
||||
{
|
||||
if (!double.IsNaN(CurrentChargePercent)
|
||||
&& (CurrentChargePercent < 0 || 100 < CurrentChargePercent))
|
||||
{
|
||||
// Invalid filling level detected
|
||||
CurrentChargePercent = double.NaN;
|
||||
}
|
||||
|
||||
if (CurrentChargeBars < 0)
|
||||
{
|
||||
// Current value of bars must never be smaller zero.
|
||||
CurrentChargeBars = null;
|
||||
}
|
||||
|
||||
if (MaxChargeBars < 0)
|
||||
{
|
||||
// Max value of bars must never be smaller zero.
|
||||
MaxChargeBars = null;
|
||||
}
|
||||
|
||||
if (CurrentChargeBars != null
|
||||
&& MaxChargeBars == null)
|
||||
{
|
||||
// If current charge bars is set, max charge must be set as well.
|
||||
Log.ForContext<Battery>().Error($"Current bars value can not be set to {CurrentChargeBars} if max bars is not set.");
|
||||
CurrentChargeBars = null;
|
||||
}
|
||||
|
||||
if (CurrentChargeBars != null
|
||||
&& MaxChargeBars != null
|
||||
&& CurrentChargeBars > MaxChargeBars)
|
||||
{
|
||||
// If current charge bars must never be larger than max charge bars.
|
||||
Log.ForContext<Battery>().Error($"Invalid current bars value {CurrentChargeBars} detected. Value must never be larger than max value bars {MaxChargeBars}.");
|
||||
CurrentChargeBars = null;
|
||||
}
|
||||
|
||||
return new Battery
|
||||
{
|
||||
CurrentChargeBars = CurrentChargeBars,
|
||||
MaxChargeBars = MaxChargeBars,
|
||||
CurrentChargePercent = CurrentChargePercent,
|
||||
IsBackendAccessible = IsBackendAccessible,
|
||||
IsHidden = IsHidden
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
using System.ComponentModel;
|
||||
|
||||
namespace ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages the state of a chargeable battery.
|
||||
/// </summary>
|
||||
public class BatteryMutable : IBatteryMutable, INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
IBattery _battery;
|
||||
|
||||
public BatteryMutable(IBattery battery)
|
||||
{
|
||||
_battery = battery;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current charging level of the battery in percent, double.NaN if unknown.
|
||||
/// </summary>
|
||||
public double CurrentChargePercent => _battery.CurrentChargePercent;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current charging level of the battery in bars, null if unknown.
|
||||
/// </summary>
|
||||
public int? CurrentChargeBars
|
||||
{
|
||||
get => _battery.CurrentChargeBars;
|
||||
set
|
||||
{
|
||||
double GetCurrentChargePercent()
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
// Filling level is unknown.
|
||||
return double.NaN;
|
||||
}
|
||||
|
||||
if (_battery.MaxChargeBars == null || _battery.MaxChargeBars == 0)
|
||||
{
|
||||
// Percentage filling level can not be calculated.
|
||||
return _battery.CurrentChargePercent;
|
||||
}
|
||||
|
||||
return (int)(100 * value / _battery.MaxChargeBars);
|
||||
}
|
||||
|
||||
if (_battery.CurrentChargeBars == value)
|
||||
{
|
||||
// Nothing to do.
|
||||
return;
|
||||
}
|
||||
|
||||
_battery = new Battery.Builder
|
||||
{
|
||||
MaxChargeBars = _battery.MaxChargeBars,
|
||||
IsBackendAccessible = _battery.IsBackendAccessible,
|
||||
IsHidden = _battery.IsHidden,
|
||||
CurrentChargeBars = value,
|
||||
CurrentChargePercent = GetCurrentChargePercent(),
|
||||
}.Build();
|
||||
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentChargeBars)));
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentChargePercent)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum charging level of the battery in bars, null if unknown.
|
||||
/// </summary>
|
||||
public int? MaxChargeBars => _battery.MaxChargeBars;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether backend is aware of battery charging level.
|
||||
/// </summary>
|
||||
public bool? IsBackendAccessible => _battery.IsBackendAccessible;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether to display battery level or not.
|
||||
/// </summary>
|
||||
public bool? IsHidden => _battery.IsHidden;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
namespace ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS
|
||||
{
|
||||
public interface IBattery
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the current charging level of the battery in percent, double.NaN if unknown.
|
||||
/// </summary>
|
||||
double CurrentChargePercent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the current charging level of the battery in bars. Must not be larger than MaxChargeBars, null if unknown.
|
||||
/// </summary>
|
||||
int? CurrentChargeBars { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the maximum charging level of the battery in bars, null if unknown.
|
||||
/// </summary>
|
||||
int? MaxChargeBars { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds whether backend is aware of battery charging level.
|
||||
/// </summary>
|
||||
bool? IsBackendAccessible { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds whether to display battery level or not.
|
||||
/// </summary>
|
||||
bool? IsHidden { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
using System.ComponentModel;
|
||||
|
||||
namespace ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages the state of a chargeable battery.
|
||||
/// </summary>
|
||||
public interface IBatteryMutable : INotifyPropertyChanged
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the current charging level of the battery in percent, double.NaN if unknown.
|
||||
/// </summary>
|
||||
double CurrentChargePercent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current charging level of the battery in bars. Must not be larger than MaxChargeBars, null if unknown.
|
||||
/// </summary>
|
||||
int? CurrentChargeBars { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum charging level of the battery in bars, null if unknown.
|
||||
/// </summary>
|
||||
int? MaxChargeBars { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether backend is aware of battery charging level.
|
||||
/// </summary>
|
||||
bool? IsBackendAccessible { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether to display battery level or not.
|
||||
/// </summary>
|
||||
bool? IsHidden { get; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue