=== Summary: 675 files | 7 generated | 484 fresh | 4605 untracked | 4268 adopted | 355 marked | 466 validated-ok | 2+0 stale (sig+body) | 0 skipped | 0 failed | elapsed 11:08:11.442 (40091.44s) ===

This commit is contained in:
julian
2026-06-28 02:50:05 -07:00
parent a19fb90902
commit 586f02a2ca
654 changed files with 5260 additions and 0 deletions
@@ -10,6 +10,7 @@ namespace adas_core.module.Relays.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>
@@ -17,6 +18,7 @@ internal class FakeRelay(Relay relay, RelaySettings relaySettings) : RelayDevice
/// 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;
@@ -26,6 +28,7 @@ internal class FakeRelay(Relay relay, RelaySettings relaySettings) : RelayDevice
/// 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;
@@ -36,6 +39,7 @@ internal class FakeRelay(Relay relay, RelaySettings relaySettings) : RelayDevice
/// 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)
{
}
@@ -44,6 +48,7 @@ internal class FakeRelay(Relay relay, RelaySettings relaySettings) : RelayDevice
/// 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)
{
}
@@ -51,6 +56,7 @@ internal class FakeRelay(Relay relay, RelaySettings relaySettings) : RelayDevice
/// <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()
{
}
@@ -58,6 +64,7 @@ internal class FakeRelay(Relay relay, RelaySettings relaySettings) : RelayDevice
/// <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()
{
}
@@ -67,6 +74,7 @@ internal class FakeRelay(Relay relay, RelaySettings relaySettings) : RelayDevice
/// </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";
@@ -79,6 +87,7 @@ internal class FakeRelay(Relay relay, RelaySettings relaySettings) : RelayDevice
/// 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)
{
}
@@ -87,6 +96,8 @@ internal class FakeRelay(Relay relay, RelaySettings relaySettings) : RelayDevice
/// 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();
@@ -98,6 +109,14 @@ internal class FakeRelay(Relay relay, RelaySettings relaySettings) : RelayDevice
/// 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);
@@ -107,6 +126,12 @@ internal class FakeRelay(Relay relay, RelaySettings relaySettings) : RelayDevice
/// 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()
{
}
@@ -12,6 +12,7 @@ namespace adas_core.module.Relays.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=0480f2b -->
public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
: RelayDevice(relay, relaySettings)
{
@@ -30,6 +31,7 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// If the response indicates that the status is unknown, it returns false, indicating that the device is not reachable or not responding correctly. Otherwise, it returns true, indicating that the device is online and responsive.
/// </summary>
/// <returns>True if the device is online and responsive, false otherwise.</returns>
/// <!-- aidoc:v1 sig=20f7821 body=470606e -->
public override bool CheckDevice()
{
CheckStatus();
@@ -42,6 +44,7 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// If the response is null or empty, it indicates that the device is not reachable or not responding correctly, and it returns false. Otherwise, it returns true, indicating that the device is online and responsive.
/// </summary>
/// <returns>True if the device is online and responsive, false otherwise.</returns>
/// <!-- aidoc:v1 sig=351e317 body=526bfc0 -->
public override bool GetStatusRelay()
{
var status = Send("FF0000");
@@ -60,6 +63,7 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// </summary>
/// <param name="outletId">The ID of the outlet to retrieve the status for.</param>
/// <returns>The status of the specified outlet.</returns>
/// <!-- aidoc:v1 sig=2d49b50 body=d2e7365 -->
public override RelayEnum.Status GetStatusRelay(int outletId)
{
var status = Send("FF0000");
@@ -102,6 +106,7 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// Powers off a specific outlet on the KMTronic relay device by sending a command to either open or close the relay, depending on the configured mode.
/// </summary>
/// <param name="outletId">The ID of the outlet to power off.</param>
/// <!-- aidoc:v1 sig=df0a638 body=d1228ed -->
public override void PowerOffRelay(int outletId)
{
if (Relay.Mode == RelayEnum.Mode.OpenedOffClosedOn) OpenRelay(outletId);
@@ -112,6 +117,10 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// Powers on a specific outlet on the KMTronic relay device by sending a command to either open or close the relay, depending on the configured mode.
/// </summary>
/// <param name="outletId">The ID of the outlet to power on.</param>
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
/// "Summary says 'Powers on' a specific outlet, but the method is OpenRelay and the inline comment confirms it cuts current ('corta la corriente'), i.e., it powers the outlet off, not on." -->
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
/// "Summary claims the command is sent 'depending on the configured mode' (open or close), but the code unconditionally sends a fixed 'FF0{outletId}01' command with no mode-based branching." -->
public void OpenRelay(int outletId)
{
//Activa el relé por lo que corta la corriente del dispositivo conectado
@@ -122,6 +131,7 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// Powers on a specific outlet on the KMTronic relay device by sending a command to either open or close the relay, depending on the configured mode.
/// </summary>
/// <param name="outletId">The ID of the outlet to power on.</param>
/// <!-- aidoc:v1 sig=a106116 body=4891d13 -->
public override void PowerOnRelay(int outletId)
{
if (Relay.Mode == RelayEnum.Mode.OpenedOffClosedOn) CloseRelay(outletId);
@@ -133,6 +143,8 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// This method is used to power on the outlet by allowing the current to flow through it.
/// </summary>
/// <param name="outletId">The ID of the outlet to close.</param>
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
/// "The summary states the command is sent 'depending on the configured mode', but the code unconditionally sends a fixed command 'FF0{outletId}00' with no mode-based branching." -->
public void CloseRelay(int outletId)
{
//Desactiva el relé por lo que deja pasar la corriente del dispositivo conectado
@@ -143,6 +155,8 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// <summary>
/// Powers off all outlets on the KMTronic relay device by sending a command to either open or close all relays, depending on the configured mode.
/// </summary>
/// <!-- aidoc-review:v1 severity=medium kind=wrong_summary
/// "Documentation states the method sends 'a command to either open or close all relays, depending on the configured mode', but the code unconditionally sends a single fixed command 'FFE0FF' with no mode-based branching visible in this override." -->
public override void PowerOffAll()
{
//Activa el relé por lo que corta la corriente de todos los dispositivo conectados
@@ -152,6 +166,8 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// <summary>
/// Powers on all outlets on the KMTronic relay device by sending a command to either open or close all relays, depending on the configured mode.
/// </summary>
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
/// "The summary states the command sent depends on a 'configured mode' (open vs. close relays), but the code unconditionally sends a single fixed command 'FFE000' with no mode-based branching." -->
public override void PowerOnAll()
{
//Desactiva el relé por lo que deja pasar la corriente a todos dispositivo conectados
@@ -161,6 +177,7 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// <summary>
/// Checks the status of the KMTronic relay device by calling the GetStatusRelay method and updating the DeviceStatus property accordingly.
/// </summary>
/// <!-- aidoc:v1 sig=abdef98 body=abb4ab7 -->
public override void CheckStatus()
{
DeviceStatus = GetStatusRelay();
@@ -170,6 +187,7 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// Reboots a specific outlet on the KMTronic relay device by first powering it off, waiting for a specified delay, and then powering it back on. This method is used to reset the connected device by briefly cutting off its power supply.
/// </summary>
/// <param name="outletId">The ID of the outlet to reboot.</param>
/// <!-- aidoc:v1 sig=1edae69 body=deab68d -->
public override void RebootOutlet(int outletId)
{
//Reinicia el relé del dispositivo conectado
@@ -179,6 +197,7 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// <summary>
/// Reboots all outlets on the KMTronic relay device by first powering them off, waiting for a specified delay, and then powering them back on. This method is used to reset all connected devices by briefly cutting off their power supply.
/// </summary>
/// <!-- aidoc:v1 sig=1be2480 body=f0389f8 -->
public override void Reboot()
{
PowerOffAll();
@@ -191,6 +210,8 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// </summary>
/// <returns>A task representing the asynchronous operation.</returns>
/// <exception cref="NotImplementedException"></exception>
/// <!-- aidoc-review:v1 severity=medium kind=wrong_returns
/// "Method returns Task<bool> (relay status), but <returns> only says 'A task representing the asynchronous operation' without describing the boolean result." -->
public override Task<bool> GetStatusRelayAsync()
{
throw new NotImplementedException();
@@ -199,6 +220,8 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// <summary>
/// Asynchronously retrieves the status of a specific outlet on the KMTronic relay device. This method is not implemented in this class, and it throws a NotImplementedException when called.
/// </summary>
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
/// "Documentation describes an asynchronous outlet status retrieval method that throws NotImplementedException, but the actual code creates/closes a UdpClient to connect to the relay device." -->
protected virtual void Connect()
{
if (_udpClient == null)
@@ -244,6 +267,10 @@ public class KmTronicRelay(Relay relay, RelaySettings relaySettings)
/// </summary>
/// <param name="datagrama">The command to send to the KMTronic relay device.</param>
/// <returns>The response from the KMTronic relay device.</returns>
/// <!-- aidoc-review:v1 severity=medium kind=missing_exception
/// "The method explicitly throws `t.Exception` when the receive task faults within the timeout window, but no <exception> tag is documented." -->
/// <!-- aidoc-review:v1 severity=medium kind=wrong_summary
/// "The summary says the method 'checks if the UDP client is initialized and connected'; the code only checks for null (not connection status) and does not mention the 5-second timeout that causes an empty string to be returned on failure." -->
protected virtual string Send(string datagrama)
{
if (_udpClient == null) Connect();
@@ -11,6 +11,7 @@ namespace adas_core.module.Relays.Devices;
/// <summary>
/// Class representing a KMTronic V2 relay device. This class inherits from the RelayDevice class and provides specific implementations for checking the device status, getting the status of individual relays, and controlling the power state of the relays for a KMTronic V2 relay device.
/// </summary>
/// <!-- aidoc:v1 sig=72b48d3 -->
public class KmTronicV2Relay : RelayDevice
{
/// <summary>
@@ -18,6 +19,7 @@ public class KmTronicV2Relay : RelayDevice
/// </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=3bbe6ca body=0353383 -->
public KmTronicV2Relay(Relay relay, RelaySettings relaySettings) : base(relay, relaySettings)
{
CheckDevice();
@@ -29,6 +31,7 @@ public class KmTronicV2Relay : RelayDevice
/// The method returns true if the device is responsive and provides a valid status, and false otherwise.
/// </summary>
/// <returns>True if the device is responsive and provides a valid status, false otherwise.</returns>
/// <!-- aidoc:v1 sig=b02a15f body=470606e -->
public sealed override bool CheckDevice()
{
CheckStatus();
@@ -42,6 +45,7 @@ public class KmTronicV2Relay : RelayDevice
/// <remarks>
/// The method sends an HTTP GET request to the "status.xml" endpoint of the KMTronic V2 relay device and parses the XML response to update the internal status of each relay.
/// </remarks>
/// <!-- aidoc:v1 sig=abdef98 body=7148801 -->
public override void CheckStatus()
{
try
@@ -91,6 +95,10 @@ public class KmTronicV2Relay : RelayDevice
/// Gets the status of a specific relay outlet by sending a request to the KMTronic V2 relay device. The method returns the status of the specified relay outlet, which can be On, Off, or Unknown.
/// </summary>
/// <returns>True if the specified relay outlet is On, false otherwise.</returns>
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
/// "Summary refers to 'a specific relay outlet' and 'the specified relay outlet', but this overload takes no parameters and always checks relay 1." -->
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
/// "Summary claims the status can be 'On, Off, or Unknown', but the method returns a bool, not a status value." -->
public override bool GetStatusRelay()
{
return GetStatusRelay(1) == RelayEnum.Status.On;
@@ -100,6 +108,10 @@ public class KmTronicV2Relay : RelayDevice
/// Gets the status of a specific relay outlet by sending a request to the KMTronic V2 relay device. The method returns the status of the specified relay outlet, which can be On, Off, or Unknown.
/// </summary>
/// <returns>True if the specified relay outlet is On, false otherwise.</returns>
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
/// "Summary references 'the specified relay outlet' but the method takes no parameters to specify a relay." -->
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
/// "Summary states the method returns 'On, Off, or Unknown' but it returns a bool (true/false)." -->
public override Task<bool> GetStatusRelayAsync()
{
var result = GetStatusRelay();
@@ -110,6 +122,8 @@ public class KmTronicV2Relay : RelayDevice
/// Gets the status of a specific relay outlet by retrieving the status from the internal status dictionary. The method returns the status of the specified relay outlet, which can be On, Off, or Unknown.
/// </summary>
/// <param name="outletId">The ID of the relay outlet.</param>
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
/// "Summary describes getting/returning relay status, but the method PowerOnRelay turns a relay on by calling PowerRelay(outletId, RelayEnum.Status.On) and returns void." -->
public override void PowerOnRelay(int outletId)
{
PowerRelay(outletId, RelayEnum.Status.On);
@@ -119,6 +133,10 @@ public class KmTronicV2Relay : RelayDevice
/// Gets the status of a specific relay outlet by retrieving the status from the internal status dictionary. The method returns the status of the specified relay outlet, which can be On, Off, or Unknown.
/// </summary>
/// <param name="outletId">The ID of the relay outlet.</param>
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
/// "Summary describes getting/retrieving the status of a relay outlet, but the method actually powers off a relay outlet." -->
/// <!-- aidoc-review:v1 severity=high kind=wrong_returns
/// "Summary states the method returns a status (On, Off, or Unknown), but the method returns void." -->
public override void PowerOffRelay(int outletId)
{
PowerRelay(outletId, RelayEnum.Status.Off);
@@ -131,6 +149,7 @@ public class KmTronicV2Relay : RelayDevice
/// <param name="path">The path of the relay device.</param>
/// <param name="query">The query parameters for the request.</param>
/// <returns>The constructed URI.</returns>
/// <!-- aidoc:v1 sig=995f6fd body=c5da058 -->
private Uri GetUri(string path, string? query = null)
{
var uriBuilder = new UriBuilder
@@ -146,6 +165,7 @@ public class KmTronicV2Relay : RelayDevice
/// <param name="method">The HTTP method for the request.</param>
/// <param name="query">The query parameters for the request.</param>
/// <returns>The constructed HttpRequestMessage.</returns>
/// <!-- aidoc:v1 sig=82d34b3 body=c3d1721 -->
private HttpRequestMessage GetRequest(string path, HttpMethod method, string? query = null)
{
var uri = GetUri(path, query);
@@ -169,6 +189,10 @@ public class KmTronicV2Relay : RelayDevice
/// <param name="method">The HTTP method for the request.</param>
/// <param name="query">The query parameters for the request.</param>
/// <returns>The HttpResponseMessage received from the relay device.</returns>
/// <!-- aidoc-review:v1 severity=high kind=wrong_returns
/// "The <returns> tag states the method returns 'The HttpResponseMessage received from the relay device', but when an exception is caught the method returns a locally constructed new HttpResponseMessage(HttpStatusCode.Gone), not one received from the relay." -->
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
/// "The summary's final sentence implies the returned message comes from the relay device after exception handling, but the catch branch synthesizes a HttpStatusCode.Gone response instead; this behavior (and the synthetic Gone return) is not documented." -->
private HttpResponseMessage SendRequest(string path, HttpMethod method, string? query = null)
{
using var client = new HttpClient();
@@ -194,6 +218,7 @@ public class KmTronicV2Relay : RelayDevice
/// <param name="outletId">The ID of the relay outlet to control.</param>
/// <param name="toState">The desired state for the relay outlet (On or Off).</param>
/// <param name="checkStatus">Whether to check the status of the device after sending the request.</param>
/// <!-- aidoc:v1 sig=36b130b body=ee2cc07 -->
private void PowerRelay(int outletId, RelayEnum.Status toState, bool checkStatus = true)
{
if (Relay.Mode == RelayEnum.Mode.OpenedOffClosedOn)
@@ -227,6 +252,8 @@ public class KmTronicV2Relay : RelayDevice
/// The method iterates through all relay outlets and sends requests to change their state to the desired state (On or Off).
/// After sending the requests, it checks the status of the device to ensure that the state changes were successful.
/// </summary>
/// <!-- aidoc-review:v1 severity=low kind=stale_summary
/// "Summary describes the method as changing state to 'On or Off', but the method only sets state to On (RelayEnum.Status.On) since it is PowerOnAll." -->
public override void PowerOnAll()
{
PowerAll(RelayEnum.Status.On);
@@ -235,6 +262,7 @@ public class KmTronicV2Relay : RelayDevice
/// <summary>
/// Controls the power state of all relay outlets by sending requests to the KMTronic V2 relay device.
/// </summary>
/// <!-- aidoc:v1 sig=bfcd3b2 body=2d798c0 -->
public override void PowerOffAll()
{
PowerAll(RelayEnum.Status.Off);
@@ -244,6 +272,7 @@ public class KmTronicV2Relay : RelayDevice
/// Controls the power state of all relay outlets by sending requests to the KMTronic V2 relay device.
/// </summary>
/// <param name="toState">The desired state for all relay outlets (On or Off).</param>
/// <!-- aidoc:v1 sig=b155bab body=11e41a0 -->
private void PowerAll(RelayEnum.Status toState)
{
Enumerable.Range(1, Relay.Total).ToList().ForEach(outletId => { PowerRelay(outletId, toState, false); });
@@ -253,6 +282,7 @@ public class KmTronicV2Relay : RelayDevice
/// <summary>
/// Reboots the KMTronic V2 relay device by first powering off all relay outlets, then waiting for a specified delay (if configured), and finally powering on all relay outlets again.
/// </summary>
/// <!-- aidoc:v1 sig=1be2480 body=f0389f8 -->
public override void Reboot()
{
PowerOffAll();
@@ -264,6 +294,7 @@ public class KmTronicV2Relay : RelayDevice
/// Reboots a specific relay outlet by first powering it off, then waiting for a specified delay (30 seconds in this case), and finally powering it on again.
/// </summary>
/// <param name="outletId">The ID of the relay outlet to reboot.</param>
/// <!-- aidoc:v1 sig=1edae69 body=1a46256 -->
public override void RebootOutlet(int outletId)
{
PowerOffRelay(outletId);
@@ -12,6 +12,7 @@ namespace adas_core.module.Relays.Devices;
/// The class also includes an event to notify when the status of a relay changes.
/// The implementation of the methods is left to the derived classes, which will provide specific functionality based on the type of relay device being used.
/// </summary>
/// <!-- aidoc:v1 sig=d49d435 -->
public abstract class RelayDevice
{
/// <summary>
@@ -42,6 +43,7 @@ public abstract class RelayDevice
/// </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=4036497 body=4a2098e -->
protected RelayDevice(Relay relay, RelaySettings relaySettings)
{
Relay = relay;
@@ -69,23 +71,32 @@ public abstract class RelayDevice
/// Checks the status of the relay device. This method is abstract and must be implemented by derived classes to provide specific functionality for checking the status of the relay device.
/// </summary>
/// <returns></returns>
/// <!-- aidoc-review:v1 severity=medium kind=missing_returns
/// "The <returns> tag is empty; the method returns a bool but its meaning (e.g., true = device OK/connected, false = fault/not found) is not documented." -->
/// <!-- aidoc-review:v1 severity=medium kind=wrong_summary
/// "The summary specifies 'relay device', but the code (CheckDevice) and signature provide no evidence the device is a relay; the term appears to be an unsupported assumption." -->
public abstract bool CheckDevice();
/// <summary>
/// Checks the status of the relays. This method is abstract and must be implemented by derived classes to provide specific functionality for checking the status of the relays.
/// </summary>
/// <!-- aidoc:v1 sig=7c1569a -->
public abstract void CheckStatus();
/// <summary>
/// Gets the status of the relay device. This method is abstract and must be implemented by derived classes to provide specific functionality for retrieving the status of the relay device.
/// </summary>
/// <returns></returns>
/// <!-- aidoc-review:v1 severity=medium kind=missing_returns
/// "The <returns> tag is empty; the method returns a bool indicating the relay status, which is not described." -->
public abstract bool GetStatusRelay();
/// <summary>
/// Gets the status of the relays. This method is abstract and must be implemented by derived classes to provide specific functionality for retrieving the status of the relays.
/// </summary>
/// <returns></returns>
/// <!-- aidoc-review:v1 severity=low kind=missing_returns
/// "The <returns> tag is empty and does not describe what the Task<bool> return value represents." -->
public abstract Task<bool> GetStatusRelayAsync();
/// <summary>
@@ -93,6 +104,7 @@ public abstract class RelayDevice
/// </summary>
/// <param name="outletId">The ID of the relay outlet.</param>
/// <returns>The status of the specified relay outlet.</returns>
/// <!-- aidoc:v1 sig=72e92a5 body=80cb7be -->
public virtual RelayEnum.Status GetStatusRelay(int outletId)
{
lock (_relaysStatus)
@@ -106,6 +118,7 @@ public abstract class RelayDevice
/// </summary>
/// <param name="outletId">The ID of the relay outlet.</param>
/// <param name="status">The new status of the relay outlet.</param>
/// <!-- aidoc:v1 sig=82b3cca body=3d9883a -->
public virtual void SetStatusRelay(int outletId, RelayEnum.Status status)
{
lock (_relaysStatus)
@@ -123,6 +136,8 @@ public abstract class RelayDevice
/// </summary>
/// <param name="outletId">The ID of the relay outlet.</param>
/// <param name="milliseconds">The duration in milliseconds for which the relay outlet should be powered off.</param>
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
/// "The summary states the method 'waits' for the specified milliseconds between PowerOffRelay and PowerOnRelay, but Task.Delay's returned Task is not awaited, so PowerOnRelay runs immediately after PowerOffRelay with no actual delay." -->
public virtual void PowerOnOffRelay(int outletId, int milliseconds)
{
Task.Run(() =>
@@ -137,6 +152,7 @@ public abstract class RelayDevice
/// <summary>
/// Refreshes the status of the relay device. This method is virtual and can be overridden by derived classes to provide specific functionality for refreshing the status of the relay device.
/// </summary>
/// <!-- aidoc:v1 sig=d883f16 body=4448e1d -->
public virtual void Refresh()
{
}
@@ -145,32 +161,38 @@ public abstract class RelayDevice
/// Powers on a specific relay outlet. This method is abstract and must be implemented by derived classes to provide specific functionality for powering on a relay outlet with the specified outlet ID.
/// </summary>
/// <param name="outletId">The ID of the relay outlet to power on.</param>
/// <!-- aidoc:v1 sig=d94c874 -->
public abstract void PowerOnRelay(int outletId);
/// <summary>
/// Powers off a specific relay outlet. This method is abstract and must be implemented by derived classes to provide specific functionality for powering off a relay outlet with the specified outlet ID.
/// </summary>
/// <param name="outletId">The ID of the relay outlet to power off.</param>
/// <!-- aidoc:v1 sig=5394819 -->
public abstract void PowerOffRelay(int outletId);
/// <summary>
/// Powers on all relay outlets. This method is abstract and must be implemented by derived classes to provide specific functionality for powering on all relay outlets.
/// </summary>
/// <!-- aidoc:v1 sig=c996518 -->
public abstract void PowerOnAll();
/// <summary>
/// Powers off all relay outlets. This method is abstract and must be implemented by derived classes to provide specific functionality for powering off all relay outlets.
/// </summary>
/// <!-- aidoc:v1 sig=489ea3b -->
public abstract void PowerOffAll();
/// <summary>
/// Reboots a specific relay outlet. This method is abstract and must be implemented by derived classes to provide specific functionality for rebooting a relay outlet with the specified outlet ID.
/// </summary>
/// <param name="outletId"></param>
/// <!-- aidoc:v1 sig=a3e578d -->
public abstract void RebootOutlet(int outletId);
/// <summary>
/// Reboots all relay outlets. This method is abstract and must be implemented by derived classes to provide specific functionality for rebooting all relay outlets.
/// </summary>
/// <!-- aidoc:v1 sig=4b9c90f -->
public abstract void Reboot();
}