sharee.bike-App/TINKLib/Services/BluetoothLock/LocksServiceOutOfReach.cs
2023-04-19 12:14:14 +02:00

65 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TINK.Model.Bikes;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
using TINK.Services.BluetoothLock.Tdo;
namespace TINK.Services.BluetoothLock
{
/// <summary>
/// Fake 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 attempts 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> No info centered 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>();
// 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;
}
/// <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);
}
}