Merge branch 'feature/sodistore-alarm-notification' into main

This commit is contained in:
Yinyin Liu 2026-04-22 10:20:58 +02:00
commit e1a16b3c67
2 changed files with 51 additions and 1 deletions

View File

@ -1,5 +1,6 @@
using InnovEnergy.App.Backend.Database;
using InnovEnergy.App.Backend.Relations;
using InnovEnergy.Lib.Mailer;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.App.Backend.DataTypes.Methods;
@ -171,5 +172,39 @@ public static class InstallationMethods
return true;
}
private const String SupportEmail = "support@inesco.energy";
private const String SupportName = "inesco energy Support Team";
public static Task SendAlarmNotificationToSupport(this Installation installation, Int32 prevStatus)
{
var productName = ProductName(installation.Product);
var fromStatus = StatusName(prevStatus);
var subject = $"[inesco energy] Alarm: {installation.Name}";
var body =
$"Installation \"{installation.Name}\" (ID {installation.Id}, {productName})\n" +
$"status changed from {fromStatus} to Alarm.\n\n" +
"Please check the Log tab on the Monitor to see detailed errors and warnings.\n";
return Mailer.Send(SupportName, SupportEmail, subject, body);
}
private static String StatusName(Int32 status) => status switch
{
-1 => "Offline",
0 => "Green",
1 => "Warning",
2 => "Alarm",
_ => "Unknown"
};
private static String ProductName(Int32 product) => product switch
{
2 => "Sodistore Home",
3 => "Sodistore Max",
4 => "Sodistore Grid",
5 => "Sodistore Pro",
_ => $"Product {product}"
};
}

View File

@ -2,6 +2,7 @@ using System.Text;
using System.Text.Json;
using InnovEnergy.App.Backend.Database;
using InnovEnergy.App.Backend.DataTypes;
using InnovEnergy.App.Backend.DataTypes.Methods;
using InnovEnergy.Lib.Utils;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
@ -186,6 +187,20 @@ public static class RabbitMqManager
Db.UpdateInstallationStatus(installationId, receivedStatusMessage.Status);
const int AlarmStatus = 2;
var isSodistore = installation.Product is 2 or 3 or 4 or 5;
if (isSodistore
&& prevStatus != AlarmStatus
&& receivedStatusMessage.Status == AlarmStatus)
{
var prev = prevStatus;
_ = Task.Run(async () =>
{
try { await installation.SendAlarmNotificationToSupport(prev); }
catch (Exception ex) { Console.WriteLine($"[AlarmNotify] failed for {installationId}: {ex.Message}"); }
});
}
//Console.WriteLine("----------------------------------------------");
//If the status has changed, update all the connected front-ends regarding this installation
if(prevStatus != receivedStatusMessage.Status && WebsocketManager.InstallationConnections[installationId].Connections.Count > 0)