refactor: rearrange and add solution for 4-series

This commit is contained in:
Andrew Welker
2023-02-07 15:45:01 -07:00
parent 7a9f76ee12
commit 0d515e5f0a
649 changed files with 45907 additions and 105752 deletions

View File

@@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
namespace PepperDash.Essentials.Core.Shades
{
/// <summary>
/// Requirements for an object that contains shades
/// </summary>
public interface IShades
{
List<ShadeBase> Shades { get; }
}
/// <summary>
/// Requirements for a device that implements basic Open/Close shade control
/// </summary>
[Obsolete("Please use IShadesOpenCloseStop instead")]
public interface IShadesOpenClose
{
void Open();
void Close();
}
/// <summary>
/// Requirements for a device that implements basic Open/Close/Stop shade control (Uses 3 relays)
/// </summary>
public interface IShadesOpenCloseStop
{
void Open();
void Close();
void Stop();
}
public interface IShadesOpenClosePreset : IShadesOpenCloseStop
{
void RecallPreset(uint presetNumber);
void SavePreset(uint presetNumber);
string StopOrPresetButtonLabel { get; }
event EventHandler PresetSaved;
}
/// <summary>
/// Requirements for a shade that implements press/hold raise/lower functions
/// </summary>
[Obsolete("Please use IShadesOpenCloseStop instead")]
public interface IShadesRaiseLower
{
void Raise(bool state);
void Lower(bool state);
}
/// <summary>
/// Requirements for a shade device that provides raising/lowering feedback
/// </summary>
public interface IShadesRaiseLowerFeedback
{
BoolFeedback ShadeIsLoweringFeedback { get; }
BoolFeedback ShadeIsRaisingFeedback { get; }
}
/// <summary>
/// Requirements for a shade/scene that is open or closed
/// </summary>
public interface IShadesOpenClosedFeedback: IShadesOpenCloseStop
{
BoolFeedback ShadeIsOpenFeedback { get; }
BoolFeedback ShadeIsClosedFeedback { get; }
}
/// <summary>
///
/// </summary>
[Obsolete("Please use IShadesOpenCloseStop instead")]
public interface IShadesStop
{
void Stop();
}
/// <summary>
/// Used to implement raise/stop/lower/stop from single button
/// </summary>
public interface IShadesStopOrMove
{
void OpenOrStop();
void CloseOrStop();
void OpenCloseOrStop();
}
/// <summary>
/// Basic feedback for shades/scene stopped
/// </summary>
public interface IShadesStopFeedback : IShadesOpenCloseStop
{
BoolFeedback IsStoppedFeedback { get; }
}
/// <summary>
/// Requirements for position
/// </summary>
public interface IShadesPosition
{
void SetPosition(ushort value);
}
/// <summary>
/// Basic feedback for shades position
/// </summary>
public interface IShadesFeedback: IShadesPosition, IShadesStopFeedback
{
IntFeedback PositionFeedback { get; }
}
/// <summary>
///
/// </summary>
public interface ISceneFeedback
{
void Run();
BoolFeedback AllAreAtSceneFeedback { get; }
}
public interface ICrestronBasicShade : IShadesOpenClosedFeedback, IShadesStop,
IShadesStopOrMove, IShadesFeedback, IShadesRaiseLowerFeedback
{
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Essentials.Core.CrestronIO;
namespace PepperDash.Essentials.Core.Shades
{
/// <summary>
/// Base class for a shade device
/// </summary>
public abstract class ShadeBase : EssentialsDevice, IShadesOpenCloseStop
{
public ShadeBase(string key, string name)
: base(key, name)
{
}
#region iShadesOpenClose Members
public abstract void Open();
public abstract void Stop();
public abstract void Close();
#endregion
}
}

View File

@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
namespace PepperDash.Essentials.Core.Shades
{
/// <summary>
/// Class that contains the shades to be controlled in a room
/// </summary>
public class ShadeController : EssentialsDevice, IShades
{
ShadeControllerConfigProperties Config;
public List<ShadeBase> Shades { get; private set; }
public ShadeController(string key, string name, ShadeControllerConfigProperties config)
: base(key, name)
{
Config = config;
Shades = new List<ShadeBase>();
}
public override bool CustomActivate()
{
foreach (var shadeConfig in Config.Shades)
{
var shade = DeviceManager.GetDeviceForKey(shadeConfig.Key) as ShadeBase;
if (shade != null)
{
AddShade(shade);
}
}
return base.CustomActivate();
}
void AddShade(ShadeBase shade)
{
Shades.Add(shade);
}
}
public class ShadeControllerConfigProperties
{
public List<ShadeConfig> Shades { get; set; }
public class ShadeConfig
{
public string Key { get; set; }
}
}
public class ShadeControllerFactory : EssentialsDeviceFactory<ShadeController>
{
public ShadeControllerFactory()
{
TypeNames = new List<string>() { "shadecontroller" };
}
public override EssentialsDevice BuildDevice(DeviceConfig dc)
{
Debug.Console(1, "Factory Attempting to create new ShadeController Device");
var props = Newtonsoft.Json.JsonConvert.DeserializeObject<Core.Shades.ShadeControllerConfigProperties>(dc.Properties.ToString());
return new Core.Shades.ShadeController(dc.Key, dc.Name, props);
}
}
}