Version 3.0.340

This commit is contained in:
Anja 2022-09-20 13:51:55 +02:00
parent 52c9f6f1d9
commit bad07e1ec9
62 changed files with 1401 additions and 1000 deletions

View file

@ -1,13 +1,12 @@
using System;
using System;
using System.Collections.Generic;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
using TINK.Model.State;
namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
{
public class BikeInfo : Model.Bikes.BikeInfoNS.BC.BikeInfo, IBikeInfo
public class BikeInfo : BC.BikeInfo, IBikeInfo
{
/// <summary>
/// Constructs a bike info object for a available bike.
@ -18,7 +17,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
/// <param name="tariffDescription">Hold tariff description of bike.</param>
public BikeInfo(
BikeNS.Bike bike,
Bike bike,
Drive drive,
int lockId,
Guid lockGuid,
@ -29,7 +28,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
IEnumerable<string> group = null) : base(
new StateInfo(),
bike != null
? new BikeNS.Bike(
? new Bike(
bike.Id,
LockModel.ILockIt /* Ensure consistend lock model value */,
bike.WheelType,
@ -43,7 +42,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
operatorUri,
tariffDescription)
{
LockInfo = new Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo.Builder { Id = lockId, Guid = lockGuid }.Build();
LockInfo = new LockInfo.Builder { Id = lockId, Guid = lockGuid }.Build();
}
/// <summary>
@ -59,7 +58,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
/// <param name="tariffDescription">Hold tariff description of bike.</param>
/// <param name="dateTimeProvider">Date time provider to calculate reaining time.</param>
public BikeInfo(
BikeNS.Bike bike,
Bike bike,
Drive drive,
int lockId,
Guid lockGuid,
@ -80,7 +79,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
mailAddress,
""),
bike != null
? new BikeNS.Bike(
? new Bike(
bike.Id,
LockModel.ILockIt /* Ensure consistend lock model value */,
bike.WheelType,
@ -94,7 +93,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
operatorUri,
tariffDescription)
{
LockInfo = new Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo.Builder { Id = lockId, Guid = lockGuid, UserKey = userKey, AdminKey = adminKey, Seed = seed }.Build();
LockInfo = new LockInfo.Builder { Id = lockId, Guid = lockGuid, UserKey = userKey, AdminKey = adminKey, Seed = seed }.Build();
}
/// <summary>
@ -110,7 +109,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
/// <param name="tariffDescription">Hold tariff description of bike.</param>
/// <param name="wheelType"></param>
public BikeInfo(
BikeNS.Bike bike,
Bike bike,
Drive drive,
int lockId,
Guid lockGuid,
@ -129,7 +128,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
mailAddress,
""),
bike != null
? new BikeNS.Bike(
? new Bike(
bike.Id,
LockModel.ILockIt /* Ensure consistend lock model value */,
bike.WheelType,
@ -143,16 +142,16 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
operatorUri,
tariffDescription)
{
LockInfo = new Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo.Builder { Id = lockId, Guid = lockGuid, UserKey = userKey, AdminKey = adminKey, Seed = seed }.Build();
LockInfo = new LockInfo.Builder { Id = lockId, Guid = lockGuid, UserKey = userKey, AdminKey = adminKey, Seed = seed }.Build();
}
public BikeInfo(Model.Bikes.BikeInfoNS.BC.BikeInfo bikeInfo, Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo lockInfo) : base(
public BikeInfo(Model.Bikes.BikeInfoNS.BC.BikeInfo bikeInfo, LockInfo lockInfo) : base(
bikeInfo ?? throw new ArgumentException($"Can not copy-construct {typeof(BikeInfo).Name}-object. Source bike info must not be null."))
{
LockInfo = lockInfo
?? throw new ArgumentException($"Can not copy-construct {typeof(BikeInfo).Name}-object. Source lock object must not be null.");
}
public Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo LockInfo { get; private set; }
public LockInfo LockInfo { get; private set; }
}
}

View file

@ -1,4 +1,4 @@
using System;
using System;
namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
{
@ -19,5 +19,10 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
Guid Guid { get; set; }
byte[] Seed { get; }
/// <summary>
/// Gets the version info of the locks.
/// </summary>
IVersionInfo VersionInfo { get; set; }
}
}

View file

@ -0,0 +1,20 @@
namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
{
public interface IVersionInfo
{
/// <summary>
/// Holds the firmware version of the lock.
/// </summary>
int FirmwareVersion { get; }
/// <summary>
/// Holds the hardware version (revision) of the lock.
/// </summary>
int HardwareVersion { get; }
/// <summary>
/// Holds lock version (2 classic, 3 plus, 4 GPS).
/// </summary>
int LockVersion { get; }
}
}

View file

@ -1,11 +1,11 @@
using System;
using System;
namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
{
public class LockInfoMutable : TINK.Model.Bikes.BikeInfoNS.BluetoothLock.ILockInfoMutable
public class LockInfoMutable : ILockInfoMutable
{
/// <summary> Lock info object. </summary>
private Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo LockInfo { get; set; }
private LockInfo LockInfo { get; set; }
/// <summary> Constructs a bluetooth lock info object. </summary>
/// <param name="id">Id of lock must always been known when constructing an lock info object.</param>
@ -15,9 +15,9 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
byte[] userKey,
byte[] adminKey,
byte[] seed,
Model.Bikes.BikeInfoNS.BluetoothLock.LockingState state)
LockingState state)
{
LockInfo = new Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo.Builder() { Id = id, Guid = guid, UserKey = userKey, AdminKey = adminKey, Seed = seed, State = state }.Build();
LockInfo = new LockInfo.Builder() { Id = id, Guid = guid, UserKey = userKey, AdminKey = adminKey, Seed = seed, State = state }.Build();
}
public int Id => LockInfo.Id;
@ -26,7 +26,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
public Guid Guid
{
get => LockInfo.Guid;
set => LockInfo = new Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo.Builder(LockInfo) { Guid = value }.Build();
set => LockInfo = new LockInfo.Builder(LockInfo) { Guid = value }.Build();
}
public byte[] Seed => LockInfo.Seed;
@ -35,19 +35,24 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
public byte[] AdminKey => LockInfo.AdminKey;
public Model.Bikes.BikeInfoNS.BluetoothLock.LockingState State
public LockingState State
{
get => LockInfo.State;
set => LockInfo = new Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo.Builder(LockInfo) { State = value }.Build();
set => LockInfo = new LockInfo.Builder(LockInfo) { State = value }.Build();
}
/// <summary> Holds the percentage of lock battery.</summary>
public double BatteryPercentage { get; set; } = double.NaN;
/// <summary>
/// Gets the version info of the lock.
/// </summary>
public IVersionInfo VersionInfo { get; set; } = new VersionInfo.Builder().Build();
/// <summary> Loads lock info object from values. </summary>
public void Load(int id, Guid guid, byte[] seed, byte[] userKey, byte[] adminKey)
{
LockInfo = new Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo.Builder(LockInfo) { Id = id, Guid = guid, Seed = seed, UserKey = userKey, AdminKey = adminKey }.Build();
LockInfo = new LockInfo.Builder(LockInfo) { Id = id, Guid = guid, Seed = seed, UserKey = userKey, AdminKey = adminKey }.Build();
}
}
}

View file

@ -0,0 +1,69 @@
using Newtonsoft.Json;
namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
{
public class VersionInfo : IVersionInfo
{
/// <summary>
/// Holds info about firmware- and hardware version of a lock and the type of lock (lock version).
/// </summary>
private VersionInfo() { }
/// <summary>
/// Holds the firmware version of the lock.
/// </summary>
public int FirmwareVersion { get; private set; } = 0;
/// <summary>
/// Holds the hardware version (revision) of the lock.
/// </summary>
public int HardwareVersion { get; private set; } = 0;
/// <summary>
/// Holds lock version (2 classic, 3 plus, 4 GPS).
/// </summary>
public int LockVersion { get; private set; } = 0;
public override bool Equals(object obj)
=> Equals(obj as VersionInfo);
public bool Equals(VersionInfo other)
{
if (ReferenceEquals(other, null)) return false;
if (ReferenceEquals(this, other)) return true;
if (GetType() != other.GetType()) return false;
return ToString() == other.ToString();
}
public override int GetHashCode() => ToString().GetHashCode();
public override string ToString() => JsonConvert.SerializeObject(this);
public static bool operator ==(VersionInfo lhs, VersionInfo rhs)
{
if (ReferenceEquals(lhs, null))
return ReferenceEquals(rhs, null) ? true /*null == null = true*/: false;
return lhs.Equals(rhs);
}
public static bool operator !=(VersionInfo lhs, VersionInfo rhs)
=> !(lhs == rhs);
public class Builder
{
private VersionInfo versionInfo = new VersionInfo();
public int FirmwareVersion { get => versionInfo.FirmwareVersion; set => versionInfo.FirmwareVersion = value; }
public int HardwareVersion { get => versionInfo.HardwareVersion; set => versionInfo.HardwareVersion = value; }
public int LockVersion { get => versionInfo.LockVersion; set => versionInfo.LockVersion = value; }
public VersionInfo Build()
{
return versionInfo;
}
}
}
}