Skip to content

Commit

Permalink
Merge pull request #214 from mcrossley/main
Browse files Browse the repository at this point in the history
V4.3.0 Merge
  • Loading branch information
mcrossley authored Dec 4, 2024
2 parents a1e9620 + 51c8d66 commit 585d9eb
Show file tree
Hide file tree
Showing 71 changed files with 7,066 additions and 3,456 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,8 @@ dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
dotnet_style_prefer_collection_expression = true:suggestion

dotnet_remove_unnecessary_suppression_exclusions = CA1416


[SQLite.cs]
generated_code = true
171 changes: 161 additions & 10 deletions CHANGELOG.md

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions CumulusMX/AirQualityIndices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ internal static class AirQualityIndices
/*
* US AQI - United States Environmental Protection Agency (EPA)
* https://www.airnow.gov/sites/default/files/2018-05/aqi-technical-assistance-document-may2016.pdf
* https://www.epa.gov/system/files/documents/2024-02/pm-naaqs-air-quality-index-fact-sheet.pdf
*/

public static int US_EPApm2p5(double pmVal)
Expand Down Expand Up @@ -56,21 +57,21 @@ public static int US_EPApm2p5(double pmVal)
//Ihigh = 150
retVal = 100 + Interpolate(35.4, 55.4, pmVal) * 50;
}
else if (pmVal >= 12)
else if (pmVal >= 9)
{
//Clow = 12.1
//Clow = 9.1
//Chigh = 35.4
//Ilow = 51
//Ihigh = 100
retVal = 50 + Interpolate(12, 35.4, pmVal) * 50;
retVal = 50 + Interpolate(9, 35.4, pmVal) * 50;
}
else
{
//Clow = 0
//Chigh = 12
//Chigh = 9
//Ilow = 0
//Ihigh = 50
retVal = Interpolate(0, 12, pmVal) * 50;
retVal = Interpolate(0, 9, pmVal) * 50;
}
//return (Ihigh - Ilow) / (Chigh - Clow) * (pmVal - Clow) + Ilow
return (int) Math.Round(retVal);
Expand Down Expand Up @@ -180,7 +181,8 @@ public static double UK_COMEAPpm2p5(double pmVal)

/*
* UK Air Quality Index - Committee on the Medical Effects of Air Pollutants (COMEAP)
* https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/304633/COMEAP_review_of_the_uk_air_quality_index.pdf
* https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/304633/COMEAP_review_of_the_uk_air_quality_index.pdf (2011)
* https://assets.publishing.service.gov.uk/media/5a749a66e5274a44083b8003/COMEAP_review_of_the_uk_air_quality_index.pdf (2011)
* Only integer values are defined, but we will interpolate between them
*/
public static double UK_COMEAPpm10(double pmVal)
Expand Down
205 changes: 154 additions & 51 deletions CumulusMX/Alarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public bool Triggered
public bool Latch { get; set; }
public double LatchHours { get; set; }
public string EmailMsg { get; set; }
public string BskyFile { get; set; }
public string Units { get; set; } = units;
public string LastMessage { get; set; }
public int TriggerThreshold { get; set; }
Expand Down Expand Up @@ -119,32 +120,66 @@ private void DoTriggered(bool value)

if (!string.IsNullOrEmpty(Action))
{
if (!File.Exists(Action))
try
{
cumulus.LogWarningMessage($"Warning: Alarm ({Name}): External program: '{Action}' does not exist");
var args = string.Empty;
// Prepare the process to run
if (!string.IsNullOrEmpty(ActionParams))
{
var parser = new TokenParser(cumulus.TokenParserOnToken)
{
InputText = ActionParams
};
args = parser.ToStringFromString();
}
cumulus.LogMessage($"Alarm ({Name}): Starting external program: '{Action}', with parameters: {args}");
_ = Utils.RunExternalTask(Action, args, false, false, ShowWindow);
}
else
catch (FileNotFoundException ex)
{
try
cumulus.LogWarningMessage($"Warning: Alarm ({Name}): External program: '{Action}' does not exist - " + ex.Message);
}
catch (Exception ex)
{
cumulus.LogExceptionMessage(ex, $"Alarm ({Name}): Error executing external program '{Action}' '{ActionParams}'");
}
}

if (cumulus.Bluesky.Enabled && !string.IsNullOrEmpty(BskyFile) && BskyFile != "none")
{
if (File.Exists(BskyFile))
{
if (!string.IsNullOrEmpty(cumulus.Bluesky.ID) && !string.IsNullOrEmpty(cumulus.Bluesky.PW))
{
var args = string.Empty;
// Prepare the process to run
if (!string.IsNullOrEmpty(ActionParams))
// read the template contents
var template = File.ReadAllText(BskyFile);

// check for including the default alarm message
if (template.Contains("|IncludeAlarmMessage|"))
{
var parser = new TokenParser(cumulus.TokenParserOnToken)
var msg = EmailMsg ?? string.Empty;

if (!string.IsNullOrEmpty(LastMessage))
{
InputText = ActionParams
};
args = parser.ToStringFromString();
msg += "\r\nLast message: " + LastMessage;
}

template = template.Replace("|IncludeAlarmMessage|", string.Format(msg, Value, Units));
}
cumulus.LogMessage($"Alarm ({Name}): Starting external program: '{Action}', with parameters: {args}");
Utils.RunExternalTask(Action, args, false, false, ShowWindow);
}
catch (Exception ex)
{
cumulus.LogErrorMessage($"Alarm ({Name}): Error executing external program '{Action}': {ex.Message}");

var parser = new TokenParser(cumulus.TokenParserOnToken)
{
InputText = template
};
template = parser.ToStringFromString();

_ = cumulus.Bluesky.DoUpdate(template);
}
}
else
{
cumulus.LogWarningMessage($"Warning: Alarm ({Name}): Bluesky file: '{BskyFile}' does not exist");
}
}
}

Expand Down Expand Up @@ -300,33 +335,67 @@ private void DoUpTriggered(bool value)

if (!string.IsNullOrEmpty(Action))
{
if (!File.Exists(Action))
try
{
var args = string.Empty;
// Prepare the process to run
if (!string.IsNullOrEmpty(ActionParams))
{
var parser = new TokenParser(cumulus.TokenParserOnToken)
{
InputText = ActionParams
};
args = parser.ToStringFromString();
}
cumulus.LogMessage($"Alarm ({NameUp}): Starting external program: '{Action}', with parameters: {args}");
_ = Utils.RunExternalTask(Action, args, false, false, ShowWindow);
}
catch (FileNotFoundException ex)
{
cumulus.LogWarningMessage($"Warning: Alarm ({Name}): External program: '{Action}' does not exist");
cumulus.LogWarningMessage($"Warning: Alarm ({NameUp}): External program: '{Action}' does not exist - " + ex.Message);
}
else
catch (Exception ex)
{
try
cumulus.LogExceptionMessage(ex, $"Alarm ({NameUp}): Error executing external program '{Action}'");
}
}
}

if (cumulus.Bluesky.Enabled && !string.IsNullOrEmpty(BskyFile) && BskyFile != "none")
{
if (File.Exists(BskyFile))
{
if (!string.IsNullOrEmpty(cumulus.Bluesky.ID) && !string.IsNullOrEmpty(cumulus.Bluesky.PW))
{
// read the template contents
var template = File.ReadAllText(BskyFile);

// check for including the default alarm message
if (template.Contains("|IncludeAlarmMessage|"))
{
var args = string.Empty;
// Prepare the process to run
if (!string.IsNullOrEmpty(ActionParams))
var msg = EmailMsg ?? string.Empty;

if (!string.IsNullOrEmpty(LastMessage))
{
var parser = new TokenParser(cumulus.TokenParserOnToken)
{
InputText = ActionParams
};
args = parser.ToStringFromString();
msg += "\r\nLast message: " + LastMessage;
}
cumulus.LogMessage($"Alarm ({NameUp}): Starting external program: '{Action}', with parameters: {args}");
Utils.RunExternalTask(Action, args, false, false, ShowWindow);

template = template.Replace("|IncludeAlarmMessage|", string.Format(msg, Value, Units));
}
catch (Exception ex)

var parser = new TokenParser(cumulus.TokenParserOnToken)
{
cumulus.LogErrorMessage($"Alarm ({NameUp}): Error executing external program '{Action}': {ex.Message}");
}
InputText = template
};
template = parser.ToStringFromString();

_ = cumulus.Bluesky.DoUpdate(template);
}
}
else
{
cumulus.LogWarningMessage($"Warning: Alarm ({NameUp}): Bluesky file: '{BskyFile}' does not exist");
}
}

// If we get a new trigger, record the time
Expand Down Expand Up @@ -387,33 +456,66 @@ private void DoDownTriggered(bool value)

if (!string.IsNullOrEmpty(Action))
{
if (!File.Exists(Action))
try
{
var args = string.Empty;
// Prepare the process to run
if (!string.IsNullOrEmpty(ActionParams))
{
var parser = new TokenParser(cumulus.TokenParserOnToken)
{
InputText = ActionParams
};
args = parser.ToStringFromString();
}
cumulus.LogMessage($"Alarm ({NameDown}): Starting external program: '{Action}', with parameters: {args}");
_ = Utils.RunExternalTask(Action, args, false, false, ShowWindow);
}
catch (FileNotFoundException ex)
{
cumulus.LogWarningMessage($"Warning: Alarm ({Name}): External program: '{Action}' does not exist");
cumulus.LogWarningMessage($"Warning: Alarm ({NameDown}): External program: '{Action}' does not exist - " + ex.Message);
}
else
catch (Exception ex)
{
cumulus.LogExceptionMessage(ex, $"Alarm ({NameDown}): Error executing external program '{Action}'");
}
}

try
if (cumulus.Bluesky.Enabled && !string.IsNullOrEmpty(BskyFile) && BskyFile != "none")
{
if (File.Exists(BskyFile))
{
if (!string.IsNullOrEmpty(cumulus.Bluesky.ID) && !string.IsNullOrEmpty(cumulus.Bluesky.PW))
{
var args = string.Empty;
// Prepare the process to run
if (!string.IsNullOrEmpty(ActionParams))
// read the template contents
var template = File.ReadAllText(BskyFile);

// check for including the default alarm message
if (template.Contains("|IncludeAlarmMessage|"))
{
var parser = new TokenParser(cumulus.TokenParserOnToken)
var msg = EmailMsg ?? string.Empty;

if (!string.IsNullOrEmpty(LastMessage))
{
InputText = ActionParams
};
args = parser.ToStringFromString();
msg += "\r\nLast message: " + LastMessage;
}

template = template.Replace("|IncludeAlarmMessage|", string.Format(msg, Value, Units));
}
cumulus.LogMessage($"Alarm ({NameDown}): Starting external program: '{Action}', with parameters: {args}");
Utils.RunExternalTask(Action, args, false, false, ShowWindow);
}
catch (Exception ex)
{
cumulus.LogErrorMessage($"Alarm ({NameDown}): Error executing external program '{Action}': {ex.Message}");

var parser = new TokenParser(cumulus.TokenParserOnToken)
{
InputText = template
};
template = parser.ToStringFromString();

_ = cumulus.Bluesky.DoUpdate(template);
}
}
else
{
cumulus.LogWarningMessage($"Warning: Alarm ({NameDown}): Bluesky file: '{BskyFile}' does not exist");
}
}
}

Expand Down Expand Up @@ -450,6 +552,7 @@ public enum AlarmTypes
{
Above,
Below,
Equals,
Change,
Trigger
}
Expand Down
Loading

0 comments on commit 585d9eb

Please sign in to comment.