API endpoints for resetting Min/Max-values (#1658)
* API: Reset Min/Max for individual sensor * API: Able to reset all Min/Max values
This commit is contained in:
@@ -244,6 +244,7 @@ public sealed partial class MainForm : Form
|
||||
fahrenheitMenuItem.Checked = !celsiusMenuItem.Checked;
|
||||
|
||||
Server = new HttpServer(_root,
|
||||
_computer,
|
||||
_settings.GetValue("listenerIp", "?"),
|
||||
_settings.GetValue("listenerPort", 8085),
|
||||
_settings.GetValue("authenticationEnabled", false),
|
||||
|
||||
@@ -29,11 +29,13 @@ public class HttpServer
|
||||
{
|
||||
private readonly HttpListener _listener;
|
||||
private readonly Node _root;
|
||||
private readonly IElement _rootElement;
|
||||
private Thread _listenerThread;
|
||||
|
||||
public HttpServer(Node node, string ip, int port, bool authEnabled = false, string userName = "", string password = "")
|
||||
public HttpServer(Node node, IElement rootElement, string ip, int port, bool authEnabled = false, string userName = "", string password = "")
|
||||
{
|
||||
_root = node;
|
||||
_rootElement = rootElement;
|
||||
ListenerIp = ip;
|
||||
ListenerPort = port;
|
||||
AuthEnabled = authEnabled;
|
||||
@@ -241,6 +243,14 @@ public class HttpServer
|
||||
throw new ArgumentException("Unknown id " + dict["id"] + " specified");
|
||||
}
|
||||
|
||||
if (dict["action"] == "ResetMinMax")
|
||||
{
|
||||
// Reset Min/Max, then return Sensor values...
|
||||
sNode.Sensor.ResetMin();
|
||||
sNode.Sensor.ResetMax();
|
||||
dict["action"] = "Get";
|
||||
}
|
||||
|
||||
switch (dict["action"])
|
||||
{
|
||||
case "Set" when dict.ContainsKey("value"):
|
||||
@@ -387,6 +397,17 @@ public class HttpServer
|
||||
return;
|
||||
}
|
||||
|
||||
if (requestedFile.Contains("ResetAllMinMax"))
|
||||
{
|
||||
_rootElement.Accept(new SensorVisitor(delegate (ISensor sensor)
|
||||
{
|
||||
sensor.ResetMin();
|
||||
sensor.ResetMax();
|
||||
}));
|
||||
SendJson(context.Response, request);
|
||||
return;
|
||||
}
|
||||
|
||||
// default file to be served
|
||||
if (string.IsNullOrEmpty(requestedFile))
|
||||
requestedFile = "index.html";
|
||||
|
||||
Reference in New Issue
Block a user