sharee.bike-App/TINKLib/Model/Bikes/BikeInfoNS/BluetoothLock/LockInfoMutable.cs

59 lines
1.8 KiB
C#
Raw Normal View History

2022-09-20 13:51:55 +02:00
using System;
2021-05-13 20:03:07 +02:00
2022-08-30 15:42:25 +02:00
namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
2021-05-13 20:03:07 +02:00
{
2022-09-20 13:51:55 +02:00
public class LockInfoMutable : ILockInfoMutable
2022-09-06 16:08:19 +02:00
{
/// <summary> Lock info object. </summary>
2022-09-20 13:51:55 +02:00
private LockInfo LockInfo { get; set; }
2022-09-06 16:08:19 +02:00
/// <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>
public LockInfoMutable(
int id,
Guid guid,
byte[] userKey,
byte[] adminKey,
byte[] seed,
2022-09-20 13:51:55 +02:00
LockingState state)
2022-09-06 16:08:19 +02:00
{
2022-09-20 13:51:55 +02:00
LockInfo = new LockInfo.Builder() { Id = id, Guid = guid, UserKey = userKey, AdminKey = adminKey, Seed = seed, State = state }.Build();
2022-09-06 16:08:19 +02:00
}
public int Id => LockInfo.Id;
/// <summary> Changes during runtime: Can be unknown when set from copri and chang to a valid value when set from lock.</summary>
public Guid Guid
{
get => LockInfo.Guid;
2022-09-20 13:51:55 +02:00
set => LockInfo = new LockInfo.Builder(LockInfo) { Guid = value }.Build();
2022-09-06 16:08:19 +02:00
}
public byte[] Seed => LockInfo.Seed;
public byte[] UserKey => LockInfo.UserKey;
public byte[] AdminKey => LockInfo.AdminKey;
2022-09-20 13:51:55 +02:00
public LockingState State
2022-09-06 16:08:19 +02:00
{
get => LockInfo.State;
2022-09-20 13:51:55 +02:00
set => LockInfo = new LockInfo.Builder(LockInfo) { State = value }.Build();
2022-09-06 16:08:19 +02:00
}
/// <summary> Holds the percentage of lock battery.</summary>
public double BatteryPercentage { get; set; } = double.NaN;
2022-09-20 13:51:55 +02:00
/// <summary>
/// Gets the version info of the lock.
/// </summary>
public IVersionInfo VersionInfo { get; set; } = new VersionInfo.Builder().Build();
2022-09-06 16:08:19 +02:00
/// <summary> Loads lock info object from values. </summary>
public void Load(int id, Guid guid, byte[] seed, byte[] userKey, byte[] adminKey)
{
2022-09-20 13:51:55 +02:00
LockInfo = new LockInfo.Builder(LockInfo) { Id = id, Guid = guid, Seed = seed, UserKey = userKey, AdminKey = adminKey }.Build();
2022-09-06 16:08:19 +02:00
}
}
2021-05-13 20:03:07 +02:00
}