Skip to content

Commit

Permalink
microclimate data: LowBattery field & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dima117 committed Sep 29, 2017
1 parent 1d843be commit cd91583
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 26 additions & 4 deletions ThinkingHome.NooLite.Tests/MicroclimateData/ParseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ThinkingHome.NooLite.Tests.MicroclimateData
{
using H = TestHelpers;

public class ParseTest
{
[Fact]
Expand All @@ -28,7 +28,7 @@ public void Parse_TwoByteTemperature_IsCorrect()

Assert.Equal((decimal)27.5, data.Temperature);
}

[Fact]
public void Parse_NegativeTemperature_IsCorrect()
{
Expand All @@ -45,7 +45,7 @@ public void Parse_NegativeTemperature_IsCorrect()
public void Parse_Humidity_IsCorrect()
{
byte[] bytes = H.GetBytes()
.Set(8, 0b00100000) // bits 4-6 == 010 => PT111
.Set(8, 0b00100000) // bits 4-6 == 010 => PT111
.Set(9, 0b00001101); // 13 - humidity value

var data = new NooLite.MicroclimateData(bytes);
Expand All @@ -57,11 +57,33 @@ public void Parse_Humidity_IsCorrect()
public void Parse_EmptyHumidity_IsCorrect()
{
byte[] bytes = H.GetBytes()
.Set(8, 0b00010000); // bits 4-6 == 001 => PT112
.Set(8, 0b00010000); // bits 4-6 == 001 => PT112

var data = new NooLite.MicroclimateData(bytes);

Assert.Null(data.Humidity);
}

[Fact]
public void Parse_PositiveLowBatteryStatus_IsCorrect()
{
byte[] bytes = H.GetBytes()
.Set(8, 0b00000000); // bits 7 == 0 => battery is ok

var data = new NooLite.MicroclimateData(bytes);

Assert.False(data.LowBattery);
}

[Fact]
public void Parse_NegativeLowBatteryStatus_IsCorrect()
{
byte[] bytes = H.GetBytes()
.Set(8, 0b10000000); // bits 7 == 1 => low battery

var data = new NooLite.MicroclimateData(bytes);

Assert.True(data.LowBattery);
}
}
}
2 changes: 2 additions & 0 deletions ThinkingHome.NooLite/MicroclimateData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public MicroclimateData(byte[] data) : base(data)
public decimal Temperature => ParseTemperature(Data1, Data2);

public int? Humidity => ParseHumidity(Data2, Data3);

public bool LowBattery => Data2 >> 7 == 1;

private static decimal ParseTemperature(byte data1, byte data2)
{
Expand Down

0 comments on commit cd91583

Please sign in to comment.