=== 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
@@ -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);