Version 3.0.371

This commit is contained in:
Anja 2023-08-31 12:31:38 +02:00
parent bdb2dec1c1
commit 6d22dbf40b
145 changed files with 2289 additions and 764 deletions

View file

@ -22,7 +22,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BC
/// <summary>
/// Holds the drive object.
/// </summary>
public Drive Drive { get; }
public DriveMutable Drive { get; }
/// <summary> Gets the information where the data origins from. </summary>
public DataSource DataSource { get; }
@ -32,7 +32,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BC
protected BikeInfo(
IStateInfo stateInfo,
Bike bike,
Drive drive,
DriveMutable drive,
DataSource dataSource,
bool? isDemo = DEFAULTVALUEISDEMO,
IEnumerable<string> group = null,

View file

@ -15,7 +15,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BC
private readonly Bike _Bike;
/// <summary> Holds the drive of the bike. </summary>
private readonly Drive _Drive;
private readonly DriveMutable _Drive;
/// <summary> Holds the state info of the bike. </summary>
private readonly StateInfoMutable _StateInfo;
@ -31,7 +31,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BC
/// <param name="stateInfo">Bike state info.</param>
protected BikeInfoMutable(
Bike bike,
Drive drive,
DriveMutable drive,
DataSource dataSource,
bool isDemo = BikeInfo.DEFAULTVALUEISDEMO,
IEnumerable<string> group = null,
@ -105,7 +105,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BC
public string Description => _Bike.Description;
public Drive Drive => _Drive;
public DriveMutable Drive => _Drive;
/// <summary>
/// Fired whenever property of bike changes.

View file

@ -18,7 +18,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BC
/// <summary>
/// Holds the drive.
/// </summary>
Drive Drive { get; }
DriveMutable Drive { get; }
/// <summary> Gets or sets the information where the data origins from. </summary>
DataSource DataSource { get; }

View file

@ -59,7 +59,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BC
/// <summary>
/// Hold the drive object.
/// </summary>
Drive Drive { get; }
DriveMutable Drive { get; }
/// <summary> Gets or sets the information where the data origins from. </summary>
DataSource DataSource { get; set; }

View file

@ -20,7 +20,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
/// <param name="tariffDescription">Hold tariff description of bike.</param>
public BikeInfo(
Bike bike,
Drive drive,
DriveMutable drive,
DataSource dataSource,
int lockId,
Guid lockGuid,
@ -65,7 +65,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
/// <param name="dateTimeProvider">Date time provider to calculate remaining time.</param>
public BikeInfo(
Bike bike,
Drive drive,
DriveMutable drive,
DataSource dataSource,
int lockId,
Guid lockGuid,
@ -121,7 +121,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
/// <param name="wheelType"></param>
public BikeInfo(
Bike bike,
Drive drive,
DriveMutable drive,
DataSource dataSource,
int lockId,
Guid lockGuid,

View file

@ -32,7 +32,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock.Command
}
/// <summary>
/// Possible steps of closing a lock.
/// Possible states of closing a lock.
/// </summary>
public enum State
{
@ -182,7 +182,8 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock.Command
}
}
// Start query geolocation data.
//// Start Action
//// Step: Start query geolocation data.
Log.ForContext<T>().Debug($"Starting step {Step.StartingQueryingLocation}...");
InvokeCurrentStep(Step.StartingQueryingLocation);
var ctsLocation = new CancellationTokenSource();
@ -199,7 +200,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock.Command
await InvokeCurrentStateAsync(State.StartGeolocationException, ex.Message);
}
// Close lock.
//// Step: Close lock.
IGeolocation currentLocation;
Log.ForContext<T>().Debug($"Starting step {Step.ClosingLock}...");
InvokeCurrentStep(Step.ClosingLock);
@ -236,7 +237,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock.Command
// Signal cts to cancel getting geolocation.
ctsLocation.Cancel();
//// Step: Wait until getting geolocation and stop polling has completed.
// Wait until getting geolocation and stop polling has completed.
currentLocation = await WaitForPendingTasks(currentLocationTask);
// Update current state from exception
@ -256,14 +257,14 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock.Command
throw;
}
// Step: Update backend.
// Update backend.
// Do this even if current lock state is open (lock state must not necessarily be open before try to open, i.e. something undefined between open and closed).
await UpdateLockingState(currentLocation, timeStampNow);
throw;
}
//// Step: Wait until getting geolocation and stop polling has completed.
//// Step: Wait until getting geolocation and stop polling has completed.
currentLocation = await WaitForPendingTasks(currentLocationTask);
bike.LockInfo.State = lockingState?.GetLockingState() ?? LockingState.UnknownDisconnected;
@ -276,7 +277,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock.Command
return;
}
//// Step: Update backend.
//// Step: Update backend.
await UpdateLockingState(currentLocation, timeStampNow);
}
}

View file

@ -97,6 +97,8 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock.Command
}
}
//// Start Action
//// Step: Start query geolocation data.
InvokeCurrentStep(Step.StartingQueryLocation);
// Get geolocation which was requested when closing lock.
@ -123,7 +125,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock.Command
await InvokeCurrentStateAsync(State.DisconnetedNoLocationError, "");
// Disconnect lock.
//// Step: Disconnect lock.
InvokeCurrentStep(Step.DisconnectingLockOnDisconnectedNoLocationError);
try
{

View file

@ -22,7 +22,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.CopriLock
/// <param name="tariffDescription">Hold tariff description of bike.</param>
public BikeInfo(
Bike bike,
Drive drive,
DriveMutable drive,
DataSource dataSource,
string currentStationId,
LockInfo lockInfo,
@ -70,7 +70,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.CopriLock
/// <param name="dateTimeProvider">Provider for current date time to calculate remaining time on demand for state of type reserved.</param>
public BikeInfo(
Bike bike,
Drive drive,
DriveMutable drive,
DataSource dataSource,
DateTime requestedAt,
string mailAddress,
@ -122,7 +122,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.CopriLock
/// <param name="tariffDescription">Hold tariff description of bike.</param>
public BikeInfo(
Bike bike,
Drive drive,
DriveMutable drive,
DataSource dataSource,
DateTime bookedAt,
string mailAddress,

View file

@ -2,32 +2,35 @@ using Serilog;
namespace TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS
{
/// <summary>
/// Holds the state of a chargeable battery.
/// </summary>
public class Battery : IBattery
{
private Battery() { }
/// <summary>
/// Holds the current charging level of the battery in percent, double.NaN if unknown.
/// Gets the current charging level of the battery in percent, double.NaN if unknown.
/// </summary>
public double CurrentChargePercent { get; private set; } = double.NaN;
/// <summary>
/// Holds the current charging level of the battery in bars, null if unknown.
/// Gets the current charging level of the battery in bars, null if unknown.
/// </summary>
public int? CurrentChargeBars { get; private set; } = null;
/// <summary>
/// Holds the maximum charging level of the battery in bars, null if unknown.
/// Gets the maximum charging level of the battery in bars, null if unknown.
/// </summary>
public int? MaxChargeBars { get; private set; } = null;
/// <summary>
/// Holds whether backend is aware of battery charging level.
/// Gets whether backend is aware of battery charging level.
/// </summary>
public bool? IsBackendAccessible { get; private set; } = null;
/// <summary>
/// Holds whether to display battery level or not.
/// Gets whether to display battery level or not.
/// </summary>
public bool? IsHidden { get; private set; } = null;

View file

@ -0,0 +1,84 @@
using System.ComponentModel;
namespace TINK.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;
}
}

View file

@ -1,7 +1,7 @@
namespace TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS
{
public interface IBattery
public interface IBattery
{
/// <summary>
/// Holds the current charging level of the battery in percent, double.NaN if unknown.

View file

@ -0,0 +1,35 @@
using System.ComponentModel;
namespace TINK.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; }
}
}

View file

@ -1,4 +1,4 @@
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS.EngineNS;
namespace TINK.Model.Bikes.BikeInfoNS.DriveNS
@ -6,32 +6,32 @@ namespace TINK.Model.Bikes.BikeInfoNS.DriveNS
public enum DriveType
{
/// <summary>
/// Bike without pedalling aid.
/// Bike without pedaling aid.
/// </summary>
SoleHumanPowered,
/// <summary>
/// pedal electric cycle: Pedalling is assisted by an electric engine.
/// pedal electric cycle: Pedaling is assisted by an electric engine.
/// </summary>
Pedelec
}
public class Drive
public class DriveMutable
{
public Drive(
public DriveMutable(
IEngine engine = null,
IBattery battery = null)
{
if (engine == null)
{
Engine = new Engine();
Battery = new Battery.Builder().Build();
Battery = new BatteryMutable(new Battery.Builder().Build());
Type = DriveType.SoleHumanPowered;
return;
}
Engine = engine;
Battery = battery ?? new Battery.Builder().Build();
Battery = new BatteryMutable(battery ?? new Battery.Builder().Build());
Type = DriveType.Pedelec;
}
@ -48,15 +48,6 @@ namespace TINK.Model.Bikes.BikeInfoNS.DriveNS
/// <summary>
/// Battery powering the engine.
/// </summary>
public IBattery _Battery = new Battery.Builder().Build();
/// <summary>
/// Battery powering the engine.
/// </summary>
public IBattery Battery
{
get => _Battery;
set => _Battery = value ?? new Battery.Builder().Build();
}
public IBatteryMutable Battery { get; private set; }
}
}

View file

@ -7,16 +7,16 @@ namespace TINK.Model.Connector.Updater
{
public static class DriveFactory
{
public static Drive Create(this BikeType bikeType)
public static DriveMutable Create(this BikeType bikeType)
{
if (string.IsNullOrEmpty(bikeType?.engine?.manufacturer))
{
// Bike is has no engine
return new Drive();
return new DriveMutable();
}
// Bike is a pedelec.
return new Drive(
return new DriveMutable(
new Engine(bikeType?.engine?.manufacturer),
new Battery.Builder
{

View file

@ -712,6 +712,16 @@ namespace TINK.Model
new Version(3, 0, 370),
AppResources.ChangeLog_3_0_370
},
{
new Version(3, 0, 371),
AppResources.ChangeLog_3_0_371_SB,
new List<AppFlavor> { AppFlavor.ShareeBike }
},
{
new Version(3, 0, 371),
AppResources.ChangeLog_3_0_371_MK,
new List<AppFlavor> { AppFlavor.MeinKonrad}
},
};
/// <summary> Manges the whats new information.</summary>