mirror of
https://github.com/excaliburpartners/OmniLinkBridge.git
synced 2025-04-19 21:07:20 +00:00
Compare commits
No commits in common. "master" and "1.1.17" have entirely different histories.
@ -44,11 +44,9 @@ namespace OmniLinkBridge
|
||||
|
||||
startTime = DateTime.Now;
|
||||
|
||||
Program.ShowSendLogsWarning();
|
||||
|
||||
using (LogContext.PushProperty("Telemetry", "Startup"))
|
||||
log.Information("Started version {Version} in {Environment} on {OperatingSystem} with {Modules}",
|
||||
Assembly.GetExecutingAssembly().GetName().Version, Program.GetEnvironment(), Environment.OSVersion, modules);
|
||||
log.Information("Started version {Version} on {OperatingSystem} with {Modules}",
|
||||
Assembly.GetExecutingAssembly().GetName().Version, Environment.OSVersion, modules);
|
||||
|
||||
// Startup modules
|
||||
foreach (IModule module in modules)
|
||||
|
@ -9,11 +9,6 @@ namespace OmniLinkBridge
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public static string Truncate(this string value, int maxLength)
|
||||
{
|
||||
return value?.Length > maxLength ? value.Substring(0, maxLength) : value;
|
||||
}
|
||||
|
||||
public static double ToCelsius(this double f)
|
||||
{
|
||||
// Convert to celsius
|
||||
|
@ -10,8 +10,6 @@ namespace OmniLinkBridge
|
||||
{
|
||||
public static bool DebugSettings { get; set; }
|
||||
public static bool UseEnvironment { get; set; }
|
||||
public static bool SendLogs { get; set; }
|
||||
public static Guid SessionID { get; } = Guid.NewGuid();
|
||||
|
||||
// HAI / Leviton Omni Controller
|
||||
public static string controller_address;
|
||||
@ -59,7 +57,7 @@ namespace OmniLinkBridge
|
||||
public static string mqtt_discovery_name_prefix;
|
||||
public static HashSet<int> mqtt_discovery_ignore_zones;
|
||||
public static HashSet<int> mqtt_discovery_ignore_units;
|
||||
public static ConcurrentDictionary<int, MQTT.OverrideArea> mqtt_discovery_override_area;
|
||||
public static HashSet<int> mqtt_discovery_area_code_required;
|
||||
public static ConcurrentDictionary<int, MQTT.OverrideZone> mqtt_discovery_override_zone;
|
||||
public static ConcurrentDictionary<int, MQTT.OverrideUnit> mqtt_discovery_override_unit;
|
||||
public static Type mqtt_discovery_button_type;
|
||||
|
@ -1,4 +1,9 @@
|
||||
using HAI_Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OmniLinkBridge.MQTT
|
||||
{
|
||||
@ -23,13 +28,7 @@ namespace OmniLinkBridge.MQTT
|
||||
}
|
||||
else if (supportValidate && payloads.Length == 3)
|
||||
{
|
||||
// Special case for Home Assistant when code not required
|
||||
if (string.Compare(payloads[1], "validate", true) == 0 &&
|
||||
string.Compare(payloads[2], "None", true) == 0)
|
||||
{
|
||||
ret.Success = true;
|
||||
}
|
||||
else if (string.Compare(payloads[1], "validate", true) == 0)
|
||||
if (string.Compare(payloads[1], "validate", true) == 0)
|
||||
{
|
||||
ret.Validate = true;
|
||||
ret.Success = int.TryParse(payloads[2], out code);
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OmniLinkBridge.MQTT.HomeAssistant
|
||||
{
|
||||
@ -17,14 +16,5 @@ namespace OmniLinkBridge.MQTT.HomeAssistant
|
||||
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string code { get; set; }
|
||||
|
||||
public bool code_arm_required { get; set; } = false;
|
||||
|
||||
public bool code_disarm_required { get; set; } = false;
|
||||
|
||||
public bool code_trigger_required { get; set; } = false;
|
||||
|
||||
public List<string> supported_features { get; set; } = new List<string>(new string[] {
|
||||
"arm_home", "arm_away", "arm_night", "arm_vacation" });
|
||||
}
|
||||
}
|
||||
|
@ -25,27 +25,10 @@ namespace OmniLinkBridge.MQTT
|
||||
|
||||
};
|
||||
|
||||
Global.mqtt_discovery_override_area.TryGetValue(area.Number, out OverrideArea override_area);
|
||||
|
||||
if (override_area != null)
|
||||
if(Global.mqtt_discovery_area_code_required.Contains(area.Number))
|
||||
{
|
||||
if(override_area.code_arm || override_area.code_disarm)
|
||||
{
|
||||
ret.command_template = "{{ action }},validate,{{ code }}";
|
||||
ret.code = "REMOTE_CODE";
|
||||
}
|
||||
ret.code_arm_required = override_area.code_arm;
|
||||
ret.code_disarm_required = override_area.code_disarm;
|
||||
|
||||
ret.supported_features.Clear();
|
||||
if (override_area.arm_home)
|
||||
ret.supported_features.Add("arm_home");
|
||||
if (override_area.arm_away)
|
||||
ret.supported_features.Add("arm_away");
|
||||
if (override_area.arm_night)
|
||||
ret.supported_features.Add("arm_night");
|
||||
if (override_area.arm_vacation)
|
||||
ret.supported_features.Add("arm_vacation");
|
||||
ret.command_template = "{{ action }},validate,{{ code }}";
|
||||
ret.code = "REMOTE_CODE";
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -1,19 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OmniLinkBridge.MQTT
|
||||
{
|
||||
public class OverrideArea
|
||||
{
|
||||
public bool code_arm { get; set; }
|
||||
|
||||
public bool code_disarm { get; set; }
|
||||
|
||||
public bool arm_home { get; set; } = true;
|
||||
|
||||
public bool arm_away { get; set; } = true;
|
||||
|
||||
public bool arm_night { get; set; } = true;
|
||||
|
||||
public bool arm_vacation { get; set; } = true;
|
||||
}
|
||||
}
|
@ -402,9 +402,6 @@ namespace OmniLinkBridge.Modules
|
||||
{
|
||||
log.Debug("Publishing {type}", "buttons");
|
||||
|
||||
if (Global.mqtt_discovery_button_type == typeof(Switch))
|
||||
log.Information("See {setting} for new option when publishing {type}", "mqtt_discovery_button_type", "buttons");
|
||||
|
||||
for (ushort i = 1; i <= OmniLink.Controller.Buttons.Count; i++)
|
||||
{
|
||||
clsButton button = OmniLink.Controller.Buttons[i];
|
||||
@ -424,6 +421,8 @@ namespace OmniLinkBridge.Modules
|
||||
|
||||
if (Global.mqtt_discovery_button_type == typeof(Switch))
|
||||
{
|
||||
log.Information("See {setting} for new option when publishing {type}", "mqtt_discovery_button_type", "buttons");
|
||||
|
||||
PublishAsync($"{Global.mqtt_discovery_prefix}/button/{Global.mqtt_prefix}/button{i}/config", null);
|
||||
PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/button{i}/config",
|
||||
JsonConvert.SerializeObject(button.ToConfigSwitch()));
|
||||
|
@ -201,8 +201,6 @@ namespace OmniLinkBridge.Modules
|
||||
tstat_timer.Start();
|
||||
|
||||
OnConnect?.Invoke(this, new EventArgs());
|
||||
|
||||
Program.ShowSendLogsWarning();
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -233,8 +231,7 @@ namespace OmniLinkBridge.Modules
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
if(!nameWait.WaitOne(new TimeSpan(0, 0, 10)))
|
||||
log.Error("Timeout occurred waiting system formats");
|
||||
nameWait.WaitOne(new TimeSpan(0, 0, 10));
|
||||
});
|
||||
}
|
||||
|
||||
@ -247,8 +244,7 @@ namespace OmniLinkBridge.Modules
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
if(!nameWait.WaitOne(new TimeSpan(0, 0, 10)))
|
||||
log.Error("Timeout occurred waiting for system troubles");
|
||||
nameWait.WaitOne(new TimeSpan(0, 0, 10));
|
||||
});
|
||||
}
|
||||
|
||||
@ -260,8 +256,7 @@ namespace OmniLinkBridge.Modules
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
if (!nameWait.WaitOne(new TimeSpan(0, 0, 30)))
|
||||
log.Error("Timeout occurred waiting for named units {unitType}", type.ToString());
|
||||
nameWait.WaitOne(new TimeSpan(0, 0, 10));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,6 @@
|
||||
<Compile Include="MQTT\HomeAssistant\Alarm.cs" />
|
||||
<Compile Include="MQTT\HomeAssistant\Lock.cs" />
|
||||
<Compile Include="MQTT\HomeAssistant\Select.cs" />
|
||||
<Compile Include="MQTT\OverrideArea.cs" />
|
||||
<Compile Include="MQTT\OverrideUnit.cs" />
|
||||
<Compile Include="MQTT\Parser\AlarmCommands.cs" />
|
||||
<Compile Include="MQTT\AreaCommandCode.cs" />
|
||||
|
@ -55,31 +55,20 @@ mqtt_discovery_name_prefix =
|
||||
# Specify a range of numbers 1,2,3,5-10
|
||||
mqtt_discovery_ignore_zones =
|
||||
mqtt_discovery_ignore_units =
|
||||
|
||||
# Override the area Home Assistant alarm control panel
|
||||
# Prompt for user code
|
||||
# code_arm: true or false, defaults to false
|
||||
# code_disarm: true or false, defaults to false
|
||||
# Show these modes
|
||||
# arm_home: true or false, defaults to true
|
||||
# arm_away: true or false, defaults to true
|
||||
# arm_night: true or false, defaults to true
|
||||
# arm_vacation: true or false, defaults to true
|
||||
#mqtt_discovery_override_area = id=1;code_disarm=true;arm_vacation=false
|
||||
|
||||
# Require Home Assistant to prompt for user code when arming/disarming area
|
||||
# Specify a range of numbers 1,2,3,5-10
|
||||
mqtt_discovery_area_code_required =
|
||||
# Override the zone Home Assistant binary sensor device_class
|
||||
# device_class: must be battery, cold, door, garage_door, gas,
|
||||
# heat, moisture, motion, problem, safety, smoke, or window
|
||||
#mqtt_discovery_override_zone = id=5;device_class=garage_door
|
||||
#mqtt_discovery_override_zone = id=6;device_class=garage_door
|
||||
|
||||
# Override the unit Home Assistant device type
|
||||
# type:
|
||||
# Units (LTe 1-32, IIe 1-64, Pro 1-256) light or switch, defaults to light
|
||||
# Flags (LTe 41-88, IIe 73-128, Pro 393-511) switch or number, defaults to switch
|
||||
#mqtt_discovery_override_unit = id=1;type=switch
|
||||
#mqtt_discovery_override_unit = id=395;type=number
|
||||
|
||||
# Publish buttons as this Home Assistant device type
|
||||
# must be button (recommended) or switch (default, previous behavior)
|
||||
mqtt_discovery_button_type = switch
|
||||
|
@ -4,9 +4,7 @@ using Serilog.Events;
|
||||
using Serilog.Filters;
|
||||
using Serilog.Formatting.Compact;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.ServiceProcess;
|
||||
@ -14,11 +12,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace OmniLinkBridge
|
||||
{
|
||||
internal class Program
|
||||
class Program
|
||||
{
|
||||
private static CoreServer server;
|
||||
static CoreServer server;
|
||||
|
||||
private static int Main(string[] args)
|
||||
static int Main(string[] args)
|
||||
{
|
||||
bool interactive = false;
|
||||
|
||||
@ -57,10 +55,6 @@ namespace OmniLinkBridge
|
||||
case "-ll":
|
||||
Enum.TryParse(args[++i], out log_level);
|
||||
break;
|
||||
case "-ld":
|
||||
Global.DebugSettings = true;
|
||||
Global.SendLogs = true;
|
||||
break;
|
||||
case "-s":
|
||||
Global.webapi_subscriptions_file = args[++i];
|
||||
break;
|
||||
@ -70,12 +64,6 @@ namespace OmniLinkBridge
|
||||
}
|
||||
}
|
||||
|
||||
if (string.Compare(Environment.GetEnvironmentVariable("SEND_LOGS"), "1") == 0)
|
||||
{
|
||||
Global.DebugSettings = true;
|
||||
Global.SendLogs = true;
|
||||
}
|
||||
|
||||
config_file = GetFullPath(config_file);
|
||||
|
||||
Global.webapi_subscriptions_file = GetFullPath(Global.webapi_subscriptions_file ?? "WebSubscriptions.json");
|
||||
@ -88,7 +76,7 @@ namespace OmniLinkBridge
|
||||
var log_config = new LoggerConfiguration()
|
||||
.MinimumLevel.Verbose()
|
||||
.Enrich.WithProperty("Application", "OmniLinkBridge")
|
||||
.Enrich.WithProperty("Session", Global.SessionID)
|
||||
.Enrich.WithProperty("Session", Guid.NewGuid())
|
||||
.Enrich.With<ControllerEnricher>()
|
||||
.Enrich.FromLogContext();
|
||||
|
||||
@ -104,10 +92,7 @@ namespace OmniLinkBridge
|
||||
rollingInterval: RollingInterval.Day, retainedFileCountLimit: 15));
|
||||
}
|
||||
|
||||
if (Global.SendLogs)
|
||||
log_config = log_config.WriteTo.Logger(lc => lc
|
||||
.WriteTo.Http("https://telemetry.excalibur-partners.com"));
|
||||
else if (UseTelemetry())
|
||||
if (UseTelemetry())
|
||||
log_config = log_config.WriteTo.Logger(lc => lc
|
||||
.Filter.ByIncludingOnly(Matching.WithProperty("Telemetry"))
|
||||
.WriteTo.Http("https://telemetry.excalibur-partners.com"));
|
||||
@ -170,7 +155,7 @@ namespace OmniLinkBridge
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static string GetFullPath(string file)
|
||||
static string GetFullPath(string file)
|
||||
{
|
||||
if (Path.IsPathRooted(file))
|
||||
return file;
|
||||
@ -184,38 +169,21 @@ namespace OmniLinkBridge
|
||||
args.Cancel = true;
|
||||
}
|
||||
|
||||
private static bool IsRunningOnMono()
|
||||
static bool IsRunningOnMono()
|
||||
{
|
||||
return Type.GetType("Mono.Runtime") != null;
|
||||
}
|
||||
|
||||
public static string GetEnvironment()
|
||||
{
|
||||
if (Environment.GetEnvironmentVariable("HASSIO_TOKEN") != null)
|
||||
return "Home Assistant";
|
||||
else if (IsRunningOnMono())
|
||||
return Process.GetProcesses().Any(w => w.Id == 2) ? "Mono" : "Docker";
|
||||
else
|
||||
return "Native";
|
||||
}
|
||||
|
||||
private static bool UseTelemetry()
|
||||
static bool UseTelemetry()
|
||||
{
|
||||
return string.Compare(Environment.GetEnvironmentVariable("TELEMETRY_OPTOUT"), "1") != 0;
|
||||
}
|
||||
|
||||
public static void ShowSendLogsWarning()
|
||||
{
|
||||
if (Global.SendLogs)
|
||||
Log.Warning("SENDING LOGS TO DEVELOPER Controller: {ControllerID}, Session: {Session}",
|
||||
Global.controller_id, Global.SessionID);
|
||||
}
|
||||
|
||||
private static void ShowHelp()
|
||||
static void ShowHelp()
|
||||
{
|
||||
Console.WriteLine(
|
||||
AppDomain.CurrentDomain.FriendlyName + " [-c config_file] [-e] [-d] [-j] [-s subscriptions_file]\n" +
|
||||
"\t[-lf log_file|disable] [-lj [-ll verbose|debug|information|warning|error] [-ld] [-i]\n" +
|
||||
"\t[-lf log_file|disable] [-lj [-ll verbose|debug|information|warning|error] [-i]\n" +
|
||||
"\t-c Specifies the configuration file. Default is OmniLinkBridge.ini\n" +
|
||||
"\t-e Check environment variables for configuration settings\n" +
|
||||
"\t-d Show debug ouput for configuration loading\n" +
|
||||
@ -223,14 +191,8 @@ namespace OmniLinkBridge
|
||||
"\t-lf Specifies the rolling log file. Retention is 15 days. Default is log.txt.\n" +
|
||||
"\t-lj Write logs as CLEF (compact log event format) JSON.\n" +
|
||||
"\t-ll Minimum level at which events will be logged. Default is information.\n" +
|
||||
"\t-ld Send logs to developer. ONLY USE WHEN ASKED.\n" +
|
||||
"\t Also enabled by setting a SEND_LOGS environment variable to 1.\n" +
|
||||
"\t-i Run in interactive mode");
|
||||
|
||||
Console.WriteLine(
|
||||
"\nVersion: " + Assembly.GetExecutingAssembly().GetName().Version +
|
||||
"\nEnvironment: " + GetEnvironment());
|
||||
|
||||
Console.WriteLine(
|
||||
"\nOmniLink Bridge collects anonymous telemetry data to help improve the software.\n" +
|
||||
"You can opt of telemetry by setting a TELEMETRY_OPTOUT environment variable to 1.");
|
||||
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.19.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.19.0")]
|
||||
[assembly: AssemblyVersion("1.1.17.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.17.0")]
|
||||
|
@ -59,7 +59,7 @@ namespace OmniLinkBridge
|
||||
|
||||
// mySQL Logging
|
||||
Global.mysql_logging = settings.ValidateBool("mysql_logging");
|
||||
Global.mysql_connection = settings.CheckEnv("mysql_connection", true);
|
||||
Global.mysql_connection = settings.CheckEnv("mysql_connection");
|
||||
|
||||
// Web Service
|
||||
Global.webapi_enabled = settings.ValidateBool("webapi_enabled");
|
||||
@ -77,8 +77,8 @@ namespace OmniLinkBridge
|
||||
{
|
||||
Global.mqtt_server = settings.CheckEnv("mqtt_server");
|
||||
Global.mqtt_port = settings.ValidatePort("mqtt_port");
|
||||
Global.mqtt_username = settings.CheckEnv("mqtt_username", true);
|
||||
Global.mqtt_password = settings.CheckEnv("mqtt_password", true);
|
||||
Global.mqtt_username = settings.CheckEnv("mqtt_username");
|
||||
Global.mqtt_password = settings.CheckEnv("mqtt_password");
|
||||
Global.mqtt_prefix = settings.CheckEnv("mqtt_prefix") ?? "omnilink";
|
||||
Global.mqtt_discovery_prefix = settings.CheckEnv("mqtt_discovery_prefix") ?? "homeassistant";
|
||||
Global.mqtt_discovery_name_prefix = settings.CheckEnv("mqtt_discovery_name_prefix") ?? string.Empty;
|
||||
@ -88,7 +88,7 @@ namespace OmniLinkBridge
|
||||
|
||||
Global.mqtt_discovery_ignore_zones = settings.ValidateRange("mqtt_discovery_ignore_zones");
|
||||
Global.mqtt_discovery_ignore_units = settings.ValidateRange("mqtt_discovery_ignore_units");
|
||||
Global.mqtt_discovery_override_area = settings.LoadOverrideArea<MQTT.OverrideArea>("mqtt_discovery_override_area");
|
||||
Global.mqtt_discovery_area_code_required = settings.ValidateRange("mqtt_discovery_area_code_required");
|
||||
Global.mqtt_discovery_override_zone = settings.LoadOverrideZone<MQTT.OverrideZone>("mqtt_discovery_override_zone");
|
||||
Global.mqtt_discovery_override_unit = settings.LoadOverrideUnit<MQTT.OverrideUnit>("mqtt_discovery_override_unit");
|
||||
Global.mqtt_discovery_button_type = settings.ValidateType("mqtt_discovery_button_type", typeof(Switch), typeof(Button));
|
||||
@ -107,113 +107,31 @@ namespace OmniLinkBridge
|
||||
{
|
||||
Global.mail_tls = settings.ValidateBool("mail_tls");
|
||||
Global.mail_port = settings.ValidatePort("mail_port");
|
||||
Global.mail_username = settings.CheckEnv("mail_username", true);
|
||||
Global.mail_password = settings.CheckEnv("mail_password", true);
|
||||
Global.mail_username = settings.CheckEnv("mail_username");
|
||||
Global.mail_password = settings.CheckEnv("mail_password");
|
||||
Global.mail_from = settings.ValidateMailFrom("mail_from");
|
||||
Global.mail_to = settings.ValidateMailTo("mail_to");
|
||||
}
|
||||
|
||||
// Prowl Notifications
|
||||
Global.prowl_key = settings.ValidateMultipleStrings("prowl_key", true);
|
||||
Global.prowl_key = settings.ValidateMultipleStrings("prowl_key");
|
||||
|
||||
// Pushover Notifications
|
||||
Global.pushover_token = settings.CheckEnv("pushover_token", true);
|
||||
Global.pushover_user = settings.ValidateMultipleStrings("pushover_user", true);
|
||||
Global.pushover_token = settings.CheckEnv("pushover_token");
|
||||
Global.pushover_user = settings.ValidateMultipleStrings("pushover_user");
|
||||
}
|
||||
|
||||
private static string CheckEnv(this NameValueCollection settings, string name, bool sensitive = false)
|
||||
private static string CheckEnv(this NameValueCollection settings, string name)
|
||||
{
|
||||
string env = Global.UseEnvironment ? Environment.GetEnvironmentVariable(name.ToUpper()) : null;
|
||||
string value = !string.IsNullOrEmpty(env) ? env : settings[name];
|
||||
|
||||
if (Global.DebugSettings)
|
||||
log.Debug("{ConfigType} {ConfigName}: {ConfigValue}",
|
||||
(!string.IsNullOrEmpty(env) ? "ENV" : "CONF").PadRight(4), name,
|
||||
sensitive && value != null ? value.Truncate(3) + "***MASKED***" : value);
|
||||
log.Debug((!string.IsNullOrEmpty(env) ? "ENV" : "CONF").PadRight(5) + $"{name}: {value}");
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private static ConcurrentDictionary<int, T> LoadOverrideArea<T>(this NameValueCollection settings, string section) where T : new()
|
||||
{
|
||||
try
|
||||
{
|
||||
ConcurrentDictionary<int, T> ret = new ConcurrentDictionary<int, T>();
|
||||
|
||||
string value = settings.CheckEnv(section);
|
||||
|
||||
if (string.IsNullOrEmpty(value))
|
||||
return ret;
|
||||
|
||||
string[] ids = value.Split(',');
|
||||
|
||||
for (int i = 0; i < ids.Length; i++)
|
||||
{
|
||||
Dictionary<string, string> attributes = ids[i].TrimEnd(new char[] { ';' }).Split(';')
|
||||
.Select(s => s.Split('='))
|
||||
.ToDictionary(a => a[0].Trim(), a => a[1].Trim(), StringComparer.InvariantCultureIgnoreCase);
|
||||
|
||||
if (!attributes.ContainsKey("id") || !int.TryParse(attributes["id"], out int attrib_id))
|
||||
throw new Exception("Missing or invalid id attribute");
|
||||
|
||||
T override_area = new T();
|
||||
|
||||
if (override_area is MQTT.OverrideArea mqtt_area)
|
||||
{
|
||||
foreach (string attribute in attributes.Keys)
|
||||
{
|
||||
switch(attribute)
|
||||
{
|
||||
case "id":
|
||||
continue;
|
||||
case "code_arm":
|
||||
if (!bool.TryParse(attributes["code_arm"], out bool code_arm))
|
||||
throw new Exception("Invalid code_arm attribute");
|
||||
mqtt_area.code_arm = code_arm;
|
||||
break;
|
||||
case "code_disarm":
|
||||
if (!bool.TryParse(attributes["code_disarm"], out bool code_disarm))
|
||||
throw new Exception("Invalid code_disarm attribute");
|
||||
mqtt_area.code_disarm = code_disarm;
|
||||
break;
|
||||
case "arm_home":
|
||||
if (!bool.TryParse(attributes["arm_home"], out bool arm_home))
|
||||
throw new Exception("Invalid arm_home attribute");
|
||||
mqtt_area.arm_home = arm_home;
|
||||
break;
|
||||
case "arm_away":
|
||||
if (!bool.TryParse(attributes["arm_away"], out bool arm_away))
|
||||
throw new Exception("Invalid arm_away attribute");
|
||||
mqtt_area.arm_away = arm_away;
|
||||
break;
|
||||
case "arm_night":
|
||||
if (!bool.TryParse(attributes["arm_night"], out bool arm_night))
|
||||
throw new Exception("Invalid arm_night attribute");
|
||||
mqtt_area.arm_night = arm_night;
|
||||
break;
|
||||
case "arm_vacation":
|
||||
if (!bool.TryParse(attributes["arm_vacation"], out bool arm_vacation))
|
||||
throw new Exception("Invalid arm_vacation attribute");
|
||||
mqtt_area.arm_vacation = arm_vacation;
|
||||
break;
|
||||
default:
|
||||
throw new Exception($"Unknown attribute {attribute}" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret.TryAdd(attrib_id, override_area);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error(ex, "Invalid override area specified for {section}", section);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private static ConcurrentDictionary<int, T> LoadOverrideZone<T>(this NameValueCollection settings, string section) where T : new()
|
||||
{
|
||||
try
|
||||
@ -324,7 +242,7 @@ namespace OmniLinkBridge
|
||||
|
||||
private static string ValidateEncryptionKey(this NameValueCollection settings, string section)
|
||||
{
|
||||
string value = settings.CheckEnv(section, true).Replace("-","");
|
||||
string value = settings.CheckEnv(section).Replace("-","");
|
||||
|
||||
if (string.IsNullOrEmpty(value) || value.Length != 16)
|
||||
{
|
||||
@ -421,14 +339,14 @@ namespace OmniLinkBridge
|
||||
}
|
||||
}
|
||||
|
||||
private static string[] ValidateMultipleStrings(this NameValueCollection settings, string section, bool sensitive = false)
|
||||
private static string[] ValidateMultipleStrings(this NameValueCollection settings, string section)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (settings.CheckEnv(section, true) == null)
|
||||
if (settings.CheckEnv(section) == null)
|
||||
return new string[] { };
|
||||
|
||||
return settings.CheckEnv(section, sensitive).Split(',');
|
||||
return settings.CheckEnv(section).Split(',');
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -1,4 +1,10 @@
|
||||
namespace OmniLinkBridge.WebAPI
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OmniLinkBridge.WebAPI
|
||||
{
|
||||
public enum DeviceType
|
||||
{
|
||||
|
@ -1,4 +1,9 @@
|
||||
using HAI_Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OmniLinkBridge.WebAPI
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
using HAI_Shared;
|
||||
using OmniLinkBridge.WebAPI;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -1,4 +1,10 @@
|
||||
namespace OmniLinkBridge.WebAPI
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OmniLinkBridge.WebAPI
|
||||
{
|
||||
public class OverrideZone
|
||||
{
|
||||
|
@ -64,14 +64,6 @@ namespace OmniLinkBridgeTest
|
||||
Assert.AreEqual(parser.Validate, true);
|
||||
Assert.AreEqual(parser.Code, 1234);
|
||||
|
||||
// Special case for Home Assistant when code not required
|
||||
payload = "disarm,validate,None";
|
||||
parser = payload.ToCommandCode(supportValidate: true);
|
||||
Assert.AreEqual(parser.Success, true);
|
||||
Assert.AreEqual(parser.Command, "disarm");
|
||||
Assert.AreEqual(parser.Validate, false);
|
||||
Assert.AreEqual(parser.Code, 0);
|
||||
|
||||
// Falures
|
||||
payload = "disarm,1a";
|
||||
parser = payload.ToCommandCode(supportValidate: true);
|
||||
|
@ -157,8 +157,7 @@ namespace OmniLinkBridgeTest
|
||||
"mqtt_discovery_name_prefix = mynameprefix",
|
||||
"mqtt_discovery_ignore_zones = 1,2-3,4",
|
||||
"mqtt_discovery_ignore_units = 2-5,7",
|
||||
"mqtt_discovery_override_area = id=1",
|
||||
"mqtt_discovery_override_area = id=2;code_arm=true;code_disarm=true;arm_home=false;arm_away=false;arm_night=false;arm_vacation=false",
|
||||
"mqtt_discovery_area_code_required = 1",
|
||||
"mqtt_discovery_override_zone = id=5;device_class=garage_door",
|
||||
"mqtt_discovery_override_zone = id=7;device_class=motion",
|
||||
"mqtt_discovery_override_unit = id=1;type=switch",
|
||||
@ -172,25 +171,7 @@ namespace OmniLinkBridgeTest
|
||||
Assert.AreEqual("mynameprefix ", Global.mqtt_discovery_name_prefix);
|
||||
Assert.IsTrue(Global.mqtt_discovery_ignore_zones.SetEquals(new int[] { 1, 2, 3, 4 }));
|
||||
Assert.IsTrue(Global.mqtt_discovery_ignore_units.SetEquals(new int[] { 2, 3, 4, 5, 7 }));
|
||||
|
||||
Dictionary<int, OmniLinkBridge.MQTT.OverrideArea> override_area = new Dictionary<int, OmniLinkBridge.MQTT.OverrideArea>()
|
||||
{
|
||||
{ 1, new OmniLinkBridge.MQTT.OverrideArea { }},
|
||||
{ 2, new OmniLinkBridge.MQTT.OverrideArea { code_arm = true, code_disarm = true,
|
||||
arm_home = false, arm_away = false, arm_night = false, arm_vacation = false }},
|
||||
};
|
||||
|
||||
Assert.AreEqual(override_area.Count, Global.mqtt_discovery_override_area.Count);
|
||||
foreach (KeyValuePair<int, OmniLinkBridge.MQTT.OverrideArea> pair in override_area)
|
||||
{
|
||||
Global.mqtt_discovery_override_area.TryGetValue(pair.Key, out OmniLinkBridge.MQTT.OverrideArea value);
|
||||
Assert.AreEqual(override_area[pair.Key].code_arm, value.code_arm);
|
||||
Assert.AreEqual(override_area[pair.Key].code_disarm, value.code_disarm);
|
||||
Assert.AreEqual(override_area[pair.Key].arm_home, value.arm_home);
|
||||
Assert.AreEqual(override_area[pair.Key].arm_away, value.arm_away);
|
||||
Assert.AreEqual(override_area[pair.Key].arm_night, value.arm_night);
|
||||
Assert.AreEqual(override_area[pair.Key].arm_vacation, value.arm_vacation);
|
||||
}
|
||||
Assert.IsTrue(Global.mqtt_discovery_area_code_required.SetEquals(new int[] { 1 }));
|
||||
|
||||
Dictionary<int, OmniLinkBridge.MQTT.OverrideZone> override_zone = new Dictionary<int, OmniLinkBridge.MQTT.OverrideZone>()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user