Files
adas-core/adas-core.module.Relays/Devices/FakeRelay.cs
T
2026-06-26 10:29:23 +02:00

113 lines
5.0 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>
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>
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>
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>
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>
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>
public override void PowerOffAll()
{
}
/// <summary>
/// Powers on all relays. Since this is a simulated device, this method does not perform any actual operations.
/// </summary>
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>
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>
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>
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>
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>
public override void CheckStatus()
{
}
}