Skip to content

Commit

Permalink
Synchronize method signatures. Fix notification unit types.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdomnitz committed Sep 23, 2024
1 parent b10c528 commit 44637f9
Show file tree
Hide file tree
Showing 23 changed files with 85 additions and 46 deletions.
14 changes: 14 additions & 0 deletions ZWaveDotNet/CommandClassReports/EnumReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


namespace ZWaveDotNet.CommandClassReports
{
public class EnumReport<T> : ICommandClassReport where T : Enum
{
public EnumReport(Memory<byte> payload)
{
Value = (T)(object)payload.Span[0];
}

public T Value { get; }
}
}
6 changes: 3 additions & 3 deletions ZWaveDotNet/CommandClassReports/HumiditySetpointReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace ZWaveDotNet.CommandClassReports
{
public class HumiditySetpointReport : ICommandClassReport
{
public readonly HRVStatusParameter StatusType;
public readonly HumidityControlModeType SetpointType;
public readonly float Value;
public readonly Units Unit;

Expand All @@ -28,7 +28,7 @@ internal HumiditySetpointReport(Memory<byte> payload)
if (payload.Length < 3)
throw new DataException($"The Humidity Setpoint Status Report was not in the expected format. Payload: {MemoryUtil.Print(payload)}");

StatusType = (HRVStatusParameter)payload.Span[0];
SetpointType = (HumidityControlModeType)payload.Span[0];
Value = PayloadConverter.ToFloat(payload.Slice(1), out byte scale, out _, out _);
Unit = GetUnit(scale);
}
Expand All @@ -43,7 +43,7 @@ private static Units GetUnit(byte scale)

public override string ToString()
{
return $"Type:{StatusType}, Value:\"{Value} {Unit}\"";
return $"Type:{SetpointType}, Value:\"{Value} {Unit}\"";
}
}
}
12 changes: 7 additions & 5 deletions ZWaveDotNet/CommandClassReports/SensorMultiLevelReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ private static Units GetUnit(SensorType type, byte scale)
case SensorType.General: return scale == 1 ? Units.None : Units.Percent;
case SensorType.Luminance: return scale == 1 ? Units.lux : Units.Percent;
case SensorType.Power: return scale == 1 ? Units.BTUPerHour : Units.Watts;
case SensorType.RelativeHumidity: return Units.Percent;
case SensorType.Humidity: return scale == 1 ? Units.gramPerCubicMeter : Units.Percent;
case SensorType.Velocity: return scale == 1 ? Units.milesPerHour : Units.metersPerSec;
case SensorType.Direction: return Units.None;
case SensorType.Direction: return Units.deg;
case SensorType.AtmosphericPressure: return scale == 1 ? Units.inHg : Units.kPa;
case SensorType.BarometricPressure: return scale == 1 ? Units.inHg : Units.kPa;
case SensorType.SolarRadiation: return Units.WattsPerSquareMeter;
Expand All @@ -68,6 +68,7 @@ private static Units GetUnit(SensorType type, byte scale)
case SensorType.SoilTemperature: return scale == 1 ? Units.degF : Units.degC;
case SensorType.SeismicIntensity: return seismicIntensityUnits[scale];
case SensorType.SeismicMagnitude: return seismicMagnitudeUnits[scale];
case SensorType.Ultraviolet: return Units.None;
case SensorType.ElectricalResistivity: return Units.ohmMeter;
case SensorType.ElectricalConductivity: return Units.siemensPerMeter;
case SensorType.Loudness: return scale == 1 ? Units.decibalA : Units.decibal;
Expand All @@ -90,7 +91,7 @@ private static Units GetUnit(SensorType type, byte scale)
case SensorType.FatMass: return Units.kg;
case SensorType.BoneMass: return Units.kg;
case SensorType.TotalBodyWater: return Units.kg;
case SensorType.BasalMetabolicRate: return Units.BMR;
case SensorType.BasalMetabolicRate: return Units.Joule;
case SensorType.BodyMassIndex: return Units.BMI;
case SensorType.AccelerationXAxis: return Units.metersPerSec2;
case SensorType.AccelerationYAxis: return Units.metersPerSec2;
Expand All @@ -106,9 +107,10 @@ private static Units GetUnit(SensorType type, byte scale)
case SensorType.DomesticHotWaterTemperature: return scale == 1 ? Units.degF : Units.degC;
case SensorType.OutsideTemperature: return scale == 1 ? Units.degF : Units.degC;
case SensorType.ExhaustTemperature: return scale == 1 ? Units.degF : Units.degC;
case SensorType.WaterAcidity: return Units.mgPerLiter;
case SensorType.WaterChlorineLevel: return Units.PH;
case SensorType.WaterAcidity: return Units.PH;
case SensorType.WaterChlorineLevel: return Units.mgPerLiter;
case SensorType.WaterOxidationReductionPotential: return Units.mVolts;
case SensorType.MotionDirection: return Units.deg;
case SensorType.AppliedForceOnTheSensor: return Units.Newtons;
case SensorType.ReturnAirTemperature: return scale == 1 ? Units.degF : Units.degC;
case SensorType.SupplyAirTemperature: return scale == 1 ? Units.degF : Units.degC;
Expand Down
8 changes: 4 additions & 4 deletions ZWaveDotNet/CommandClasses/Association.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ enum AssociationCommand
}
public Association(Node node, byte endpoint) : base(node, endpoint, CommandClass.Association) { }

public async Task<AssociationReport> Get(byte groupID, CancellationToken cancellationToken)
public async Task<AssociationReport> Get(byte groupID, CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(AssociationCommand.Get, AssociationCommand.Report, cancellationToken, groupID);
return new AssociationReport(response.Payload);
}

public async Task<byte> GetSpecific(CancellationToken cancellationToken)
public async Task<byte> GetSpecific(CancellationToken cancellationToken = default)
{
var response = await SendReceive(AssociationCommand.SpecificGroupGet, AssociationCommand.SpecificGroupReport, cancellationToken);
return response.Payload.Span[0];
Expand All @@ -58,13 +58,13 @@ public async Task Remove(byte groupID, CancellationToken cancellationToken, para
await SendCommand(AssociationCommand.Remove, cancellationToken, nodeIDs.Prepend(groupID).ToArray());
}

public async Task<AssociationGroupsReport> GetGroups(CancellationToken cancellationToken)
public async Task<AssociationGroupsReport> GetGroups(CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(AssociationCommand.GroupingsGet, AssociationCommand.GroupingsReport, cancellationToken);
return new AssociationGroupsReport(response.Payload);
}

public override async Task Interview(CancellationToken cancellationToken)
public override async Task Interview(CancellationToken cancellationToken = default)
{
await Add(LIFELINE_GROUP, cancellationToken, (byte)controller.ControllerID);
Log.Information("Assigned Lifeline Group");
Expand Down
2 changes: 1 addition & 1 deletion ZWaveDotNet/CommandClasses/BarrierOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task Set(bool open, CancellationToken cancellationToken = default)
await SendCommand(BarrierOperatorCommand.Set, cancellationToken, open ? (byte)0xFF : (byte)0x00);
}

public async Task<BarrierSignal[]> GetSupportedSignals(CancellationToken cancellationToken)
public async Task<BarrierSignal[]> GetSupportedSignals(CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(BarrierOperatorCommand.SupportedGet, BarrierOperatorCommand.SupportedReport, cancellationToken);
List<BarrierSignal> supportedTypes = new List<BarrierSignal>();
Expand Down
2 changes: 1 addition & 1 deletion ZWaveDotNet/CommandClasses/CommandClassBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ protected async Task<ReportMessage> SendReceive(Enum command, Enum response, Can
return await src.Task;
}

protected async Task FireEvent<T>(CommandClassEvent<T>? evt, T? report) where T : ICommandClassReport?
protected async Task FireEvent<T>(CommandClassEvent<T>? evt, T? report) where T : ICommandClassReport
{
if (evt != null)
await evt.Invoke(node, new CommandClassEventArgs<T>(this, report));
Expand Down
2 changes: 1 addition & 1 deletion ZWaveDotNet/CommandClasses/Enums/SensorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum SensorType : byte
General = 0x02,
Luminance = 0x03,
Power = 0x04,
RelativeHumidity = 0x05,
Humidity = 0x05,
Velocity = 0x06,
Direction = 0x07,
AtmosphericPressure = 0x08,
Expand Down
8 changes: 4 additions & 4 deletions ZWaveDotNet/CommandClasses/HRVControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ enum HRVControlCommand
SupportedReport = 0x0B
}

public async Task<HRVModeType[]> GetSupportedParameters(CancellationToken cancellationToken)
public async Task<HRVModeType[]> GetSupportedParameters(CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(HRVControlCommand.SupportedGet, HRVControlCommand.SupportedReport, cancellationToken);
List<HRVModeType> supportedTypes = new List<HRVModeType>();
Expand All @@ -52,7 +52,7 @@ public async Task<HRVModeType[]> GetSupportedParameters(CancellationToken cancel
return supportedTypes.ToArray();
}

public async Task<HRVModeType> GetMode(CancellationToken cancellationToken)
public async Task<HRVModeType> GetMode(CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(HRVControlCommand.ModeGet, HRVControlCommand.ModeReport, cancellationToken);
return (HRVModeType)response.Payload.Span[0];
Expand All @@ -63,7 +63,7 @@ public async Task SetMode(HRVModeType mode, CancellationToken cancellationToken
await SendCommand(HRVControlCommand.ModeSet, cancellationToken, (byte)mode);
}

public async Task<byte> GetBypass(CancellationToken cancellationToken)
public async Task<byte> GetBypass(CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(HRVControlCommand.BypassGet, HRVControlCommand.BypassReport, cancellationToken);
return response.Payload.Span[0];
Expand All @@ -80,7 +80,7 @@ public async Task SetBypass(byte amount, CancellationToken cancellationToken = d
await SendCommand(HRVControlCommand.BypassSet, cancellationToken, amount);
}

public async Task<byte> GetVentillationRate(CancellationToken cancellationToken)
public async Task<byte> GetVentillationRate(CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(HRVControlCommand.VentRateGet, HRVControlCommand.VentRateReport, cancellationToken);
return response.Payload.Span[0];
Expand Down
4 changes: 2 additions & 2 deletions ZWaveDotNet/CommandClasses/HRVStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enum HRVStatusCommand
SupportedReport = 0x04
}

public async Task<HRVStatusParameter[]> GetSupportedParameters(CancellationToken cancellationToken)
public async Task<HRVStatusParameter[]> GetSupportedParameters(CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(HRVStatusCommand.SupportedGet, HRVStatusCommand.SupportedReport, cancellationToken);
List<HRVStatusParameter> supportedTypes = new List<HRVStatusParameter>();
Expand All @@ -49,7 +49,7 @@ public async Task<HRVStatusParameter[]> GetSupportedParameters(CancellationToken
return supportedTypes.ToArray();
}

public async Task<HRVStatusReport> Get(HRVStatusParameter type, CancellationToken cancellationToken)
public async Task<HRVStatusReport> Get(HRVStatusParameter type, CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(HRVStatusCommand.Get, HRVStatusCommand.Report, cancellationToken, (byte)type);
return new HRVStatusReport(response.Payload);
Expand Down
15 changes: 11 additions & 4 deletions ZWaveDotNet/CommandClasses/HumidityControlMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

using System.Collections;
using ZWaveDotNet.CommandClasses.Enums;
using ZWaveDotNet.CommandClassReports;
using ZWaveDotNet.CommandClassReports.Enums;
using ZWaveDotNet.Entities;
using ZWaveDotNet.Enums;
Expand All @@ -22,6 +23,7 @@ namespace ZWaveDotNet.CommandClasses
[CCVersion(CommandClass.HumidityControlMode, 1, 1)]
public class HumidityControlMode : CommandClassBase
{
public event CommandClassEvent<EnumReport<HumidityControlModeType>>? Updated;
public HumidityControlMode(Node node, byte endpoint) : base(node, endpoint, CommandClass.HumidityControlMode) { }

enum HumidityControlModeCommand
Expand All @@ -33,7 +35,7 @@ enum HumidityControlModeCommand
SupportedReport = 0x05
}

public async Task<HumidityControlModeType[]> GetSupportedModes(CancellationToken cancellationToken)
public async Task<HumidityControlModeType[]> GetSupportedModes(CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(HumidityControlModeCommand.SupportedGet, HumidityControlModeCommand.SupportedReport, cancellationToken);
List<HumidityControlModeType> supportedTypes = new List<HumidityControlModeType>();
Expand All @@ -46,7 +48,7 @@ public async Task<HumidityControlModeType[]> GetSupportedModes(CancellationToken
return supportedTypes.ToArray();
}

public async Task<HumidityControlModeType> Get(CancellationToken cancellationToken)
public async Task<HumidityControlModeType> Get(CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(HumidityControlModeCommand.Get, HumidityControlModeCommand.Report, cancellationToken);
return (HumidityControlModeType)response.Payload.Span[0];
Expand All @@ -57,9 +59,14 @@ public async Task Set(HumidityControlModeType mode, CancellationToken cancellati
await SendCommand(HumidityControlModeCommand.Set, cancellationToken, (byte)mode);
}

protected override Task<SupervisionStatus> Handle(ReportMessage message)
protected override async Task<SupervisionStatus> Handle(ReportMessage message)
{
return Task.FromResult(SupervisionStatus.NoSupport);
if (message.Command == (byte)HumidityControlModeCommand.Report)
{
await FireEvent(Updated, new EnumReport<HumidityControlModeType>(message.Payload));
return SupervisionStatus.Success;
}
return SupervisionStatus.NoSupport;
}
}
}
14 changes: 11 additions & 3 deletions ZWaveDotNet/CommandClasses/HumidityControlOperatingState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using ZWaveDotNet.CommandClasses.Enums;
using ZWaveDotNet.CommandClassReports;
using ZWaveDotNet.CommandClassReports.Enums;
using ZWaveDotNet.Entities;
using ZWaveDotNet.Enums;
Expand All @@ -23,21 +24,28 @@ public class HumidityControlOperatingState : CommandClassBase
{
public HumidityControlOperatingState(Node node, byte endpoint) : base(node, endpoint, CommandClass.HumidityControlOperatingState) { }

public event CommandClassEvent<EnumReport<HumidityControlModeType>>? Updated;

enum HumidityControlOperatingStateCommand
{
Get = 0x01,
Report = 0x02,
}

public async Task<HumidityControlModeType> Get(CancellationToken cancellationToken)
public async Task<HumidityControlModeType> Get(CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(HumidityControlOperatingStateCommand.Get, HumidityControlOperatingStateCommand.Report, cancellationToken);
return (HumidityControlModeType)response.Payload.Span[0];
}

protected override Task<SupervisionStatus> Handle(ReportMessage message)
protected override async Task<SupervisionStatus> Handle(ReportMessage message)
{
return Task.FromResult(SupervisionStatus.NoSupport);
if (message.Command == (byte)HumidityControlOperatingStateCommand.Report)
{
await FireEvent(Updated, new EnumReport<HumidityControlModeType>(message.Payload));
return SupervisionStatus.Success;
}
return SupervisionStatus.NoSupport;
}
}
}
18 changes: 12 additions & 6 deletions ZWaveDotNet/CommandClasses/HumidityControlSetpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace ZWaveDotNet.CommandClasses
[CCVersion(CommandClass.HumidityControlSetpoint, 1, 2)]
public class HumidityControlSetpoint : CommandClassBase
{
public event CommandClassEvent<HumiditySetpointReport>? Updated;
public HumidityControlSetpoint(Node node, byte endpoint) : base(node, endpoint, CommandClass.HumidityControlSetpoint) { }

enum HumidityControlSetpointCommand
Expand All @@ -39,7 +40,7 @@ enum HumidityControlSetpointCommand
CapabilitiesReport = 0x05,
}

public async Task<HumidityControlModeType[]> GetSupportedModes(CancellationToken cancellationToken)
public async Task<HumidityControlModeType[]> GetSupportedModes(CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(HumidityControlSetpointCommand.SupportedGet, HumidityControlSetpointCommand.SupportedReport, cancellationToken);
List<HumidityControlModeType> supportedTypes = new List<HumidityControlModeType>();
Expand All @@ -52,13 +53,13 @@ public async Task<HumidityControlModeType[]> GetSupportedModes(CancellationToken
return supportedTypes.ToArray();
}

public async Task<HumiditySetpointReport> Get(CancellationToken cancellationToken)
public async Task<HumiditySetpointReport> Get(CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(HumidityControlSetpointCommand.Get, HumidityControlSetpointCommand.Report, cancellationToken);
return new HumiditySetpointReport(response.Payload);
}

public async Task<Units> GetSupportedUnits(HumidityControlModeType type, CancellationToken cancellationToken)
public async Task<Units> GetSupportedUnits(HumidityControlModeType type, CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(HumidityControlSetpointCommand.ScaleSupportedGet, HumidityControlSetpointCommand.ScaleSupportedReport, cancellationToken, (byte)type);
if (response.Payload.Span[0] == 0)
Expand All @@ -67,7 +68,7 @@ public async Task<Units> GetSupportedUnits(HumidityControlModeType type, Cancell
return Units.gramPerCubicMeter;
}

public async Task<HumiditySetpointCapabilitiesReport> GetSupportedRange(HumidityControlModeType type, CancellationToken cancellationToken)
public async Task<HumiditySetpointCapabilitiesReport> GetSupportedRange(HumidityControlModeType type, CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(HumidityControlSetpointCommand.CapabilitiesGet, HumidityControlSetpointCommand.CapabilitiesReport, cancellationToken, (byte)type);
return new HumiditySetpointCapabilitiesReport(response.Payload);
Expand Down Expand Up @@ -95,9 +96,14 @@ public async Task Set(float value, Units unit, HumidityControlModeType type, Can
await SendCommand(HumidityControlSetpointCommand.Set, cancellationToken, payload.Array!);
}

protected override Task<SupervisionStatus> Handle(ReportMessage message)
protected override async Task<SupervisionStatus> Handle(ReportMessage message)
{
return Task.FromResult(SupervisionStatus.NoSupport);
if (message.Command == (byte)HumidityControlSetpointCommand.Report)
{
await FireEvent(Updated, new HumiditySetpointReport(message.Payload));
return SupervisionStatus.Success;
}
return SupervisionStatus.NoSupport;
}
}
}
2 changes: 1 addition & 1 deletion ZWaveDotNet/CommandClasses/Lock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum LockCommand
Report = 0x03
}

public async Task<bool> Get(CancellationToken cancellationToken)
public async Task<bool> Get(CancellationToken cancellationToken = default)
{
ReportMessage response = await SendReceive(LockCommand.Get, LockCommand.Report, cancellationToken);
return response.Payload.Span[0] != 0x0;
Expand Down
Loading

0 comments on commit 44637f9

Please sign in to comment.