138 lines
6.9 KiB
C#
138 lines
6.9 KiB
C#
using adas_core.Domain.Enums;
|
|
using adas_core.Domain.Models.MongoModels;
|
|
using adas_core.module.Relays.Models;
|
|
|
|
namespace adas_core.module.Relays.Devices;
|
|
|
|
/// <summary>
|
|
/// This class represents a fake relay device used for testing purposes. It inherits from the RelayDevice class and overrides its methods to provide simulated behavior without interacting with actual hardware.
|
|
/// This allows developers to test the functionality of their code that interacts with relay devices without needing access to physical devices.
|
|
/// </summary>
|
|
/// <param name="relay">The Relay object representing the relay device.</param>
|
|
/// <param name="relaySettings">The RelaySettings object containing the configuration settings for the relay device.</param>
|
|
/// <!-- aidoc:v1 sig=a63ae6e -->
|
|
internal class FakeRelay(Relay relay, RelaySettings relaySettings) : RelayDevice(relay, relaySettings)
|
|
{
|
|
/// <summary>
|
|
/// Checks the status of the fake relay device. Since this is a simulated device, it always returns true, indicating that the device is functioning properly.
|
|
/// In a real implementation, this method would contain logic to check the actual status of the hardware device.
|
|
/// </summary>
|
|
/// <returns>True if the device is functioning properly, false otherwise.</returns>
|
|
/// <!-- aidoc:v1 sig=20f7821 body=eb3da57 -->
|
|
public override bool CheckDevice()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the status of the fake relay device. Since this is a simulated device, it always returns true, indicating that the device is on.
|
|
/// </summary>
|
|
/// <returns>True if the device is on, false otherwise.</returns>
|
|
/// <!-- aidoc:v1 sig=351e317 body=eb3da57 -->
|
|
public override bool GetStatusRelay()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Powers off the relay for the specified outlet ID. Since this is a simulated device, this method does not perform any actual operations.
|
|
/// In a real implementation, this method would contain logic to send a command to the hardware device to power off the specified outlet.
|
|
/// </summary>
|
|
/// <param name="outletId">The ID of the outlet to power off</param>
|
|
/// <!-- aidoc:v1 sig=df0a638 body=4448e1d -->
|
|
public override void PowerOffRelay(int outletId)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Powers on the relay for the specified outlet ID. Since this is a simulated device, this method does not perform any actual operations.
|
|
/// </summary>
|
|
/// <param name="outletId">The ID of the outlet to power on.</param>
|
|
/// <!-- aidoc:v1 sig=a106116 body=4448e1d -->
|
|
public override void PowerOnRelay(int outletId)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Powers off all relays. Since this is a simulated device, this method does not perform any actual operations.
|
|
/// </summary>
|
|
/// <!-- aidoc:v1 sig=bfcd3b2 body=4448e1d -->
|
|
public override void PowerOffAll()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Powers on all relays. Since this is a simulated device, this method does not perform any actual operations.
|
|
/// </summary>
|
|
/// <!-- aidoc:v1 sig=c24d19e body=4448e1d -->
|
|
public override void PowerOnAll()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the status of the relay for the specified outlet ID. Since this is a simulated device, it returns a hardcoded status string "00000000", which indicates that all outlets are off.
|
|
/// </summary>
|
|
/// <param name="outletId">The ID of the outlet to get the status for.</param>
|
|
/// <returns>The status of the specified outlet.</returns>
|
|
/// <!-- aidoc:v1 sig=2d49b50 body=6d71a28 -->
|
|
public override RelayEnum.Status GetStatusRelay(int outletId)
|
|
{
|
|
const string status = "00000000";
|
|
|
|
if (status.Length == 0) return RelayEnum.Status.On;
|
|
return status.Substring(outletId - 1, 1) == "0" ? RelayEnum.Status.Off : RelayEnum.Status.On;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reboots the relay for the specified outlet ID. Since this is a simulated device, this method does not perform any actual operations.
|
|
/// </summary>
|
|
/// <param name="outletId">The ID of the outlet to reboot.</param>
|
|
/// <!-- aidoc:v1 sig=1edae69 body=4448e1d -->
|
|
public override void RebootOutlet(int outletId)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reboots all relays. Since this is a simulated device, this method does not perform any actual operations.
|
|
/// However, it includes a delay based on the RebootDelay property of the Relay object to simulate the time taken for a reboot process.
|
|
/// </summary>
|
|
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
|
|
/// "The summary states 'this method does not perform any actual operations', but the code clearly performs operations by calling PowerOffAll(), optionally Thread.Sleep(Relay.RebootDelay), and PowerOnAll()." -->
|
|
public override void Reboot()
|
|
{
|
|
PowerOffAll();
|
|
if (Relay.RebootDelay is > 0) Thread.Sleep(Relay.RebootDelay!.Value);
|
|
PowerOnAll();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously gets the status of the relay for the specified outlet ID. Since this is a simulated device, it returns a hardcoded status string "00000000", which indicates that all outlets are off.
|
|
/// </summary>
|
|
/// <returns>A task that represents the asynchronous operation. The task result contains the status of the specified outlet.</returns>
|
|
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
|
|
/// "Documents returning a hardcoded string '00000000' but the method actually returns a boolean true via Task.FromResult(true)" -->
|
|
/// <!-- aidoc-review:v1 severity=high kind=wrong_returns
|
|
/// "Returns tag says task result contains 'the status of the specified outlet' (implied string), but the method returns Task<bool> with value true" -->
|
|
/// <!-- aidoc-review:v1 severity=high kind=extra_param
|
|
/// "Summary references 'the specified outlet ID' but the method takes no parameters" -->
|
|
/// <!-- aidoc-review:v1 severity=high kind=mentions_removed_behavior
|
|
/// "Describes returning an 8-character status string indicating all outlets are off, which is not present in the code" -->
|
|
public override Task<bool> GetStatusRelayAsync()
|
|
{
|
|
return Task.FromResult(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously gets the status of the relay for the specified outlet ID.
|
|
/// Since this is a simulated device, it returns a hardcoded status string "00000000", which indicates that all outlets are off.
|
|
/// </summary>
|
|
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
|
|
/// "Documents async status retrieval and returning a hardcoded string, but the method is void with an empty body" -->
|
|
/// <!-- aidoc-review:v1 severity=high kind=wrong_returns
|
|
/// "Summary says it returns a status string, but the method return type is void" -->
|
|
/// <!-- aidoc-review:v1 severity=high kind=extra_param
|
|
/// "References 'the specified outlet ID' but the method has no parameters" -->
|
|
public override void CheckStatus()
|
|
{
|
|
}
|
|
} |