Relay warming, cooling and shutdown messages

This commit is contained in:
Heath Volmer
2017-12-13 14:36:13 -07:00
parent ae496f556b
commit 289a33451f
5 changed files with 87 additions and 13 deletions

View File

@@ -40,6 +40,12 @@ namespace PepperDash.Essentials
Room.CurrentVolumeDeviceChange += new EventHandler<VolumeDeviceChangeEventArgs>(Room_CurrentVolumeDeviceChange);
Room.OnFeedback.OutputChange += new EventHandler<EventArgs>(OnFeedback_OutputChange);
Room.IsCoolingDownFeedback.OutputChange += new EventHandler<EventArgs>(IsCoolingDownFeedback_OutputChange);
Room.IsWarmingUpFeedback.OutputChange += new EventHandler<EventArgs>(IsWarmingUpFeedback_OutputChange);
Room.ShutdownPromptTimer.HasStarted += new EventHandler<EventArgs>(ShutdownPromptTimer_HasStarted);
Room.ShutdownPromptTimer.HasFinished += new EventHandler<EventArgs>(ShutdownPromptTimer_HasFinished);
Room.ShutdownPromptTimer.WasCancelled += new EventHandler<EventArgs>(ShutdownPromptTimer_WasCancelled);
// Registers for initial volume events, if possible
var currentVolumeDevice = Room.CurrentVolumeControls;
@@ -57,6 +63,74 @@ namespace PepperDash.Essentials
}
void ShutdownPromptTimer_WasCancelled(object sender, EventArgs e)
{
JObject roomStatus = new JObject();
roomStatus.Add("state", "wasCancelled");
JObject message = new JObject();
message.Add("type", "/room/shutdown/");
message.Add("content", roomStatus);
Parent.PostToServer(Room, message);
}
void ShutdownPromptTimer_HasFinished(object sender, EventArgs e)
{
JObject roomStatus = new JObject();
roomStatus.Add("state", "hasFinished");
JObject message = new JObject();
message.Add("type", "/room/shutdown/");
message.Add("content", roomStatus);
Parent.PostToServer(Room, message);
}
void ShutdownPromptTimer_HasStarted(object sender, EventArgs e)
{
JObject roomStatus = new JObject();
roomStatus.Add("state", "hasStarted");
roomStatus.Add("duration", Room.ShutdownPromptTimer.SecondsToCount);
JObject message = new JObject();
message.Add("type", "/room/shutdown/");
message.Add("content", roomStatus);
Parent.PostToServer(Room, message);
// equivalent JS message:
// Post( { type: '/room/status/', content: { shutdown: 'hasStarted', duration: Room.ShutdownPromptTimer.SecondsToCount })
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void IsWarmingUpFeedback_OutputChange(object sender, EventArgs e)
{
JObject roomStatus = new JObject();
roomStatus.Add("isWarmingUp", (sender as BoolFeedback).BoolValue);
JObject message = new JObject();
message.Add("type", "/room/status/");
message.Add("content", roomStatus);
Parent.PostToServer(Room, message);
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void IsCoolingDownFeedback_OutputChange(object sender, EventArgs e)
{
JObject roomStatus = new JObject();
roomStatus.Add("isCoolingDown", (sender as BoolFeedback).BoolValue);
JObject message = new JObject();
message.Add("type", "/room/status/");
message.Add("content", roomStatus);
Parent.PostToServer(Room, message);
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void OnFeedback_OutputChange(object sender, EventArgs e)
{
/* Example message

View File

@@ -205,26 +205,26 @@ namespace PepperDash.Essentials
{
try
{
if(Client == null)
//if(Client == null)
Client = new HttpClient();
Client.Verbose = true;
Client.KeepAlive = true;
string url = string.Format("http://{0}/api/system/{1}/status", Config.ServerUrl, SystemUuid);
HttpClientRequest request = new HttpClientRequest();
request.Url.Parse(url);
request.RequestType = RequestType.Post;
request.Header.SetHeaderValue("Content-Type", "application/json");
request.KeepAlive = true;
// Ignore any null objects when serializing and remove formatting
string ignored = JsonConvert.SerializeObject(o, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
request.ContentString = ignored;
Debug.Console(1, this, "Posting to '{0}':\n{1}", url, request.ContentString);
try
{
HttpClientRequest request = new HttpClientRequest();
request.RequestType = RequestType.Post;
string url = string.Format("http://{0}/api/system/{1}/status", Config.ServerUrl, SystemUuid);
request.Url.Parse(url);
request.KeepAlive = true;
request.Header.ContentType = "application/json";
// Ignore any null objects when serializing and remove formatting
string ignored = JsonConvert.SerializeObject(o, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
Debug.Console(1, this, "Posting to '{0}':\n{1}", url, ignored);
request.ContentString = ignored;
request.FinalizeHeader();
Client.DispatchAsync(request, (r, err) => { if (r != null) { Debug.Console(1, this, "Status Response Code: {0}", r.Code); } });
}
catch (Exception e)

View File

@@ -216,7 +216,7 @@ namespace PepperDash.Essentials
/// </summary>
public void RunDefaultRoute()
{
if (DefaultSourceItem != null)
if (DefaultSourceItem != null && !OnFeedback.BoolValue)
RunRouteAction(DefaultSourceItem);
}