mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-02 14:24:59 +00:00
UI Applications can now request status for specific feature sets instead of full status for a device. This will hopefully cut down on the traffic and messages required to get the data for the UI.
56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using System;
|
|
using Newtonsoft.Json;
|
|
using PepperDash.Core;
|
|
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
|
|
|
|
namespace PepperDash.Essentials.AppServer.Messengers
|
|
{
|
|
/// <summary>
|
|
/// Represents a IHumiditySensorMessenger
|
|
/// </summary>
|
|
public class IHumiditySensorMessenger : MessengerBase
|
|
{
|
|
private readonly IHumiditySensor device;
|
|
|
|
public IHumiditySensorMessenger(string key, IHumiditySensor device, string messagePath)
|
|
: base(key, messagePath, device as IKeyName)
|
|
{
|
|
this.device = device;
|
|
}
|
|
|
|
protected override void RegisterActions()
|
|
{
|
|
base.RegisterActions();
|
|
|
|
AddAction("/fullStatus", (id, content) => SendFullStatus(id));
|
|
|
|
AddAction("/humidityStatus", (id, content) => SendFullStatus(id));
|
|
|
|
device.HumidityFeedback.OutputChange += new EventHandler<Core.FeedbackEventArgs>((o, a) => SendFullStatus());
|
|
}
|
|
|
|
private void SendFullStatus(string id = null)
|
|
{
|
|
var state = new IHumiditySensorStateMessage
|
|
{
|
|
Humidity = string.Format("{0}%", device.HumidityFeedback.UShortValue)
|
|
};
|
|
|
|
PostStatusMessage(state, id);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represents a IHumiditySensorStateMessage
|
|
/// </summary>
|
|
public class IHumiditySensorStateMessage : DeviceStateMessageBase
|
|
{
|
|
|
|
/// <summary>
|
|
/// Gets or sets the Humidity
|
|
/// </summary>
|
|
[JsonProperty("humidity")]
|
|
public string Humidity { get; set; }
|
|
}
|
|
}
|