mirror of
https://github.com/excaliburpartners/OmniLinkBridge.git
synced 2025-04-19 12:57:18 +00:00
1.1.4 - Shutdown cleanly on linux or docker
This commit is contained in:
parent
3e4a53fa13
commit
fe66f608ec
@ -83,6 +83,7 @@ namespace OmniLinkBridge.Modules
|
||||
PublishConfig();
|
||||
};
|
||||
MqttClient.ConnectingFailed += (sender, e) => { log.Debug("Error connecting " + e.Exception.Message); };
|
||||
MqttClient.Disconnected += (sender, e) => { log.Debug("Disconnected"); };
|
||||
|
||||
MqttClient.StartAsync(manoptions);
|
||||
|
||||
@ -103,6 +104,8 @@ namespace OmniLinkBridge.Modules
|
||||
|
||||
log.Debug("Publishing controller offline");
|
||||
MqttClient.PublishAsync($"{Global.mqtt_prefix}/status", "offline", MqttQualityOfServiceLevel.AtMostOnce, true);
|
||||
|
||||
MqttClient.StopAsync();
|
||||
}
|
||||
|
||||
private void MqttClient_ApplicationMessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e)
|
||||
@ -307,7 +310,8 @@ namespace OmniLinkBridge.Modules
|
||||
|
||||
private void OmniLink_OnConnect(object sender, EventArgs e)
|
||||
{
|
||||
PublishConfig();
|
||||
if(MqttClient.IsConnected)
|
||||
PublishConfig();
|
||||
|
||||
ControllerConnected = true;
|
||||
}
|
||||
@ -316,8 +320,11 @@ namespace OmniLinkBridge.Modules
|
||||
{
|
||||
ControllerConnected = false;
|
||||
|
||||
log.Debug("Publishing controller offline");
|
||||
MqttClient.PublishAsync($"{Global.mqtt_prefix}/status", "offline", MqttQualityOfServiceLevel.AtMostOnce, true);
|
||||
if (MqttClient.IsConnected)
|
||||
{
|
||||
log.Debug("Publishing controller offline");
|
||||
MqttClient.PublishAsync($"{Global.mqtt_prefix}/status", "offline", MqttQualityOfServiceLevel.AtMostOnce, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void PublishConfig()
|
||||
@ -489,6 +496,9 @@ namespace OmniLinkBridge.Modules
|
||||
|
||||
private void Omnilink_OnAreaStatus(object sender, AreaStatusEventArgs e)
|
||||
{
|
||||
if (!MqttClient.IsConnected)
|
||||
return;
|
||||
|
||||
PublishAreaState(e.Area);
|
||||
|
||||
// Since the controller doesn't fire zone status change on area status change
|
||||
@ -519,19 +529,28 @@ namespace OmniLinkBridge.Modules
|
||||
|
||||
private void Omnilink_OnZoneStatus(object sender, ZoneStatusEventArgs e)
|
||||
{
|
||||
if (!MqttClient.IsConnected)
|
||||
return;
|
||||
|
||||
PublishZoneState(e.Zone);
|
||||
}
|
||||
|
||||
private void Omnilink_OnUnitStatus(object sender, UnitStatusEventArgs e)
|
||||
{
|
||||
if (!MqttClient.IsConnected)
|
||||
return;
|
||||
|
||||
PublishUnitState(e.Unit);
|
||||
}
|
||||
|
||||
private void Omnilink_OnThermostatStatus(object sender, ThermostatStatusEventArgs e)
|
||||
{
|
||||
if (!MqttClient.IsConnected)
|
||||
return;
|
||||
|
||||
// Ignore events fired by thermostat polling and when temperature is invalid
|
||||
// An invalid temperature can occur when a Zigbee thermostat is unreachable
|
||||
if(!e.EventTimer && e.Thermostat.Temp > 0)
|
||||
if (!e.EventTimer && e.Thermostat.Temp > 0)
|
||||
PublishThermostatState(e.Thermostat);
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,8 @@ namespace OmniLinkBridge.Modules
|
||||
|
||||
trigger.WaitOne(new TimeSpan(0, 0, 5));
|
||||
}
|
||||
|
||||
Disconnect();
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
@ -84,6 +86,8 @@ namespace OmniLinkBridge.Modules
|
||||
|
||||
private void Disconnect()
|
||||
{
|
||||
log.Info("CONNECTION STATUS: Disconnecting");
|
||||
|
||||
if (Controller.Connection.ConnectionState != enuOmniLinkConnectionState.Offline)
|
||||
Controller.Connection.Disconnect();
|
||||
}
|
||||
|
@ -156,6 +156,9 @@
|
||||
<PackageReference Include="log4net">
|
||||
<Version>2.0.8</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Mono.Posix-4.5">
|
||||
<Version>4.5.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MQTTnet.Extensions.ManagedClient">
|
||||
<Version>2.8.4</Version>
|
||||
</PackageReference>
|
||||
|
@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using Mono.Unix;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.ServiceProcess;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OmniLinkBridge
|
||||
{
|
||||
@ -55,8 +57,26 @@ namespace OmniLinkBridge
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
|
||||
if (Environment.UserInteractive || interactive)
|
||||
{
|
||||
if (IsRunningOnMono())
|
||||
{
|
||||
UnixSignal[] signals = new UnixSignal[]{
|
||||
new UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
|
||||
new UnixSignal(Mono.Unix.Native.Signum.SIGINT),
|
||||
new UnixSignal(Mono.Unix.Native.Signum.SIGUSR1)
|
||||
};
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
// Blocking call to wait for any kill signal
|
||||
int index = UnixSignal.WaitAny(signals, -1);
|
||||
|
||||
server.Shutdown();
|
||||
});
|
||||
}
|
||||
|
||||
Console.TreatControlCAsInput = false;
|
||||
Console.CancelKeyPress += new ConsoleCancelEventHandler(myHandler);
|
||||
|
||||
@ -86,6 +106,11 @@ namespace OmniLinkBridge
|
||||
args.Cancel = true;
|
||||
}
|
||||
|
||||
static bool IsRunningOnMono()
|
||||
{
|
||||
return Type.GetType("Mono.Runtime") != null;
|
||||
}
|
||||
|
||||
static void ShowHelp()
|
||||
{
|
||||
Console.WriteLine(
|
||||
|
@ -224,6 +224,7 @@ Version 1.1.4 - 2019-11-22
|
||||
- Fix compatibility with Home Assistant 0.95.4 MQTT extra keys
|
||||
- Add Home Assistant MQTT device registry support
|
||||
- Add MQTT messages for controller disconnect and last will
|
||||
- Shutdown cleanly on linux or docker
|
||||
|
||||
Version 1.1.3 - 2019-02-10
|
||||
- Publish config when reconnecting to MQTT
|
||||
|
Loading…
x
Reference in New Issue
Block a user