Merge branch 'main' into feat/logging-update
All checks were successful
Build and Publish / Build Yale Access Frontend (pull_request) Successful in 50s
Build and Publish / Push Yale Access Frontend Docker Image (pull_request) Has been skipped
Build and Publish / Build Yale Access Backend (pull_request) Successful in 1m53s
Build and Publish / Push Yale Access Backend Docker Image (pull_request) Has been skipped
All checks were successful
Build and Publish / Build Yale Access Frontend (pull_request) Successful in 50s
Build and Publish / Push Yale Access Frontend Docker Image (pull_request) Has been skipped
Build and Publish / Build Yale Access Backend (pull_request) Successful in 1m53s
Build and Publish / Push Yale Access Backend Docker Image (pull_request) Has been skipped
This commit is contained in:
@@ -58,11 +58,11 @@ try
|
||||
if (builder.Environment.IsDevelopment() && configuration.GetValue<bool>("UseMockDevelopmentMode"))
|
||||
{
|
||||
builder.Services.AddSingleton<MockYaleData>();
|
||||
builder.Services.AddScoped<IYaleAccessor, MockYaleAccessor>();
|
||||
builder.Services.AddSingleton<IYaleAccessor, MockYaleAccessor>();
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Services.AddScoped<IYaleAccessor, YaleAccessor>();
|
||||
builder.Services.AddSingleton<IYaleAccessor, YaleAccessor>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Diagnostics;
|
||||
using YaleAccess.Models;
|
||||
using YaleAccess.Models.Options;
|
||||
using YaleAccess.Services.Interfaces;
|
||||
@@ -56,23 +57,36 @@ namespace YaleAccess.Services
|
||||
// Flag to indicate if the driver is ready to use
|
||||
bool isReady = false;
|
||||
|
||||
// Message and flag to indicate if there was an error starting the driver
|
||||
string? message = null;
|
||||
|
||||
// Subscribe to the driver ready event
|
||||
driver.DriverReady += () =>
|
||||
{
|
||||
logger.LogInformation("Z-Wave driver started successfully.");
|
||||
isReady = true;
|
||||
};
|
||||
|
||||
driver.StartUpError += (message) =>
|
||||
driver.StartupErrorEvent += (error) =>
|
||||
{
|
||||
throw new Exception(message);
|
||||
logger.LogError("Error starting the driver: {error}", error);
|
||||
message = error;
|
||||
};
|
||||
|
||||
// Wait for the driver to be ready
|
||||
while (!isReady)
|
||||
while (!isReady && message == null)
|
||||
{
|
||||
// Sleep for a short time to avoid busy waiting
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
// If there was an error starting the driver, throw an exception
|
||||
if (message != null)
|
||||
{
|
||||
logger.LogError("Failed to start the driver. Error message: {message}", message);
|
||||
throw new Exception($"Failed to start the driver. Error message: {message}");
|
||||
}
|
||||
|
||||
// Get the lock node from the driver
|
||||
lockNode = driver.Controller.Nodes.Get(devicesOptions.YaleLockNodeId);
|
||||
|
||||
@@ -81,22 +95,45 @@ namespace YaleAccess.Services
|
||||
|
||||
public async Task<YaleUserCode> GetCodeInformationAsync(int userCodeId)
|
||||
{
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
|
||||
// Log the start of the operation
|
||||
_logger.LogDebug("Retrieving user code information for user code ID: {userCodeId}", userCodeId);
|
||||
|
||||
// Setup the two tasks to get the values we need
|
||||
CMDResult status = await lockNode.GetValue(GetUserStatusValue(userCodeId));
|
||||
|
||||
_logger.LogDebug("Retrieved user code status for user code ID: {userCodeId} in {ElapsedMilliseconds} ms", userCodeId, stopwatch.ElapsedMilliseconds);
|
||||
|
||||
CMDResult code = await lockNode.GetValue(GetUserCodeValue(userCodeId));
|
||||
|
||||
_logger.LogDebug("Retrieved user code value for user code ID: {userCodeId} in {ElapsedMilliseconds} ms", userCodeId, stopwatch.ElapsedMilliseconds);
|
||||
|
||||
// Covert the result to a YaleUserCode object
|
||||
return new YaleUserCode()
|
||||
YaleUserCode yaleUserCode = new()
|
||||
{
|
||||
Id = userCodeId,
|
||||
Code = GetUserCodeValue(code),
|
||||
Status = GetUserStatusValue(status),
|
||||
IsHome = false
|
||||
};
|
||||
|
||||
stopwatch.Stop();
|
||||
_logger.LogDebug("Retrieved user code information for user code ID: {userCodeId} in {ElapsedMilliseconds} ms", userCodeId, stopwatch.ElapsedMilliseconds);
|
||||
|
||||
// Return the user code information
|
||||
return yaleUserCode;
|
||||
}
|
||||
|
||||
public async Task<bool> SetUserCode(int userCodeId, string code)
|
||||
{
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
|
||||
// Log the start of the operation
|
||||
_logger.LogDebug("Setting user code for user code ID: {userCodeId} to {code}", userCodeId, code);
|
||||
|
||||
// Setup the set value task
|
||||
CMDResult result = await lockNode.SetValue(GetUserCodeValue(userCodeId), code);
|
||||
|
||||
@@ -106,12 +143,21 @@ namespace YaleAccess.Services
|
||||
_logger.LogError("Failed to set user code {@userCodeId} to {@code}. Error message: {message}", userCodeId, code, result.Message);
|
||||
}
|
||||
|
||||
stopwatch.Stop();
|
||||
_logger.LogDebug("Set user code for user code ID: {userCodeId} to {code} in {ElapsedMilliseconds} ms", userCodeId, code, stopwatch.ElapsedMilliseconds);
|
||||
|
||||
// Return the result
|
||||
return result.Success;
|
||||
}
|
||||
|
||||
public async Task<bool> SetCodeAsAvailable(int userCode)
|
||||
{
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
|
||||
// Log the start of the operation
|
||||
_logger.LogDebug("Setting user code status for user code ID: {userCode} to available", userCode);
|
||||
|
||||
// Setup the set value task
|
||||
CMDResult result = await lockNode.SetValue(GetUserStatusValue(userCode), (int)UserCodeStatus.AVAILABLE);
|
||||
|
||||
@@ -121,6 +167,9 @@ namespace YaleAccess.Services
|
||||
_logger.LogError("Failed to set user code {@userCode} to available status. Error message: {message}", userCode, result.Message);
|
||||
}
|
||||
|
||||
stopwatch.Stop();
|
||||
_logger.LogDebug("Set user code status for user code ID: {userCode} to available in {ElapsedMilliseconds} ms", userCode, stopwatch.ElapsedMilliseconds);
|
||||
|
||||
// Return the result
|
||||
return result.Success;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -16,5 +16,6 @@
|
||||
"vue": "^3.4.10",
|
||||
"vue-router": "^4.2.5"
|
||||
},
|
||||
"dependencies": {}
|
||||
"dependencies": {},
|
||||
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ services:
|
||||
|
||||
frontend:
|
||||
container_name: yale-access-frontend
|
||||
image: liamp1/yale-access-frontend:latest
|
||||
image: liamsgit.dev/liampietralla/yale-access-frontend:latest
|
||||
restart: unless-stopped
|
||||
|
||||
ports: 5015:3000
|
||||
@@ -12,7 +12,7 @@ services:
|
||||
|
||||
backend:
|
||||
container_name: yale-access-backend
|
||||
image: liamp1/yale-access-backend:latest
|
||||
image: liamsgit.dev/liampietralla/yale-access-backend:latest
|
||||
restart: unless-stopped
|
||||
|
||||
ports: 5016:80
|
||||
@@ -34,4 +34,5 @@ services:
|
||||
|
||||
volumes:
|
||||
- ./log:/log
|
||||
- ./data:/yale-data
|
||||
- ./data:/yale-data
|
||||
|
||||
Reference in New Issue
Block a user