Skip to content

Commit

Permalink
1.1.15 - Add notice for deprecated modules and update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
rwagoner committed Apr 13, 2024
1 parent 84b52c8 commit 800242a
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 14 deletions.
16 changes: 16 additions & 0 deletions OmniLinkBridge/ControllerEnricher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Serilog.Core;
using Serilog.Events;

namespace OmniLinkBridge
{
public class ControllerEnricher : ILogEventEnricher
{
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if(Global.controller_id != Guid.Empty)
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
"ControllerId", Global.controller_id));
}
}
}
11 changes: 11 additions & 0 deletions OmniLinkBridge/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;

namespace OmniLinkBridge
Expand Down Expand Up @@ -43,5 +45,14 @@ private static List<int> ParseRange(string range)
.Select(t => int.Parse(t)).ToList(); // digit to int
return RangeNums.Count.Equals(2) ? Enumerable.Range(RangeNums.Min(), (RangeNums.Max() + 1) - RangeNums.Min()).ToList() : RangeNums;
}

public static Guid ComputeGuid(this string data)
{
using SHA256 hash = SHA256.Create();
byte[] bytes = hash.ComputeHash(Encoding.UTF8.GetBytes(data));
byte[] guidBytes = new byte[16];
Array.Copy(bytes, guidBytes, 16);
return new Guid(guidBytes);
}
}
}
2 changes: 2 additions & 0 deletions OmniLinkBridge/Global.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Net.Mail;
Expand All @@ -16,6 +17,7 @@ public abstract class Global
public static string controller_key1;
public static string controller_key2;
public static string controller_name;
public static Guid controller_id;

// Time Sync
public static bool time_sync;
Expand Down
29 changes: 27 additions & 2 deletions OmniLinkBridge/Modules/LoggerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void Startup()
{
if (Global.mysql_logging)
{
log.Warning("MySQL logging is deprecated");
log.Information("Connecting to database");

mysql_conn = new OdbcConnection(Global.mysql_connection);
Expand Down Expand Up @@ -214,10 +215,34 @@ private void Omnilink_OnConnect(object sender, EventArgs e)
log.Verbose("Initial LockStatus {id} {name}, Status: {status}", i, reader.Name, reader.LockStatusText());
}

ushort audioSourceUsage = 0;
for (ushort i = 1; i <= omnilink.Controller.AudioSources.Count; i++)
{
clsAudioSource audioSource = omnilink.Controller.AudioSources[i];

if (audioSource.DefaultProperties == true)
continue;

audioSourceUsage++;
}

ushort audioZoneUsage = 0;
for (ushort i = 1; i <= omnilink.Controller.AudioZones.Count; i++)
{
clsAudioZone audioZone = omnilink.Controller.AudioZones[i];

if (audioZone.DefaultProperties == true)
continue;

audioZoneUsage++;
}

using (LogContext.PushProperty("Telemetry", "ControllerUsage"))
log.Debug("Controller has {AreaUsage} areas, {ZoneUsage} zones, {UnitUsage} units, " +
"{OutputUsage} outputs, {FlagUsage} flags, {ThermostatUsage} thermostats, {LockUsage} locks",
areaUsage, zoneUsage, unitUsage, outputUsage, flagUsage, thermostatUsage, lockUsage);
"{OutputUsage} outputs, {FlagUsage} flags, {ThermostatUsage} thermostats, {LockUsage} locks, " +
"{AudioSourceUsage} audio sources, {AudioZoneUsage} audio zones",
areaUsage, zoneUsage, unitUsage, outputUsage, flagUsage, thermostatUsage, lockUsage,
audioSourceUsage, audioZoneUsage);
}

private void Omnilink_OnAreaStatus(object sender, AreaStatusEventArgs e)
Expand Down
2 changes: 2 additions & 0 deletions OmniLinkBridge/Modules/WebServiceModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public WebServiceModule(OmniLinkII omni)

public void Startup()
{
log.Warning("WebAPI is deprecated");

WebNotification.RestoreSubscriptions();

Uri uri = new Uri("http://0.0.0.0:" + Global.webapi_port + "/");
Expand Down
9 changes: 5 additions & 4 deletions OmniLinkBridge/OmniLinkBridge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ControllerEnricher.cs" />
<Compile Include="CoreServer.cs" />
<Compile Include="Modules\TimeSyncModule.cs" />
<Compile Include="MQTT\HomeAssistant\Alarm.cs" />
Expand Down Expand Up @@ -185,19 +186,19 @@
<Version>3.1.2</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
<Version>13.0.3</Version>
</PackageReference>
<PackageReference Include="Serilog">
<Version>2.12.0</Version>
<Version>3.1.1</Version>
</PackageReference>
<PackageReference Include="Serilog.Formatting.Compact">
<Version>1.1.0</Version>
<Version>2.0.0</Version>
</PackageReference>
<PackageReference Include="Serilog.Sinks.Async">
<Version>1.5.0</Version>
</PackageReference>
<PackageReference Include="Serilog.Sinks.Console">
<Version>4.1.0</Version>
<Version>5.0.1</Version>
</PackageReference>
<PackageReference Include="Serilog.Sinks.File">
<Version>5.0.0</Version>
Expand Down
2 changes: 1 addition & 1 deletion OmniLinkBridge/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static int Main(string[] args)
.MinimumLevel.Verbose()
.Enrich.WithProperty("Application", "OmniLinkBridge")
.Enrich.WithProperty("Session", Guid.NewGuid())
.Enrich.WithProperty("User", (Environment.UserName + Environment.MachineName).GetHashCode())
.Enrich.With<ControllerEnricher>()
.Enrich.FromLogContext();

if (log_file != null)
Expand Down
4 changes: 2 additions & 2 deletions OmniLinkBridge/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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.14.0")]
[assembly: AssemblyFileVersion("1.1.14.0")]
[assembly: AssemblyVersion("1.1.15.0")]
[assembly: AssemblyFileVersion("1.1.15.0")]
18 changes: 16 additions & 2 deletions OmniLinkBridge/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public static void LoadSettings(NameValueCollection settings)
// HAI / Leviton Omni Controller
Global.controller_address = settings.ValidateHasValue("controller_address");
Global.controller_port = settings.ValidatePort("controller_port");
Global.controller_key1 = settings.ValidateHasValue("controller_key1");
Global.controller_key2 = settings.ValidateHasValue("controller_key2");
Global.controller_key1 = settings.ValidateEncryptionKey("controller_key1");
Global.controller_key2 = settings.ValidateEncryptionKey("controller_key2");
Global.controller_name = settings.CheckEnv("controller_name") ?? "OmniLinkBridge";
Global.controller_id = (Global.controller_address + Global.controller_key1 + Global.controller_key2).ComputeGuid();

// Controller Time Sync
Global.time_sync = settings.ValidateBool("time_sync");
Expand Down Expand Up @@ -234,6 +235,19 @@ private static string ValidateHasValue(this NameValueCollection settings, string
return value;
}

private static string ValidateEncryptionKey(this NameValueCollection settings, string section)
{
string value = settings.CheckEnv(section).Replace("-","");

if (string.IsNullOrEmpty(value) || value.Length != 16)
{
log.Error("Invalid encryption key specified for {section}", section);
throw new Exception();
}

return value;
}

private static int ValidateInt(this NameValueCollection settings, string section)
{
try
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# OmniLink Bridge
Provides MQTT bridge, web service API, time sync, and logging for [HAI/Leviton OmniPro II controllers](https://www.leviton.com/en/products/brands/omni-security-automation). Provides integration with [Samsung SmartThings via web service API](https://github.com/excaliburpartners/SmartThings-OmniPro) and [Home Assistant via MQTT](https://www.home-assistant.io/components/mqtt/).

Please note that OmniLink Bridge is not in active development. The MQTT and Home Assistant integrations are in maintenance mode. The SmartThings Web API and MySQL logging are deprecated and not feature consistent with MQTT.

## Download
You can use docker to build an image from git or download the [binary here](https://github.com/excaliburpartners/OmniLinkBridge/releases/latest/download/OmniLinkBridge.zip).
You can use docker to build an image from git or download the [binary here](https://github.com/excaliburpartners/OmniLinkBridge/releases/latest/download/OmniLinkBridge.zip). You can also install it as a [Home Assistant Add-on](https://github.com/excaliburpartners/hassio-addons).

## Requirements
- [Docker](https://www.docker.com/)
Expand All @@ -28,7 +30,7 @@ OmniLink Bridge is divided into the following modules and configurable settings.
- Provides integration with [Samsung SmartThings](https://github.com/excaliburpartners/SmartThings-OmniPro)
- Allows an application to subscribe to receive POST notifications status updates are received from the OmniLinkII module
- On failure to POST to callback URL subscription is removed
- Recommended for application to send subscribe reqeusts every few minutes
- Recommended for application to send subscribe requests every few minutes
- Requests to GET endpoints return status from the OmniLinkII module
- Requests to POST endpoints send commands to the OmniLinkII module
- Logger
Expand Down Expand Up @@ -388,7 +390,7 @@ POST /PushButton
```

## MySQL
The [MySQL ODBC Connector](http://dev.mysql.com/downloads/connector/odbc/) is required for MySQL logging. The docker image comes with the MySQL ODBC connector installed. For Windows and Linux you will need to download and install it.
The [MySQL ODBC Connector](http://dev.mysql.com/downloads/connector/odbc/) is required for MySQL logging. The docker image comes with the MySQL ODBC connector installed. For Windows and Linux you will need to download and install it. The Home Assistant Add-on does not support MySQL logging.

Configure mysql_connection in OmniLinkBridge.ini. For Windows change DRIVER={MySQL} to name of the driver shown in the ODBC Data Source Administrator.
```
Expand Down

0 comments on commit 800242a

Please sign in to comment.