Version 3.0.338

This commit is contained in:
Anja Müller-Meißner 2022-09-06 16:08:19 +02:00 committed by Anja
parent 573fe77e12
commit 0468955d49
751 changed files with 62747 additions and 60672 deletions

View file

@ -2,8 +2,8 @@
namespace TINK.Services.BluetoothLock
{
public interface ILocksServiceFake : ILocksService
{
void UpdateSimulation(BikeCollection bikes);
}
public interface ILocksServiceFake : ILocksService
{
void UpdateSimulation(BikeCollection bikes);
}
}

View file

@ -9,150 +9,150 @@ using TINK.Services.BluetoothLock.Tdo;
namespace TINK.Services.BluetoothLock
{
/// <summary>
/// Facke locks service implementation which simulates locks which are in reach.
/// </summary>
public class LocksServiceInReach : ILocksServiceFake
{
private IEnumerable<LockInfoTdo> LocksInfo { get; set; } = new List<LockInfoTdo>();
/// <summary>
/// Facke locks service implementation which simulates locks which are in reach.
/// </summary>
public class LocksServiceInReach : ILocksServiceFake
{
private IEnumerable<LockInfoTdo> LocksInfo { get; set; } = new List<LockInfoTdo>();
/// <summary> Holds timeout values for series of connecting attemps to a lock or multiple locks. </summary>
public ITimeOutProvider TimeOut { get; set; }
/// <summary> Holds timeout values for series of connecting attemps to a lock or multiple locks. </summary>
public ITimeOutProvider TimeOut { get; set; }
/// <summary> Connects to lock.</summary>
/// <param name="authInfo"> Info required to connect to lock.</param>
/// <param name="connectTimeout">Timeout for connect operation.</param>
public async Task<LockInfoTdo> ConnectAsync(LockInfoAuthTdo authInfo, TimeSpan connectTimeout)
{
return await Task.FromResult(new LockInfoTdo.Builder { Id = authInfo.Id, Guid = authInfo.Guid, State = LockitLockingState.Closed }.Build());
}
/// <summary> Connects to lock.</summary>
/// <param name="authInfo"> Info required to connect to lock.</param>
/// <param name="connectTimeout">Timeout for connect operation.</param>
public async Task<LockInfoTdo> ConnectAsync(LockInfoAuthTdo authInfo, TimeSpan connectTimeout)
{
return await Task.FromResult(new LockInfoTdo.Builder { Id = authInfo.Id, Guid = authInfo.Guid, State = LockitLockingState.Closed }.Build());
}
/// <param name="connectTimeout">Timeout for connect operation of a single lock.</param>
public async Task<IEnumerable<LockInfoTdo>> GetLocksStateAsync(IEnumerable<LockInfoAuthTdo> locksInfo, TimeSpan connectTimeout)
{
return await Task.FromResult(LocksInfo);
}
/// <param name="connectTimeout">Timeout for connect operation of a single lock.</param>
public async Task<IEnumerable<LockInfoTdo>> GetLocksStateAsync(IEnumerable<LockInfoAuthTdo> locksInfo, TimeSpan connectTimeout)
{
return await Task.FromResult(LocksInfo);
}
public void UpdateSimulation(BikeCollection bikes)
{
var locksInfo = new List<LockInfoTdo>();
public void UpdateSimulation(BikeCollection bikes)
{
var locksInfo = new List<LockInfoTdo>();
// Add and process locks info object
foreach (var bikeInfo in bikes.OfType<Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo>())
{
var lockInfo = bikeInfo.LockInfo;
// Add and process locks info object
foreach (var bikeInfo in bikes.OfType<Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo>())
{
var lockInfo = bikeInfo.LockInfo;
switch (bikeInfo.State.Value)
{
case InUseStateEnum.Disposable:
case InUseStateEnum.FeedbackPending: // State feedback pending does not exist for bluetooth locks but maches from bluetooth perspective state disposable.
switch (lockInfo.State)
{
case LockingState.Open:
case LockingState.UnknownDisconnected:
case LockingState.UnknownFromHardwareError:
// Open bikes are never disposable because as soon as a they are open they get booked.
if (LocksInfo.FirstOrDefault(x => x.Id == lockInfo.Id) != null)
{
continue; // Lock was already added.
}
locksInfo.Add(new LockInfoTdo.Builder { Id = lockInfo.Id, State = LockitLockingState.Closed }.Build());
break;
}
break;
switch (bikeInfo.State.Value)
{
case InUseStateEnum.Disposable:
case InUseStateEnum.FeedbackPending: // State feedback pending does not exist for bluetooth locks but maches from bluetooth perspective state disposable.
switch (lockInfo.State)
{
case LockingState.Open:
case LockingState.UnknownDisconnected:
case LockingState.UnknownFromHardwareError:
// Open bikes are never disposable because as soon as a they are open they get booked.
if (LocksInfo.FirstOrDefault(x => x.Id == lockInfo.Id) != null)
{
continue; // Lock was already added.
}
locksInfo.Add(new LockInfoTdo.Builder { Id = lockInfo.Id, State = LockitLockingState.Closed }.Build());
break;
}
break;
case InUseStateEnum.Reserved:
switch (lockInfo.State)
{
case LockingState.Open:
case LockingState.UnknownDisconnected:
case LockingState.UnknownFromHardwareError:
// Closed bikes are never reserved because as soon as they are open they get booked.
if (LocksInfo.FirstOrDefault(x => x.Id == lockInfo.Id) != null)
{
continue; // Lock was already added.
}
locksInfo.Add(new LockInfoTdo.Builder { Id = lockInfo.Id, State = LockitLockingState.Closed }.Build());
break;
}
break;
case InUseStateEnum.Reserved:
switch (lockInfo.State)
{
case LockingState.Open:
case LockingState.UnknownDisconnected:
case LockingState.UnknownFromHardwareError:
// Closed bikes are never reserved because as soon as they are open they get booked.
if (LocksInfo.FirstOrDefault(x => x.Id == lockInfo.Id) != null)
{
continue; // Lock was already added.
}
locksInfo.Add(new LockInfoTdo.Builder { Id = lockInfo.Id, State = LockitLockingState.Closed }.Build());
break;
}
break;
case InUseStateEnum.Booked:
switch (lockInfo.State)
{
case LockingState.UnknownDisconnected:
case LockingState.UnknownFromHardwareError:
if (LocksInfo.FirstOrDefault(x => x.Id == lockInfo.Id) != null)
{
continue; // Lock was already added.
}
locksInfo.Add(new LockInfoTdo.Builder { Id = lockInfo.Id, State = LockitLockingState.Closed }.Build());
break;
}
break;
}
case InUseStateEnum.Booked:
switch (lockInfo.State)
{
case LockingState.UnknownDisconnected:
case LockingState.UnknownFromHardwareError:
if (LocksInfo.FirstOrDefault(x => x.Id == lockInfo.Id) != null)
{
continue; // Lock was already added.
}
locksInfo.Add(new LockInfoTdo.Builder { Id = lockInfo.Id, State = LockitLockingState.Closed }.Build());
break;
}
break;
}
LocksInfo = locksInfo;
}
}
LocksInfo = locksInfo;
}
}
/// <summary> Opens a lock.</summary>
/// <param name="lockId">Id of lock to open.</param>
public async Task<LockitLockingState?> OpenAsync(int bikeId, byte[] copriKey)
{
return await Task.FromResult(LockitLockingState.Open);
}
/// <summary> Opens a lock.</summary>
/// <param name="lockId">Id of lock to open.</param>
public async Task<LockitLockingState?> OpenAsync(int bikeId, byte[] copriKey)
{
return await Task.FromResult(LockitLockingState.Open);
}
/// <summary> Closes a lock.</summary>
/// <param name="lockId">Id of lock to close.</param>
public async Task<LockitLockingState?> CloseAsync(int bikeId, byte[] copriKey)
{
return await Task.FromResult(LockitLockingState.Closed);
}
/// <summary> Closes a lock.</summary>
/// <param name="lockId">Id of lock to close.</param>
public async Task<LockitLockingState?> CloseAsync(int bikeId, byte[] copriKey)
{
return await Task.FromResult(LockitLockingState.Closed);
}
/// <summary> Set sound settings.</summary>
/// <param name="lockId">Id of lock to set sound settings.</param>
public async Task<bool> SetSoundAsync(int lockId, SoundSettings settings)
{
return await Task.FromResult(true);
}
/// <summary> Set sound settings.</summary>
/// <param name="lockId">Id of lock to set sound settings.</param>
public async Task<bool> SetSoundAsync(int lockId, SoundSettings settings)
{
return await Task.FromResult(true);
}
/// <summary> Sets whether alarm is on or off.</summary>
/// <param name="lockId">Id of lock to get info from.</param>
public async Task SetIsAlarmOffAsync(int lockId, bool activated)
{
await Task.FromResult(true);
}
/// <summary> Sets whether alarm is on or off.</summary>
/// <param name="lockId">Id of lock to get info from.</param>
public async Task SetIsAlarmOffAsync(int lockId, bool activated)
{
await Task.FromResult(true);
}
/// <summary> Gets battery percentage.</summary>
/// <param name="lockId">Id of lock to get info for.</param>
public Task<double> GetBatteryPercentageAsync(int lockId)
{
throw new NotSupportedException();
}
/// <summary> Gets battery percentage.</summary>
/// <param name="lockId">Id of lock to get info for.</param>
public Task<double> GetBatteryPercentageAsync(int lockId)
{
throw new NotSupportedException();
}
/// <summary> Gets whether alarm is on or off.</summary>
/// <param name="lockId">Id of lock to get info for.</param>
public async Task<bool> GetIsAlarmOffAsync(int lockId)
{
return await Task.FromResult(true);
}
/// <summary> Gets whether alarm is on or off.</summary>
/// <param name="lockId">Id of lock to get info for.</param>
public async Task<bool> GetIsAlarmOffAsync(int lockId)
{
return await Task.FromResult(true);
}
/// <summary>Gets a lock by bike Id.</summary>
/// <param name="bikeId"></param>
/// <returns>Lock object</returns>
public ILockService this[int bikeId]
{
get
{
return null;
}
}
/// <summary>Gets a lock by bike Id.</summary>
/// <param name="bikeId"></param>
/// <returns>Lock object</returns>
public ILockService this[int bikeId]
{
get
{
return null;
}
}
/// <summary> Disconnects lock.</summary>
/// <param name="bikeId"> Id of lock to disconnect.</param>
/// <param name="bikeGuid"> Guid of lock to disconnect.</param>
public async Task<LockingState> DisconnectAsync(int bikeId, Guid bikeGuid) => await Task.FromResult(LockingState.UnknownDisconnected);
}
/// <summary> Disconnects lock.</summary>
/// <param name="bikeId"> Id of lock to disconnect.</param>
/// <param name="bikeGuid"> Guid of lock to disconnect.</param>
public async Task<LockingState> DisconnectAsync(int bikeId, Guid bikeGuid) => await Task.FromResult(LockingState.UnknownDisconnected);
}
}

View file

@ -8,58 +8,58 @@ using TINK.Services.BluetoothLock.Tdo;
namespace TINK.Services.BluetoothLock
{
/// <summary>
/// Facke locks service implementation which simulates locks which are out of reach.
/// </summary>
public class LocksServiceOutOfReach : ILocksServiceFake
{
private IEnumerable<LockInfoTdo> LocksInfo { get; set; } = new List<LockInfoTdo>();
/// <summary>
/// Facke locks service implementation which simulates locks which are out of reach.
/// </summary>
public class LocksServiceOutOfReach : ILocksServiceFake
{
private IEnumerable<LockInfoTdo> LocksInfo { get; set; } = new List<LockInfoTdo>();
/// <summary> Holds timeout values for series of connecting attemps to a lock or multiple locks. </summary>
public ITimeOutProvider TimeOut { get; set; }
/// <summary> Holds timeout values for series of connecting attemps to a lock or multiple locks. </summary>
public ITimeOutProvider TimeOut { get; set; }
/// <summary> Connects to lock.</summary>
/// <param name="authInfo"> Info required to connect to lock.</param>
/// <param name="connectTimeout">Timeout for connect operation.</param>
public async Task<LockInfoTdo> ConnectAsync(LockInfoAuthTdo authInfo, TimeSpan connectTimeout)
{
return await Task.FromResult(new LockInfoTdo.Builder { Id = authInfo.Id, Guid = authInfo.Guid, State = null }.Build());
}
/// <summary> Connects to lock.</summary>
/// <param name="authInfo"> Info required to connect to lock.</param>
/// <param name="connectTimeout">Timeout for connect operation.</param>
public async Task<LockInfoTdo> ConnectAsync(LockInfoAuthTdo authInfo, TimeSpan connectTimeout)
{
return await Task.FromResult(new LockInfoTdo.Builder { Id = authInfo.Id, Guid = authInfo.Guid, State = null }.Build());
}
/// <summary> No info availalbe because no lock is in reach.</summary>
/// <param name="connectTimeout">Timeout for connect operation of a single lock.</param>
/// <returns>Empty collection.</returns>
public async Task<IEnumerable<LockInfoTdo>> GetLocksStateAsync(IEnumerable<LockInfoAuthTdo> locksInfo, TimeSpan connectTimeout) => await Task.FromResult(LocksInfo);
/// <summary> No info availalbe because no lock is in reach.</summary>
/// <param name="connectTimeout">Timeout for connect operation of a single lock.</param>
/// <returns>Empty collection.</returns>
public async Task<IEnumerable<LockInfoTdo>> GetLocksStateAsync(IEnumerable<LockInfoAuthTdo> locksInfo, TimeSpan connectTimeout) => await Task.FromResult(LocksInfo);
/// <summary> No changes required because lock state is unknown.</summary>
public void UpdateSimulation(BikeCollection bikes)
{
var locksInfo = new List<LockInfoTdo>();
/// <summary> No changes required because lock state is unknown.</summary>
public void UpdateSimulation(BikeCollection bikes)
{
var locksInfo = new List<LockInfoTdo>();
// Add and process locks info object
foreach (var bikeInfo in bikes.OfType<Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo>())
{
locksInfo.Add(new LockInfoTdo.Builder { Id = bikeInfo.LockInfo.Id, State = null }.Build());
}
// Add and process locks info object
foreach (var bikeInfo in bikes.OfType<Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo>())
{
locksInfo.Add(new LockInfoTdo.Builder { Id = bikeInfo.LockInfo.Id, State = null }.Build());
}
LocksInfo = locksInfo;
}
LocksInfo = locksInfo;
}
/// <summary>Gets a lock by bike Id.</summary>
/// <param name="bikeId"></param>
/// <returns>Lock object</returns>
public ILockService this[int bikeId]
{
get
{
return null;
}
}
/// <summary>Gets a lock by bike Id.</summary>
/// <param name="bikeId"></param>
/// <returns>Lock object</returns>
public ILockService this[int bikeId]
{
get
{
return null;
}
}
/// <summary> Disconnects lock.</summary>
/// <param name="bikeId"> Id of lock to disconnect.</param>
/// <param name="bikeGuid"> Guid of lock to disconnect.</param>
public async Task<LockingState> DisconnectAsync(int bikeId, Guid bikeGuid) => await Task.FromResult(LockingState.UnknownDisconnected);
}
/// <summary> Disconnects lock.</summary>
/// <param name="bikeId"> Id of lock to disconnect.</param>
/// <param name="bikeGuid"> Guid of lock to disconnect.</param>
public async Task<LockingState> DisconnectAsync(int bikeId, Guid bikeGuid) => await Task.FromResult(LockingState.UnknownDisconnected);
}
}

View file

@ -5,45 +5,45 @@ using System.Linq;
namespace TINK.Services.BluetoothLock
{
/// <summary> Manages Locks services and related configuration parameter. </summary>
public class LocksServicesContainerMutable : IEnumerable<string>
{
/// <summary> Manages the different types of LocksService objects.</summary>
private ServicesContainerMutableT<ILocksService> LocksServices { get; }
/// <summary> Manages Locks services and related configuration parameter. </summary>
public class LocksServicesContainerMutable : IEnumerable<string>
{
/// <summary> Manages the different types of LocksService objects.</summary>
private ServicesContainerMutableT<ILocksService> LocksServices { get; }
/// <summary> Holds the name of the default locks service to use. </summary>
public static string DefaultLocksservice => typeof(BLE.LockItByScanServicePolling).FullName;
/// <summary> Holds the name of the default locks service to use. </summary>
public static string DefaultLocksservice => typeof(BLE.LockItByScanServicePolling).FullName;
/// <summary></summary>
/// <param name="activeLockService">Name of active lock service implementation to use.</param>
/// <param name="locksServices">Null for production (set of lock service implentations and some fake implementation will created) hash set of services for testing purposes. </param>
public LocksServicesContainerMutable(
string activeLockService,
HashSet<ILocksService> locksServices)
{
LocksServices = new ServicesContainerMutableT<ILocksService>(
locksServices,
activeLockService);
}
/// <summary></summary>
/// <param name="activeLockService">Name of active lock service implementation to use.</param>
/// <param name="locksServices">Null for production (set of lock service implentations and some fake implementation will created) hash set of services for testing purposes. </param>
public LocksServicesContainerMutable(
string activeLockService,
HashSet<ILocksService> locksServices)
{
LocksServices = new ServicesContainerMutableT<ILocksService>(
locksServices,
activeLockService);
}
/// <summary> Active locks service.</summary>
public ILocksService Active => LocksServices.Active;
/// <summary> Active locks service.</summary>
public ILocksService Active => LocksServices.Active;
/// <summary> Sets a lock service as active locks service by name. </summary>
/// <param name="active">Name of the new locks service.</param>
public void SetActive(string active) => LocksServices.SetActive(active);
/// <summary> Sets a lock service as active locks service by name. </summary>
/// <param name="active">Name of the new locks service.</param>
public void SetActive(string active) => LocksServices.SetActive(active);
IEnumerator<string> IEnumerable<string>.GetEnumerator()
=> LocksServices.Select(x => x.GetType().FullName).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
=> LocksServices.GetEnumerator();
IEnumerator<string> IEnumerable<string>.GetEnumerator()
=> LocksServices.Select(x => x.GetType().FullName).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
=> LocksServices.GetEnumerator();
public void SetTimeOut(TimeSpan connectTimeout)
{
foreach (var locksService in LocksServices)
{
locksService.TimeOut = new TimeOutProvider(new List<TimeSpan> { connectTimeout });
}
}
}
public void SetTimeOut(TimeSpan connectTimeout)
{
foreach (var locksService in LocksServices)
{
locksService.TimeOut = new TimeOutProvider(new List<TimeSpan> { connectTimeout });
}
}
}
}