Skip to content

Commit

Permalink
fix parsing of nullable values in liquidctl cli
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarucha committed May 20, 2022
1 parent a2284f7 commit a1ac94c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions LiquidctlDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public LiquidTemperature(LiquidctlStatusJSON output)
}
public void UpdateFromJSON(LiquidctlStatusJSON output)
{
_value = output.status.Single(entry => entry.key == "Liquid temperature").value;
_value = (float)output.status.Single(entry => entry.key == "Liquid temperature").value;
}
public string Id => _id;
string _id;
Expand All @@ -40,7 +40,7 @@ public PumpSpeed(LiquidctlStatusJSON output)
}
public void UpdateFromJSON(LiquidctlStatusJSON output)
{
_value = output.status.Single(entry => entry.key == "Pump speed").value;
_value = (float)output.status.Single(entry => entry.key == "Pump speed").value;
}
public string Id => _id;
readonly string _id;
Expand All @@ -65,7 +65,7 @@ public PumpDuty(LiquidctlStatusJSON output)
}
public void UpdateFromJSON(LiquidctlStatusJSON output)
{
_value = output.status.Single(entry => entry.key == "Pump duty").value;
_value = (float)output.status.Single(entry => entry.key == "Pump duty").value;
}
public string Id => _id;
string _id;
Expand Down Expand Up @@ -95,15 +95,15 @@ public LiquidctlDevice(LiquidctlStatusJSON output)
{
address = output.address;

hasPumpSpeed = output.status.Exists(entry => entry.key == "Pump duty");
hasPumpSpeed = output.status.Exists(entry => entry.key == "Pump duty" && !(entry.value is null));
if (hasPumpSpeed)
pumpDuty = new PumpDuty(output);

hasPumpDuty = output.status.Exists(entry => entry.key == "Pump speed");
hasPumpDuty = output.status.Exists(entry => entry.key == "Pump speed" && !(entry.value is null));
if (hasPumpDuty)
pumpSpeed = new PumpSpeed(output);

hasLiquidTemperature = output.status.Exists(entry => entry.key == "Liquid temperature");
hasLiquidTemperature = output.status.Exists(entry => entry.key == "Liquid temperature" && !(entry.value is null));
if (hasLiquidTemperature)
liquidTemperature = new LiquidTemperature(output);
}
Expand Down
2 changes: 1 addition & 1 deletion LiquidctlStatusJSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class LiquidctlStatusJSON
public class StatusRecord
{
public string key { get; set; }
public float value { get; set; }
public float? value { get; set; }
public string unit { get; set; }
}
public string bus { get; set; }
Expand Down

0 comments on commit a1ac94c

Please sign in to comment.