mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-12 11:15:08 +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,105 @@
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
|
||||
using PepperDash.Essentials.Core.Shades;
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Essentials.AppServer.Messengers
|
||||
{
|
||||
public class IShadesOpenCloseStopMessenger : MessengerBase
|
||||
{
|
||||
private readonly IShadesOpenCloseStop device;
|
||||
|
||||
public IShadesOpenCloseStopMessenger(string key, IShadesOpenCloseStop shades, string messagePath)
|
||||
: base(key, messagePath, shades as Device)
|
||||
{
|
||||
device = shades;
|
||||
}
|
||||
|
||||
#if SERIES4
|
||||
protected override void RegisterActions()
|
||||
#else
|
||||
protected override void CustomRegisterWithAppServer(MobileControlSystemController appServerController)
|
||||
#endif
|
||||
{
|
||||
base.RegisterActions();
|
||||
|
||||
AddAction("/fullStatus", (id, content) => SendFullStatus());
|
||||
|
||||
AddAction("/shadeUp", (id, content) =>
|
||||
{
|
||||
|
||||
device.Open();
|
||||
|
||||
});
|
||||
|
||||
AddAction("/shadeDown", (id, content) =>
|
||||
{
|
||||
|
||||
device.Close();
|
||||
|
||||
});
|
||||
|
||||
var stopDevice = device;
|
||||
if (stopDevice != null)
|
||||
{
|
||||
AddAction("/stopOrPreset", (id, content) =>
|
||||
{
|
||||
stopDevice.Stop();
|
||||
});
|
||||
}
|
||||
|
||||
if (device is IShadesOpenClosedFeedback feedbackDevice)
|
||||
{
|
||||
feedbackDevice.ShadeIsOpenFeedback.OutputChange += new EventHandler<Core.FeedbackEventArgs>(ShadeIsOpenFeedback_OutputChange);
|
||||
feedbackDevice.ShadeIsClosedFeedback.OutputChange += new EventHandler<Core.FeedbackEventArgs>(ShadeIsClosedFeedback_OutputChange);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShadeIsOpenFeedback_OutputChange(object sender, Core.FeedbackEventArgs e)
|
||||
{
|
||||
var state = new ShadeBaseStateMessage
|
||||
{
|
||||
IsOpen = e.BoolValue
|
||||
};
|
||||
|
||||
PostStatusMessage(state);
|
||||
}
|
||||
|
||||
private void ShadeIsClosedFeedback_OutputChange(object sender, Core.FeedbackEventArgs e)
|
||||
{
|
||||
var state = new ShadeBaseStateMessage
|
||||
{
|
||||
IsClosed = e.BoolValue
|
||||
};
|
||||
|
||||
PostStatusMessage(state);
|
||||
}
|
||||
|
||||
|
||||
private void SendFullStatus()
|
||||
{
|
||||
var state = new ShadeBaseStateMessage();
|
||||
|
||||
if (device is IShadesOpenClosedFeedback feedbackDevice)
|
||||
{
|
||||
state.IsOpen = feedbackDevice.ShadeIsOpenFeedback.BoolValue;
|
||||
state.IsClosed = feedbackDevice.ShadeIsClosedFeedback.BoolValue;
|
||||
}
|
||||
|
||||
PostStatusMessage(state);
|
||||
}
|
||||
}
|
||||
|
||||
public class ShadeBaseStateMessage : DeviceStateMessageBase
|
||||
{
|
||||
[JsonProperty("middleButtonLabel", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string MiddleButtonLabel { get; set; }
|
||||
|
||||
[JsonProperty("isOpen", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public bool? IsOpen { get; set; }
|
||||
|
||||
[JsonProperty("isClosed", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public bool? IsClosed { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user