using adas_core.Domain.Enums; using adas_core.Domain.Models.MongoModels; using adas_core.module.Relays.Models; namespace adas_core.module.Relays.Devices; /// /// 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. /// /// The Relay object representing the relay device. /// The RelaySettings object containing the configuration settings for the relay device. internal class FakeRelay(Relay relay, RelaySettings relaySettings) : RelayDevice(relay, relaySettings) { /// /// 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. /// /// True if the device is functioning properly, false otherwise. public override bool CheckDevice() { return true; } /// /// Gets the status of the fake relay device. Since this is a simulated device, it always returns true, indicating that the device is on. /// /// True if the device is on, false otherwise. public override bool GetStatusRelay() { return true; } /// /// 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. /// /// The ID of the outlet to power off public override void PowerOffRelay(int outletId) { } /// /// Powers on the relay for the specified outlet ID. Since this is a simulated device, this method does not perform any actual operations. /// /// The ID of the outlet to power on. public override void PowerOnRelay(int outletId) { } /// /// Powers off all relays. Since this is a simulated device, this method does not perform any actual operations. /// public override void PowerOffAll() { } /// /// Powers on all relays. Since this is a simulated device, this method does not perform any actual operations. /// public override void PowerOnAll() { } /// /// 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. /// /// The ID of the outlet to get the status for. /// The status of the specified outlet. 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; } /// /// Reboots the relay for the specified outlet ID. Since this is a simulated device, this method does not perform any actual operations. /// /// The ID of the outlet to reboot. public override void RebootOutlet(int outletId) { } /// /// 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. /// public override void Reboot() { PowerOffAll(); if (Relay.RebootDelay is > 0) Thread.Sleep(Relay.RebootDelay!.Value); PowerOnAll(); } /// /// 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. /// /// A task that represents the asynchronous operation. The task result contains the status of the specified outlet. public override Task GetStatusRelayAsync() { return Task.FromResult(true); } /// /// 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. /// public override void CheckStatus() { } }