sharee.bike-App/TINKLib/Services/BluetoothLock/LocksServiceOutOfReach.cs

66 lines
2.3 KiB
C#
Raw Normal View History

2023-04-19 12:14:14 +02:00
using System;
2022-08-30 15:42:25 +02:00
using System.Collections.Generic;
2021-05-13 20:03:07 +02:00
using System.Linq;
using System.Threading.Tasks;
2022-08-30 15:42:25 +02:00
using TINK.Model.Bikes;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
2021-05-13 20:03:07 +02:00
using TINK.Services.BluetoothLock.Tdo;
namespace TINK.Services.BluetoothLock
{
2022-09-06 16:08:19 +02:00
/// <summary>
2023-04-19 12:14:14 +02:00
/// Fake locks service implementation which simulates locks which are out of reach.
2022-09-06 16:08:19 +02:00
/// </summary>
public class LocksServiceOutOfReach : ILocksServiceFake
{
private IEnumerable<LockInfoTdo> LocksInfo { get; set; } = new List<LockInfoTdo>();
2021-05-13 20:03:07 +02:00
2023-04-19 12:14:14 +02:00
/// <summary> Holds timeout values for series of connecting attempts to a lock or multiple locks. </summary>
2022-09-06 16:08:19 +02:00
public ITimeOutProvider TimeOut { get; set; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <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());
}
2021-05-13 20:03:07 +02:00
2023-04-19 12:14:14 +02:00
/// <summary> No info centered because no lock is in reach.</summary>
2022-09-06 16:08:19 +02:00
/// <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);
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> No changes required because lock state is unknown.</summary>
public void UpdateSimulation(BikeCollection bikes)
{
var locksInfo = new List<LockInfoTdo>();
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
// Add and process locks info object
2023-08-31 12:20:06 +02:00
foreach (var bikeInfo in bikes.OfType<BikeInfo>())
2022-09-06 16:08:19 +02:00
{
locksInfo.Add(new LockInfoTdo.Builder { Id = bikeInfo.LockInfo.Id, State = null }.Build());
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
LocksInfo = locksInfo;
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>Gets a lock by bike Id.</summary>
/// <param name="bikeId"></param>
/// <returns>Lock object</returns>
public ILockService this[int bikeId]
{
get
{
return null;
}
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <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);
}
2021-05-13 20:03:07 +02:00
}