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