mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-12 03:05:01 +00:00
feat: move MC into Essentials
In order to solve some dependency issues that keep cropping up, MC should be moved back into the Essentials repo and loaded automatically on startup. This will allow for all plugins that use the MC Messengers library to use the same version without fear of overwriting a dll due to loading of plugin libraries.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Essentials.AppServer.Messengers
|
||||
{
|
||||
public class ITemperatureSensorMessenger : MessengerBase
|
||||
{
|
||||
private readonly ITemperatureSensor device;
|
||||
|
||||
public ITemperatureSensorMessenger(string key, ITemperatureSensor device, string messagePath)
|
||||
: base(key, messagePath, device as Device)
|
||||
{
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
protected override void RegisterActions()
|
||||
{
|
||||
base.RegisterActions();
|
||||
|
||||
AddAction("/fullStatus", (id, content) => SendFullStatus());
|
||||
|
||||
AddAction("/setTemperatureUnitsToCelcius", (id, content) =>
|
||||
{
|
||||
device.SetTemperatureFormat(true);
|
||||
});
|
||||
|
||||
AddAction("/setTemperatureUnitsToFahrenheit", (id, content) =>
|
||||
{
|
||||
device.SetTemperatureFormat(false);
|
||||
});
|
||||
|
||||
device.TemperatureFeedback.OutputChange += new EventHandler<Core.FeedbackEventArgs>((o, a) => SendFullStatus());
|
||||
device.TemperatureInCFeedback.OutputChange += new EventHandler<Core.FeedbackEventArgs>((o, a) => SendFullStatus());
|
||||
}
|
||||
|
||||
private void SendFullStatus()
|
||||
{
|
||||
// format the temperature to a string with one decimal place
|
||||
var tempString = string.Format("{0}.{1}", device.TemperatureFeedback.UShortValue / 10, device.TemperatureFeedback.UShortValue % 10);
|
||||
|
||||
var state = new ITemperatureSensorStateMessage
|
||||
{
|
||||
Temperature = tempString,
|
||||
TemperatureInCelsius = device.TemperatureInCFeedback.BoolValue
|
||||
};
|
||||
|
||||
PostStatusMessage(state);
|
||||
}
|
||||
}
|
||||
|
||||
public class ITemperatureSensorStateMessage : DeviceStateMessageBase
|
||||
{
|
||||
[JsonProperty("temperature")]
|
||||
public string Temperature { get; set; }
|
||||
|
||||
[JsonProperty("temperatureInCelsius")]
|
||||
public bool TemperatureInCelsius { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user