mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 12:44:58 +00:00
Relay warming, cooling and shutdown messages
This commit is contained in:
@@ -40,6 +40,12 @@ namespace PepperDash.Essentials
|
|||||||
Room.CurrentVolumeDeviceChange += new EventHandler<VolumeDeviceChangeEventArgs>(Room_CurrentVolumeDeviceChange);
|
Room.CurrentVolumeDeviceChange += new EventHandler<VolumeDeviceChangeEventArgs>(Room_CurrentVolumeDeviceChange);
|
||||||
|
|
||||||
Room.OnFeedback.OutputChange += new EventHandler<EventArgs>(OnFeedback_OutputChange);
|
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
|
// Registers for initial volume events, if possible
|
||||||
var currentVolumeDevice = Room.CurrentVolumeControls;
|
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)
|
void OnFeedback_OutputChange(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
/* Example message
|
/* Example message
|
||||||
|
|||||||
@@ -205,26 +205,26 @@ namespace PepperDash.Essentials
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(Client == null)
|
//if(Client == null)
|
||||||
Client = new HttpClient();
|
Client = new HttpClient();
|
||||||
Client.Verbose = true;
|
Client.Verbose = true;
|
||||||
Client.KeepAlive = 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
|
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); } });
|
Client.DispatchAsync(request, (r, err) => { if (r != null) { Debug.Console(1, this, "Status Response Code: {0}", r.Code); } });
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ namespace PepperDash.Essentials
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void RunDefaultRoute()
|
public void RunDefaultRoute()
|
||||||
{
|
{
|
||||||
if (DefaultSourceItem != null)
|
if (DefaultSourceItem != null && !OnFeedback.BoolValue)
|
||||||
RunRouteAction(DefaultSourceItem);
|
RunRouteAction(DefaultSourceItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user