Skip to content

Commit

Permalink
Minor Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jdomnitz committed Sep 16, 2024
1 parent 09ae0a3 commit 5943b21
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 30 deletions.
4 changes: 2 additions & 2 deletions ZWaveDotNet/CommandClassReports/SensorMultiLevelReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +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.ElectricalResistivity: return Units.ohm;
case SensorType.ElectricalResistivity: return Units.ohmMeter;
case SensorType.ElectricalConductivity: return Units.siemensPerMeter;
case SensorType.Loudness: return scale == 1 ? Units.decibalA : Units.decibal;
case SensorType.Moisture: return moistureUnits[scale];
Expand All @@ -90,7 +90,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.BasisMetabolicRate: return Units.BMR;
case SensorType.BasalMetabolicRate: return Units.BMR;
case SensorType.BodyMassIndex: return Units.BMI;
case SensorType.AccelerationXAxis: return Units.metersPerSec2;
case SensorType.AccelerationYAxis: return Units.metersPerSec2;
Expand Down
36 changes: 36 additions & 0 deletions ZWaveDotNet/CommandClassReports/ThermostatFanStateReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// ZWaveDotNet Copyright (C) 2024
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System.Data;
using ZWaveDotNet.CommandClasses.Enums;
using ZWaveDotNet.Util;

namespace ZWaveDotNet.CommandClassReports
{
public class ThermostatFanStateReport : ICommandClassReport
{
public readonly FanState State;

internal ThermostatFanStateReport(ReadOnlySpan<byte> payload)
{
if (payload.Length == 0)
throw new DataException($"The Thermostat State Report was not in the expected format. Payload: {MemoryUtil.Print(payload)}");

State = (FanState)payload[0];
}

public override string ToString()
{
return $"State:{State}";
}
}
}
2 changes: 1 addition & 1 deletion ZWaveDotNet/CommandClasses/Basic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected override async Task<SupervisionStatus> Handle(ReportMessage message)
{
BasicReport rpt = new BasicReport(message.Payload);
await FireEvent(Report, rpt);
Log.Information("Basic Report: " + rpt.ToString());
Log.Verbose("Basic Report: " + rpt.ToString());
return SupervisionStatus.Success;
}
return SupervisionStatus.NoSupport;
Expand Down
8 changes: 4 additions & 4 deletions ZWaveDotNet/CommandClasses/Clock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task<ClockReport> Get(CancellationToken cancellationToken = default
return new ClockReport(response.Payload);
}

public async Task Set(DayOfWeek dayOfWeek, byte hour, byte minute, CancellationToken cancellationToken = default)
public async Task Set(DayOfWeek dayOfWeek, int hour, int minute, CancellationToken cancellationToken = default)
{
await SendClock(dayOfWeek, hour, minute, ClockCommand.Set, cancellationToken);
}
Expand All @@ -53,10 +53,10 @@ protected override async Task<SupervisionStatus> Handle(ReportMessage message)

public override async Task Interview(CancellationToken cancellationToken)
{
await SendClock(DateTime.Now.DayOfWeek, (byte)DateTime.Now.Hour, (byte)DateTime.Now.Minute, ClockCommand.Report, cancellationToken);
await SendClock(DateTime.Now.DayOfWeek, DateTime.Now.Hour, DateTime.Now.Minute, ClockCommand.Report, cancellationToken);
}

private async Task SendClock(DayOfWeek dayOfWeek, byte hour, byte minute, ClockCommand command, CancellationToken cancellationToken)
private async Task SendClock(DayOfWeek dayOfWeek, int hour, int minute, ClockCommand command, CancellationToken cancellationToken)
{
byte day = 0;
switch (dayOfWeek)
Expand Down Expand Up @@ -84,7 +84,7 @@ private async Task SendClock(DayOfWeek dayOfWeek, byte hour, byte minute, ClockC
break;
}

byte[] payload = new byte[] { (byte)(hour & 0x1F), minute };
byte[] payload = new byte[] { (byte)(hour & 0x1F), (byte)minute };
payload[0] |= (byte)(day << 5);

await SendCommand(command, cancellationToken, payload);
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 @@ -64,7 +64,7 @@ public enum SensorType : byte
FatMass = 0x2F,
BoneMass = 0x30,
TotalBodyWater = 0x31,
BasisMetabolicRate = 0x32,
BasalMetabolicRate = 0x32,
BodyMassIndex = 0x33,
AccelerationXAxis = 0x34,
AccelerationYAxis = 0x35,
Expand Down
31 changes: 17 additions & 14 deletions ZWaveDotNet/CommandClasses/Enums/ThermostatModeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ namespace ZWaveDotNet.CommandClasses.Enums
public enum ThermostatModeType
{
OFF = 0x0,
HEAT = 0x1,
COOL = 0x2,
AUTO = 0x3,
AUXILIARY = 0x4,
RESUME = 0x5,
FAN = 0x6,
FURNACE = 0x7,
DRY = 0x8,
MOIST = 0x9,
HEAT = 0x01,
COOL = 0x02,
AUTO = 0x03,
AUXILIARY = 0x04,
/// <summary>
/// This mode is used to resume the last activate mode (different than OFF 0x00).
/// </summary>
RESUME = 0x05,
FAN = 0x06,
FURNACE = 0x07,
DRY = 0x08,
MOIST = 0x09,
AUTO_CHANGEOVER = 0x0A,
ENERGY_HEAT = 0xB,
ENERGY_COOL = 0xC,
AWAY = 0xD,
RESERVED = 0xE,
FULL_POWER = 0xF,
ENERGY_HEAT = 0x0B,
ENERGY_COOL = 0x0C,
AWAY_HEATING_OR_BOTH = 0x0D,
AWAY_COOLING = 0x0E,
FULL_POWER = 0x0F,
MANUFACTURER_SPECIFIC = 0x1F
}
}
4 changes: 2 additions & 2 deletions ZWaveDotNet/CommandClasses/SwitchToggleBinary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace ZWaveDotNet.CommandClasses
[CCVersion(CommandClass.SwitchToggleBinary)]
public class SwitchToggleBinary : CommandClassBase
{
public event CommandClassEvent<SwitchBinaryReport>? Updated;
public event CommandClassEvent<SwitchBinaryReport>? SwitchReport;

public enum SwitchToggleBinaryCommand
{
Expand All @@ -47,7 +47,7 @@ protected override async Task<SupervisionStatus> Handle(ReportMessage message)
{
if (message.Command == (byte)SwitchToggleBinaryCommand.Report)
{
await FireEvent(Updated, new SwitchBinaryReport(message.Payload));
await FireEvent(SwitchReport, new SwitchBinaryReport(message.Payload));
return SupervisionStatus.Success;
}
return SupervisionStatus.NoSupport;
Expand Down
12 changes: 9 additions & 3 deletions ZWaveDotNet/CommandClasses/ThermostatFanState.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 @@ -21,7 +22,7 @@ namespace ZWaveDotNet.CommandClasses
[CCVersion(CommandClass.ThermostatFanState, 2)]
public class ThermostatFanState : CommandClassBase
{

public event CommandClassEvent<ThermostatFanStateReport>? Updated;
public enum ThermostatFanStateCommand
{
Get = 0x02,
Expand All @@ -36,9 +37,14 @@ public async Task<FanState> Get(CancellationToken cancellationToken = default)
return (FanState)(0xF & 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)ThermostatFanStateCommand.Report)
{
await FireEvent(Updated, new ThermostatFanStateReport(message.Payload.Span));
return SupervisionStatus.Success;
}
return SupervisionStatus.NoSupport;
}
}
}
4 changes: 2 additions & 2 deletions ZWaveDotNet/CommandClasses/ThermostatSetpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public enum ThermostatSetpointCommand
Report = 0x03,
SupportedGet = 0x04,
SupportedReport = 0x05,
CapabilitiesGet = 0x04,
CapabilitiesReport = 0x05
CapabilitiesGet = 0x09,
CapabilitiesReport = 0x0A
}

public ThermostatSetpoint(Node node, byte endpoint) : base(node, endpoint, CommandClass.ThermostatSetpoint) { }
Expand Down
8 changes: 8 additions & 0 deletions ZWaveDotNet/CommandClasses/Time.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public async Task<TimeOffsetReport> GetOffset(CancellationToken cancellationToke
return new TimeOffsetReport(response.Payload);
}

public override async Task Interview(CancellationToken cancellationToken)
{
TimeZoneInfo tz = TimeZoneInfo.Local;
TimeZoneInfo.AdjustmentRule[] rules = tz.GetAdjustmentRules();
if (rules.Length > 0)
await SetOffset(tz.BaseUtcOffset, (int)Math.Round(rules[0].DaylightDelta.TotalMinutes), rules[0].DateStart, rules[0].DateEnd, cancellationToken);
}

public async Task SetOffset(TimeSpan utcOffset, int dstOffsetMins, DateTime dstStart, DateTime dstEnd, CancellationToken cancellationToken = default)
{
byte utcHours = (byte)(utcOffset.Hours & 0x7F);
Expand Down
2 changes: 1 addition & 1 deletion ZWaveDotNet/Enums/Units.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public enum Units
Moment,
mVolts,
Newtons,
ohm,
ohmMeter,
pCiPerLiter,
Percent,
PH,
Expand Down

0 comments on commit 5943b21

Please sign in to comment.