From baeceda37a4feb3fcfacb373005bdfa3be3853b1 Mon Sep 17 00:00:00 2001 From: susch19 Date: Sun, 19 May 2024 13:57:58 +0200 Subject: [PATCH 1/2] Migrated to utc time * because this way the server is time zone independent (atleast for most parts) and the clients can decide how they want to display it * fixed painless heater scheduled not working correctly in the summer times and also having problem after time zone changes, because the time of day wasn't constant * send the heaters the local time, so that switch to and from daylight savings is intransparent to the heaters * add new controller for painless mesh, so that one can trigger time updates via rest, because it's broken in the app * upgrade to net 8, because net 7 will be out of support soon --- .gitignore | 3 + AppBroker.Core/AppBroker.Core.csproj | 24 +++---- AppBroker.Core/Devices/Device.cs | 11 +--- AppBroker.Core/DynamicUI/DeviceLayout.cs | 3 +- AppBroker.Core/Models/HeaterConfig.cs | 4 +- AppBroker.Core/Models/History.cs | 2 + AppBroker.Elsa/AppBroker.Elsa.csproj | 26 ++++---- .../AppBroker.Generators.Test.csproj | 12 ++-- .../AppBroker.Generators.csproj | 2 +- AppBroker.IOBroker/AppBroker.IOBroker.csproj | 2 +- AppBroker.IOBroker/Devices/ZigbeeDevice.cs | 41 ++++++------ .../AppBroker.PainlessMesh.Elsa.csproj | 2 +- .../AppBroker.PainlessMesh.csproj | 9 +-- .../Controller/PainlessController.cs | 40 ++++++++++++ .../Devices/Painless/Bridge.cs | 9 ++- .../Devices/Painless/Heater/Heater.cs | 46 ++++--------- .../Devices/Painless/PainlessDevice.cs | 2 +- AppBroker.PainlessMesh/Ota/UpdateManager.cs | 4 +- .../PainlessMeshMqttManager.cs | 4 +- AppBroker.PainlessMesh/Plugin.cs | 1 + .../SmarthomeMeshManager.cs | 63 +++++++----------- .../AppBroker.Zigbee2Mqtt.csproj | 10 +-- .../Devices/TradfriControlOutlet.cs | 2 - .../Devices/Zigbee2MqttDevice.cs | 41 ++++++++---- AppBroker.Zigbee2Mqtt/Zigbee2MqttManager.cs | 10 +-- AppBroker.susch/AppBroker.susch.csproj | 2 +- AppBroker.susch/Plugin.cs | 1 + AppBrokerASP/AppBrokerASP.csproj | 45 ++++++------- AppBrokerASP/Dockerfile | 4 +- AppBrokerASP/Histories/HistoryManager.cs | 6 +- AppBrokerASP/Program.cs | 3 +- AppBrokerASP/Smarthome.cs | 65 +++++++------------ AppBrokerASP/Startup.cs | 16 +++-- DbMigrator/DbMigrator.csproj | 18 ++--- .../IoBrokerHistoryImporter.csproj | 10 +-- TcpProxy/TcpProxy.csproj | 6 +- TestGenerator/TestGenerator.csproj | 2 +- .../TranslateTTMToHumanReadable.csproj | 6 +- 38 files changed, 285 insertions(+), 272 deletions(-) create mode 100644 AppBroker.PainlessMesh/Controller/PainlessController.cs diff --git a/.gitignore b/.gitignore index e4e1f78..beaaecf 100644 --- a/.gitignore +++ b/.gitignore @@ -286,3 +286,6 @@ OTA/* /DbMigrator/history.db-wal /AppBrokerASP/JSDevices /AppBrokerASP/JSExtensionDevices +*.dll +*.old +/DbMigrator/old diff --git a/AppBroker.Core/AppBroker.Core.csproj b/AppBroker.Core/AppBroker.Core.csproj index 3debe3d..4a988a1 100644 --- a/AppBroker.Core/AppBroker.Core.csproj +++ b/AppBroker.Core/AppBroker.Core.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable enable preview @@ -16,20 +16,20 @@ - + - - - - - - - + + + + + + + - - + + - + diff --git a/AppBroker.Core/Devices/Device.cs b/AppBroker.Core/Devices/Device.cs index 64a7530..22288e9 100644 --- a/AppBroker.Core/Devices/Device.cs +++ b/AppBroker.Core/Devices/Device.cs @@ -13,6 +13,7 @@ using Microsoft.EntityFrameworkCore; using System.Linq; using System.Runtime.CompilerServices; +using System.Text.Json; namespace AppBroker.Core.Devices; @@ -152,16 +153,6 @@ var oldConfs public virtual dynamic? GetConfig() { - using BrokerDbContext? cont = DbProvider.BrokerDbContext; - var configs = cont - .HeaterConfigs - .Where(x => x.DeviceId == Id) - .ToList() - .Select(x => x) - .ToList(); - if (configs.Count > 0) - return configs.ToJson(); - return null; } diff --git a/AppBroker.Core/DynamicUI/DeviceLayout.cs b/AppBroker.Core/DynamicUI/DeviceLayout.cs index 7e12762..9572d1b 100644 --- a/AppBroker.Core/DynamicUI/DeviceLayout.cs +++ b/AppBroker.Core/DynamicUI/DeviceLayout.cs @@ -10,5 +10,6 @@ public record DeviceLayout( long[]? Ids, DashboardDeviceLayout? DashboardDeviceLayout, DetailDeviceLayout? DetailDeviceLayout, + [property:Newtonsoft.Json.JsonExtensionData]IDictionary AdditionalData, int Version = 1, - bool ShowOnlyInDeveloperMode = false); + bool ShowOnlyInDeveloperMode = false ); diff --git a/AppBroker.Core/Models/HeaterConfig.cs b/AppBroker.Core/Models/HeaterConfig.cs index b340350..6f66239 100644 --- a/AppBroker.Core/Models/HeaterConfig.cs +++ b/AppBroker.Core/Models/HeaterConfig.cs @@ -40,9 +40,7 @@ public static implicit operator TimeTempMessageLE(HeaterConfig hc) => new(hc.DayOfWeek, new TimeSpan(hc.TimeOfDay.Hour, hc.TimeOfDay.Minute, 0), (float)hc.Temperature); public static implicit operator HeaterConfig(TimeTempMessageLE ttm) { - var dt = DateTime.Now; - dt = dt.AddHours(ttm.Time.Hours - dt.Hour); - dt = dt.AddMinutes(ttm.Time.Minutes - dt.Minute); + var dt = new DateTime(2000, 01, 01, ttm.Time.Hours, ttm.Time.Minutes, ttm.Time.Seconds, DateTimeKind.Utc); return new HeaterConfig(ttm.DayOfWeek, dt, ttm.Temp); } diff --git a/AppBroker.Core/Models/History.cs b/AppBroker.Core/Models/History.cs index c78e727..5d96e01 100644 --- a/AppBroker.Core/Models/History.cs +++ b/AppBroker.Core/Models/History.cs @@ -5,6 +5,8 @@ namespace AppBroker.Core.Models; public class History { + public static History Empty => new History(); + public History(HistoryRecord[] historyRecords, string propertyName) { HistoryRecords = historyRecords; diff --git a/AppBroker.Elsa/AppBroker.Elsa.csproj b/AppBroker.Elsa/AppBroker.Elsa.csproj index 6eccc61..e09834d 100644 --- a/AppBroker.Elsa/AppBroker.Elsa.csproj +++ b/AppBroker.Elsa/AppBroker.Elsa.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable enable preview @@ -18,18 +18,18 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/AppBroker.Generators.Test/AppBroker.Generators.Test.csproj b/AppBroker.Generators.Test/AppBroker.Generators.Test.csproj index 17406e7..faa587d 100644 --- a/AppBroker.Generators.Test/AppBroker.Generators.Test.csproj +++ b/AppBroker.Generators.Test/AppBroker.Generators.Test.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable false @@ -16,14 +16,14 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/AppBroker.Generators/AppBroker.Generators.csproj b/AppBroker.Generators/AppBroker.Generators.csproj index 437290d..88a0611 100644 --- a/AppBroker.Generators/AppBroker.Generators.csproj +++ b/AppBroker.Generators/AppBroker.Generators.csproj @@ -32,7 +32,7 @@ - + diff --git a/AppBroker.IOBroker/AppBroker.IOBroker.csproj b/AppBroker.IOBroker/AppBroker.IOBroker.csproj index ee6d4cf..d919821 100644 --- a/AppBroker.IOBroker/AppBroker.IOBroker.csproj +++ b/AppBroker.IOBroker/AppBroker.IOBroker.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable diff --git a/AppBroker.IOBroker/Devices/ZigbeeDevice.cs b/AppBroker.IOBroker/Devices/ZigbeeDevice.cs index e30feb4..ed08e92 100644 --- a/AppBroker.IOBroker/Devices/ZigbeeDevice.cs +++ b/AppBroker.IOBroker/Devices/ZigbeeDevice.cs @@ -8,18 +8,20 @@ using Newtonsoft.Json; -using SocketIOClient; +using SocketIOClient.Transport; using System.Collections.ObjectModel; using System.Reflection; using System.Text.RegularExpressions; +using SocketIo = SocketIOClient.SocketIO; + namespace AppBroker.IOBroker.Devices; [AppBroker.ClassPropertyChangedAppbroker] public partial class ZigbeeDevice : PropChangedJavaScriptDevice { - protected SocketIO Socket { get; } + protected SocketIo Socket { get; } public bool Available { @@ -59,7 +61,7 @@ public string LastReceivedFormatted [AppBroker.IgnoreField] private bool available; - public ZigbeeDevice(long nodeId, SocketIO socket, string typeName) : base(nodeId, typeName, new FileInfo(Path.Combine("JSExtensionDevices", typeName + ".js"))) + public ZigbeeDevice(long nodeId, SocketIo socket, string typeName) : base(nodeId, typeName, new FileInfo(Path.Combine("JSExtensionDevices", typeName + ".js"))) { TypeName = typeName; Socket = socket; @@ -82,7 +84,7 @@ public string LastReceivedFormatted .ToArray()); } - public ZigbeeDevice(long nodeId, SocketIO socket) : base(nodeId, null, null) + public ZigbeeDevice(long nodeId, SocketIo socket) : base(nodeId, null, null) { Socket = socket; @@ -125,8 +127,8 @@ public void SetPropFromIoBroker(IoBrokerObject ioBrokerObject, bool setLastRecei SetProperty(ioBrokerObject, prop); if (setLastReceived) { - LastReceived = DateTime.Now; - SetState("lastReceived", DateTime.Now); + LastReceived = DateTime.UtcNow; + SetState("lastReceived", DateTime.UtcNow); } SendDataToAllSubscribers(); @@ -276,19 +278,20 @@ private async Task GetHistoryRecords(DateTimeOffset start, Date var i = AdapterWithId + "." + type.ToLower(); var endMs = end.ToUnixTimeMilliseconds(); - var history = await Socket.Emit("getHistory", - i, - new - { - id = i, // probably not necessary to put it here again - start = start.ToUnixTimeMilliseconds(), - //end = end.ToUnixTimeMilliseconds(), - ignoreNull = true, - aggregate = "none", - count = 2000 - }); - - return history is null ? Array.Empty() : history.GetValue(1).Where(x => x.Ts < endMs).ToArray(); + return Array.Empty(); + //var history = await Socket.EmitAsync("getHistory", + // i, + // new + // { + // id = i, // probably not necessary to put it here again + // start = start.ToUnixTimeMilliseconds(), + // //end = end.ToUnixTimeMilliseconds(), + // ignoreNull = true, + // aggregate = "none", + // count = 2000 + // }); + + //return history is null ? Array.Empty() : history.GetValue(1).Where(x => x.Ts < endMs).ToArray(); } } diff --git a/AppBroker.PainlessMesh.Elsa/AppBroker.PainlessMesh.Elsa.csproj b/AppBroker.PainlessMesh.Elsa/AppBroker.PainlessMesh.Elsa.csproj index 3ce330e..b22a391 100644 --- a/AppBroker.PainlessMesh.Elsa/AppBroker.PainlessMesh.Elsa.csproj +++ b/AppBroker.PainlessMesh.Elsa/AppBroker.PainlessMesh.Elsa.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable enable diff --git a/AppBroker.PainlessMesh/AppBroker.PainlessMesh.csproj b/AppBroker.PainlessMesh/AppBroker.PainlessMesh.csproj index 373031b..f12db1e 100644 --- a/AppBroker.PainlessMesh/AppBroker.PainlessMesh.csproj +++ b/AppBroker.PainlessMesh/AppBroker.PainlessMesh.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable @@ -25,9 +25,10 @@ - - - + + + + diff --git a/AppBroker.PainlessMesh/Controller/PainlessController.cs b/AppBroker.PainlessMesh/Controller/PainlessController.cs new file mode 100644 index 0000000..a2f5630 --- /dev/null +++ b/AppBroker.PainlessMesh/Controller/PainlessController.cs @@ -0,0 +1,40 @@ +using AppBroker.Core; +using AppBroker.Core.Devices; +using AppBroker.Core.Javascript; +using AppBroker.Core.Managers; + +using AppBrokerASP.Cloud; +using AppBrokerASP.Configuration; +using AppBrokerASP.Devices; + +using Elsa.Server.Api.Attributes; + +using Microsoft.AspNetCore.Mvc; + +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +using System.Security.Cryptography; +using System.Text; +using System.Text.Json; + +namespace AppBroker.PainlessMesh; +[Route("painless")] +public class PainlessController : ControllerBase +{ + private readonly SmarthomeMeshManager? smarthomeManager; + + public PainlessController() + { + IInstanceContainer.Instance.TryGetDynamic(out smarthomeManager); + } + + [HttpPut("time")] + public ActionResult UpdateTime() + { + smarthomeManager?.UpdateTime(); + return smarthomeManager is null ? Problem("Mesh Manager not found") : Ok(); + } + + +} diff --git a/AppBroker.PainlessMesh/Devices/Painless/Bridge.cs b/AppBroker.PainlessMesh/Devices/Painless/Bridge.cs index 1bf57cc..66a6ef9 100644 --- a/AppBroker.PainlessMesh/Devices/Painless/Bridge.cs +++ b/AppBroker.PainlessMesh/Devices/Painless/Bridge.cs @@ -1,4 +1,9 @@ -namespace AppBrokerASP.Devices.Painless; +using AppBroker.Core.Models; +using AppBroker.Core; +using AppBroker.PainlessMesh; +using Newtonsoft.Json.Linq; + +namespace AppBrokerASP.Devices.Painless; public class Bridge : PainlessDevice { @@ -6,4 +11,4 @@ public Bridge(long nodeId, List parameter) : base(nodeId, "PainlessMeshB { ShowInApp = false; } -} +} \ No newline at end of file diff --git a/AppBroker.PainlessMesh/Devices/Painless/Heater/Heater.cs b/AppBroker.PainlessMesh/Devices/Painless/Heater/Heater.cs index e73b27a..ff5407b 100644 --- a/AppBroker.PainlessMesh/Devices/Painless/Heater/Heater.cs +++ b/AppBroker.PainlessMesh/Devices/Painless/Heater/Heater.cs @@ -52,21 +52,22 @@ private HeaterConfig[] timeTemps [AppBroker.IgnoreField] private bool disposed; - [IgnoreField] + [AppBroker.IgnoreField] static TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"); public Heater(long id, ByteLengthList parameters) : base(id, "PainlessMeshHeater") { using BrokerDbContext? cont = DbProvider.BrokerDbContext; - ShowInApp = true; - //cont.HeaterCalibrations.FirstOrDefault(x => x.Id == Id); + try { - DeviceModel? heater = cont.Devices.FirstOrDefault(x => x.Id == Id); - var mappings = cont.DeviceToDeviceMappings.Include(x => x.Child).Where(x => x.Parent!.Id == id /*&& cont.Devices.Any(y => y.Id == x.Child.Id)*/).ToList(); + var mappings = cont.DeviceToDeviceMappings + .Include(x => x.Child) + .Where(x => x.Parent!.Id == id) + .ToList(); Logger.Debug($"Heater {LogName} has {mappings?.Count} mappings"); if (mappings?.Count > 0) heaterSensorMapping = Task.Run(() => TrySubscribe(mappings)); @@ -115,9 +116,7 @@ private static byte[] GetSendableTimeTemps(IEnumerable timeTemps) private static TimeTempMessageLE Convert(HeaterConfig hc) { - var offset = tz.GetUtcOffset(hc.TimeOfDay); - var newTime=hc.TimeOfDay.Subtract(offset); - return new(hc.DayOfWeek, new TimeSpan(newTime.Hour, newTime.Minute, 0), (float)hc.Temperature); + return new(hc.DayOfWeek, new TimeSpan(hc.TimeOfDay.Hour, hc.TimeOfDay.Minute, 0), (float)hc.Temperature); } private Task TrySubscribe(List mappings) @@ -194,7 +193,7 @@ protected override void UpdateMessageReceived(BinarySmarthomeMessage e) var dt = DateTime.UnixEpoch.AddSeconds(seconds); var logLine = Encoding.UTF8.GetString(item.AsSpan(sizeof(long))); - dt = dt.Add(tz.GetUtcOffset(dt)); + //dt = dt.Add(tz.GetUtcOffset(dt)); if(logLine.Contains("Ti: 0")) { @@ -207,7 +206,7 @@ protected override void UpdateMessageReceived(BinarySmarthomeMessage e) { var logLine = Encoding.UTF8.GetString(item.AsSpan(sizeof(long))); - Logger.Error($"{Id}|{FriendlyName}|{DateTime.Now:yyyy-MM-dd HH:mm:ss}-Unknown|{logLine}|Binary:{BitConverter.ToString(item)}"); + Logger.Error($"{Id}|{FriendlyName}|{DateTime.UtcNow:yyyy-MM-dd HH:mm:ss}-Unknown|{logLine}|Binary:{BitConverter.ToString(item)}"); } } @@ -228,8 +227,6 @@ protected override void OptionMessageReceived(BinarySmarthomeMessage e) switch (e.Command) { case Command.Temp: - //CurrentConfig = TimeTempMessageLE.FromBase64((string)e.Parameters[0]); - //SendDataToAllSubscribers(); break; case Command.Off: DisableLed = true; @@ -238,9 +235,6 @@ protected override void OptionMessageReceived(BinarySmarthomeMessage e) DisableLed = false; break; case Command.Mode: - //if (e.Parameters.Count < 1) - // return; - //DisableLed = BitConverter.ToBoolean(e.Parameters[0]); break; default: @@ -251,25 +245,18 @@ protected override void OptionMessageReceived(BinarySmarthomeMessage e) private void HandleTimeTempMessageUpdate(byte[] messages) { - void CorrectTimeZone(HeaterConfig config) - { - config.TimeOfDay = config.TimeOfDay.Add(tz.GetUtcOffset(config.TimeOfDay)); - } - + Span message = messages.AsSpan(); var ttm = TimeTempMessageLE.LoadFromBinary(message[..3]); Temperature = ttm; - CorrectTimeZone(Temperature); ttm = TimeTempMessageLE.LoadFromBinary(message[3..6]); CurrentConfig = ttm; - CorrectTimeZone(CurrentConfig); ttm = TimeTempMessageLE.LoadFromBinary(message[6..9]); try { ttm.Temp -= 51.2f; CurrentCalibration = ttm; - CorrectTimeZone(CurrentCalibration); } catch (Exception e) { @@ -409,15 +396,15 @@ private bool UpdateDeviceMappingInDb(long tempId, long oldId) return true; } - - private void DeviceStateManager_StateChanged(object? sender, StateChangeArgs e) { if (e.Id != XiaomiTempSensor || !e.PropertyName.Equals("Temperature", StringComparison.OrdinalIgnoreCase)) return; var temp = e.NewValue.Value(); - var ttm = new TimeTempMessageLE((DayOfWeek)((((byte)DateTime.Now.DayOfWeek) + 6) % 7), new TimeSpan(DateTime.Now.TimeOfDay.Hours, DateTime.Now.TimeOfDay.Minutes, 0), temp); + var offset = tz.GetUtcOffset(DateTime.UtcNow.AddSeconds(-5)); + var local = DateTime.UtcNow.Add(offset); + var ttm = new TimeTempMessageLE((DayOfWeek)((((byte)local.DayOfWeek) + 6) % 7), new TimeSpan(local.TimeOfDay.Hours, local.TimeOfDay.Minutes, 0), temp); var msg = new BinarySmarthomeMessage((uint)Id, MessageType.Relay, Command.Temp, ttm.ToBinary()); meshManager.SendSingle((uint)Id, msg); } @@ -426,13 +413,6 @@ public override void Reconnect(ByteLengthList parameter) { base.Reconnect(parameter); - InterpretParameters(parameter); - - meshManager.SingleUpdateMessageReceived -= Node_SingleUpdateMessageReceived; - meshManager.SingleOptionsMessageReceived -= Node_SingleOptionsMessageReceived; - meshManager.SingleUpdateMessageReceived += Node_SingleUpdateMessageReceived; - meshManager.SingleOptionsMessageReceived += Node_SingleOptionsMessageReceived; - SendLastTempData(); } diff --git a/AppBroker.PainlessMesh/Devices/Painless/PainlessDevice.cs b/AppBroker.PainlessMesh/Devices/Painless/PainlessDevice.cs index f70783b..882bf2b 100644 --- a/AppBroker.PainlessMesh/Devices/Painless/PainlessDevice.cs +++ b/AppBroker.PainlessMesh/Devices/Painless/PainlessDevice.cs @@ -141,7 +141,7 @@ public void OtaAdvertisment(FirmwareMetadata metadata) if (!DeviceName.Equals(metadata.DeviceType, StringComparison.OrdinalIgnoreCase) || ((FirmwareVersionNr == metadata.FirmwareVersion || !metadata.Forced) && FirmwareVersionNr >= metadata.FirmwareVersion) - || LastPartRequestReceived.AddSeconds(30) > DateTime.Now + || LastPartRequestReceived.AddSeconds(30) > DateTime.UtcNow || (metadata.TargetId > 0 && metadata.TargetId != Id)) { return; diff --git a/AppBroker.PainlessMesh/Ota/UpdateManager.cs b/AppBroker.PainlessMesh/Ota/UpdateManager.cs index 1842579..3f9d526 100644 --- a/AppBroker.PainlessMesh/Ota/UpdateManager.cs +++ b/AppBroker.PainlessMesh/Ota/UpdateManager.cs @@ -145,10 +145,10 @@ private void StartStopAdvertismentFromFile(object sender, RenamedEventArgs e) public void AdvertiseUpdate(FirmwareMetadata metadata, byte[] data, List parts) { var firmwareId = metadata.FirmwareId; - if (currentAdvertisments.TryGetValue(firmwareId, out var advertisment) && advertisment.AdvertiseUntil > DateTime.Now) + if (currentAdvertisments.TryGetValue(firmwareId, out var advertisment) && advertisment.AdvertiseUntil > DateTime.UtcNow) return; - currentAdvertisments[firmwareId] = new FirmwareAdvertisment(parts, DateTime.Now.AddHours(1), metadata, data); + currentAdvertisments[firmwareId] = new FirmwareAdvertisment(parts, DateTime.UtcNow.AddHours(1), metadata, data); if (advertismentTimers.TryGetValue(firmwareId, out var timer)) timer?.Dispose(); diff --git a/AppBroker.PainlessMesh/PainlessMeshMqttManager.cs b/AppBroker.PainlessMesh/PainlessMeshMqttManager.cs index a6cef7f..25819d9 100644 --- a/AppBroker.PainlessMesh/PainlessMeshMqttManager.cs +++ b/AppBroker.PainlessMesh/PainlessMeshMqttManager.cs @@ -252,7 +252,7 @@ private void TryInterpretTopicAsStateUpdate(long id, string payload) InstanceContainer .Instance .DeviceStateManager - .SetSingleState(id, "lastReceived", DateTime.Now); + .SetSingleState(id, "lastReceived", DateTime.UtcNow); } private void SetSingleState(long id, string propName, JToken value) { @@ -264,7 +264,7 @@ private void SetSingleState(long id, string propName, JToken value) InstanceContainer .Instance .DeviceStateManager - .SetSingleState(id, "lastReceived", DateTime.Now, StateFlags.StoreLastState); + .SetSingleState(id, "lastReceived", DateTime.UtcNow, StateFlags.StoreLastState); } public async ValueTask DisposeAsync() diff --git a/AppBroker.PainlessMesh/Plugin.cs b/AppBroker.PainlessMesh/Plugin.cs index a6e44ab..e73b083 100644 --- a/AppBroker.PainlessMesh/Plugin.cs +++ b/AppBroker.PainlessMesh/Plugin.cs @@ -13,6 +13,7 @@ internal class Plugin : IPlugin { public string Name => "Plainless Mesh"; + public bool Initialize(LogFactory logFactory) { var cm = InstanceContainer.Instance.ConfigManager; diff --git a/AppBroker.PainlessMesh/SmarthomeMeshManager.cs b/AppBroker.PainlessMesh/SmarthomeMeshManager.cs index 21a9594..a8f4407 100644 --- a/AppBroker.PainlessMesh/SmarthomeMeshManager.cs +++ b/AppBroker.PainlessMesh/SmarthomeMeshManager.cs @@ -51,6 +51,7 @@ public NodeSync(uint id, byte missedConnections) private readonly List timers; private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); private bool running; + static TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"); public SmarthomeMeshManager(bool enabled, int listenPort, uint nodeId = 1) { @@ -123,8 +124,9 @@ internal void UpdateTime() private static readonly byte[] fromServer = new byte[] { 1 }; private void SendTimeUpdate(object? state) { - var dto = new DateTimeOffset(DateTime.Now); - var list = new ByteLengthList(fromServer, BitConverter.GetBytes((int)dto.ToUnixTimeSeconds())); + var dto = new DateTimeOffset(DateTime.UtcNow); + var currOffest = tz.GetUtcOffset(dto); + var list = new ByteLengthList(fromServer, BitConverter.GetBytes((int)(dto.ToUnixTimeSeconds() + currOffest.TotalSeconds))); var msg = new BinarySmarthomeMessage(0, MessageType.Update, Command.Time, list); SendBroadcast(msg); } @@ -173,13 +175,13 @@ public void SocketClientDataReceived(BinarySmarthomeMessage e) NodeSync? known = knownNodeIds.FirstOrDefault(x => x.Id == e.NodeId); if (known == default) { - if (!whoIAmSendTime.TryGetValue(e.NodeId, out (DateTime time, int count) dt) || dt.time.Add(waitBeforeWhoIAmSendAgain) > DateTime.Now) + if (!whoIAmSendTime.TryGetValue(e.NodeId, out (DateTime time, int count) dt) || dt.time.Add(waitBeforeWhoIAmSendAgain) > DateTime.UtcNow) { //SendSingle(e.NodeId, new BinarySmarthomeMessage(0, MessageType.Get, Command.WhoIAm)); if (dt == default) - _ = whoIAmSendTime.TryAdd(e.NodeId, (DateTime.Now.Subtract(waitBeforeWhoIAmSendAgain), 0)); + _ = whoIAmSendTime.TryAdd(e.NodeId, (DateTime.UtcNow.Subtract(waitBeforeWhoIAmSendAgain), 0)); else - whoIAmSendTime[e.NodeId] = (DateTime.Now.Subtract(waitBeforeWhoIAmSendAgain), 0); + whoIAmSendTime[e.NodeId] = (DateTime.UtcNow.Subtract(waitBeforeWhoIAmSendAgain), 0); } if (!queuedMessages.TryGetValue(e.NodeId, out Queue? queue)) { @@ -190,7 +192,7 @@ public void SocketClientDataReceived(BinarySmarthomeMessage e) return; } - if (known.MissedConnections > 0) + if (known.MissedConnections > 5) { known.MissedConnections = 0; ConnectionReestablished?.Invoke(this, (known.Id, e.Parameters)); @@ -236,9 +238,9 @@ private bool TryParseSubsRecursive(Sub sub, out List subs) { //SendSingle(sub.NodeId, new BinarySmarthomeMessage(0, MessageType.Get, Command.WhoIAm)); if (dt == default) - _ = whoIAmSendTime.TryAdd(sub.NodeId, (DateTime.Now, 0)); + _ = whoIAmSendTime.TryAdd(sub.NodeId, (DateTime.UtcNow, 0)); else - whoIAmSendTime[sub.NodeId] = (DateTime.Now, 0); + whoIAmSendTime[sub.NodeId] = (DateTime.UtcNow, 0); } } @@ -312,10 +314,13 @@ internal void RefreshMesh(Sub sub) if (item.MissedConnections > 0) { item.MissedConnections = 0; - if (IInstanceContainer.Instance.DeviceManager.Devices.TryGetValue(item.Id, out AppBroker.Core.Devices.Device? dev)) - SendSingle((uint)dev.Id, new BinarySmarthomeMessage(0, MessageType.Get, Command.WhoIAm)); - else - lostSubs.Add(item.Id); + if (item.MissedConnections > 5) + { + if (IInstanceContainer.Instance.DeviceManager.Devices.TryGetValue(item.Id, out AppBroker.Core.Devices.Device? dev)) + SendSingle((uint)dev.Id, new BinarySmarthomeMessage(0, MessageType.Get, Command.WhoIAm)); + else + lostSubs.Add(item.Id); + } } } } @@ -330,11 +335,15 @@ internal void RefreshMesh(Sub sub) foreach (uint id in lostSubs) { NodeSync? knownId = knownNodeIds.FirstOrDefault(x => x.Id == id); - ConnectionLost?.Invoke(this, id); if (knownId != default) { if (knownId.MissedConnections > 15) _ = knownNodeIds.Remove(knownId); + else if (knownId.MissedConnections > 5) + { + logger.Warn($"Lost connection to {id}"); + ConnectionLost?.Invoke(this, id); + } else knownId.MissedConnections++; } @@ -383,18 +392,6 @@ public void SendSingle(uint destination, Memory message) logger.Error(e); } } - //public void SendCustomSingle(long destination, PackageType type, T message) - //{ - // try - // { - // ServerSocket.SendToAllClients(type, message.ToJson(), destination); - // } - // catch (Exception e) - // { - // Console.WriteLine(e); - // logger.Error(e); - // } - //} public void SendBroadcast(T message) where T : BinarySmarthomeMessage { @@ -424,18 +421,6 @@ public void SendBroadcast(Memory message) logger.Error(e); } } - //public void SendCustomBroadcast(PackageType type, T message) - //{ - // try - // { - // ServerSocket.SendToAllClients(type, message.ToJson(), 0); - // } - // catch (Exception e) - // { - // Console.WriteLine(e); - // logger.Error(e); - // } - //} public void SendToBridge(T message) where T : BinarySmarthomeMessage { @@ -476,10 +461,10 @@ private void WhoAmITask() { foreach (KeyValuePair item in whoIAmSendTime) { - if (item.Value.time.Add(waitBeforeWhoIAmSendAgain) < DateTime.Now) + if (item.Value.time.Add(waitBeforeWhoIAmSendAgain) < DateTime.UtcNow) { SendSingle(item.Key, new BinarySmarthomeMessage(0, MessageType.Get, Command.WhoIAm)); - whoIAmSendTime[item.Key] = (DateTime.Now, item.Value.count + 1); + whoIAmSendTime[item.Key] = (DateTime.UtcNow, item.Value.count + 1); } if (item.Value.count > 20) toDelete.Add(item.Key, item.Value); diff --git a/AppBroker.Zigbee2Mqtt/AppBroker.Zigbee2Mqtt.csproj b/AppBroker.Zigbee2Mqtt/AppBroker.Zigbee2Mqtt.csproj index 016a585..930f5c0 100644 --- a/AppBroker.Zigbee2Mqtt/AppBroker.Zigbee2Mqtt.csproj +++ b/AppBroker.Zigbee2Mqtt/AppBroker.Zigbee2Mqtt.csproj @@ -1,10 +1,10 @@  - - net7.0 - enable - enable - + + net8.0 + enable + enable + diff --git a/AppBroker.Zigbee2Mqtt/Devices/TradfriControlOutlet.cs b/AppBroker.Zigbee2Mqtt/Devices/TradfriControlOutlet.cs index 15b97c5..b6b54f6 100644 --- a/AppBroker.Zigbee2Mqtt/Devices/TradfriControlOutlet.cs +++ b/AppBroker.Zigbee2Mqtt/Devices/TradfriControlOutlet.cs @@ -1,7 +1,5 @@ using AppBroker.Core.Devices; -using SocketIOClient; - namespace AppBroker.Zigbee2Mqtt.Devices; [DeviceName("E1603/E1702")] diff --git a/AppBroker.Zigbee2Mqtt/Devices/Zigbee2MqttDevice.cs b/AppBroker.Zigbee2Mqtt/Devices/Zigbee2MqttDevice.cs index 15f223e..6158924 100644 --- a/AppBroker.Zigbee2Mqtt/Devices/Zigbee2MqttDevice.cs +++ b/AppBroker.Zigbee2Mqtt/Devices/Zigbee2MqttDevice.cs @@ -54,8 +54,8 @@ public string LastReceivedFormatted static Zigbee2MqttDevice() { - zigbeeManager = InstanceContainer.Instance.GetDynamic(); - client = InstanceContainer.Instance.GetDynamic().MQTTClient!; + zigbeeManager = IInstanceContainer.Instance.GetDynamic(); + client = IInstanceContainer.Instance.GetDynamic().MQTTClient!; } public Zigbee2MqttDevice(Zigbee2MqttDeviceJson device, long id) @@ -235,20 +235,35 @@ protected override Context ExtendEngine(Context engine) protected override bool FriendlyNameChanging(string oldName, string newName) { - if (string.IsNullOrWhiteSpace(oldName) || string.IsNullOrWhiteSpace(newName)) - return true; +#if DEBUG + return false; +#endif + if (string.IsNullOrWhiteSpace(newName)) + return false; + try + { + if (string.IsNullOrWhiteSpace(oldName)) + { + zigbeeManager.friendlyNameToIdMapping[newName] = Id; + return true; + } + logger.Info($"Trying to rename {oldName} to {newName} for device with id {Id}"); + client.EnqueueAsync("zigbee2mqtt/bridge/request/device/rename", $"{{\"from\": \"{oldName}\", \"to\": \"{newName}\"}}"); + if (zigbeeManager.friendlyNameToIdMapping.TryGetValue(oldName, out var id) + && id == Id + && !zigbeeManager.friendlyNameToIdMapping.ContainsKey(newName) + && zigbeeManager.friendlyNameToIdMapping.Remove(oldName, out _)) + { + zigbeeManager.friendlyNameToIdMapping[newName] = id; + return true; + } - client.EnqueueAsync("zigbee2mqtt/bridge/request/device/rename", $"{{\"from\": \"{oldName}\", \"to\": \"{newName}\"}}"); - if (zigbeeManager.friendlyNameToIdMapping.TryGetValue(oldName, out var id) - && id == Id - && !zigbeeManager.friendlyNameToIdMapping.ContainsKey(newName) - && zigbeeManager.friendlyNameToIdMapping.Remove(oldName, out _)) + logger.Error($"Couldn't rename {oldName} to {newName} for zigbee2mqtt, because the old name was incorrect, it couldn't be removed from the mapping or the new name was already used"); + } + catch (Exception ex) { - zigbeeManager.friendlyNameToIdMapping[newName] = id; - return true; + logger.Error(ex, $" Couldn't rename {oldName} to {newName} for zigbee2mqtt"); } - - logger.Error($"Couldn't rename {oldName} to {newName} for zigbee2mqtt, because the old name was incorrect, it couldn't be removed from the mapping or the new name was already used"); return false; } } diff --git a/AppBroker.Zigbee2Mqtt/Zigbee2MqttManager.cs b/AppBroker.Zigbee2Mqtt/Zigbee2MqttManager.cs index 9359d1e..55e22b7 100644 --- a/AppBroker.Zigbee2Mqtt/Zigbee2MqttManager.cs +++ b/AppBroker.Zigbee2Mqtt/Zigbee2MqttManager.cs @@ -14,6 +14,7 @@ using AppBroker.Zigbee2Mqtt.Devices; using System.Diagnostics.CodeAnalysis; using AppBroker.Core.Devices; +using AppBroker.Core.DynamicUI; namespace AppBroker.Zigbee2Mqtt; @@ -252,10 +253,11 @@ private void TryInterpretTopicAsStateUpdate(string deviceName, string payload) .DeviceStateManager .SetMultipleStates(id, ReplaceCustomStates(id, JsonConvert.DeserializeObject>(payload)!)); - InstanceContainer - .Instance - .DeviceStateManager - .SetSingleState(id, "lastReceived", DateTime.Now); + InstanceContainer + .Instance + .DeviceStateManager + .SetSingleState(id, "lastReceived", DateTime.UtcNow); + } } } diff --git a/AppBroker.susch/AppBroker.susch.csproj b/AppBroker.susch/AppBroker.susch.csproj index 152cdc6..0b7db5e 100644 --- a/AppBroker.susch/AppBroker.susch.csproj +++ b/AppBroker.susch/AppBroker.susch.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable diff --git a/AppBroker.susch/Plugin.cs b/AppBroker.susch/Plugin.cs index 8c92460..08593a6 100644 --- a/AppBroker.susch/Plugin.cs +++ b/AppBroker.susch/Plugin.cs @@ -113,6 +113,7 @@ private void DeviceStateManager_StateChanged(object? sender, StateChangeArgs e) { var currentState = IInstanceContainer.Instance.DeviceStateManager.GetSingleState(ledstrip, "colorMode"); IInstanceContainer.Instance.DeviceStateManager.SetSingleState(ledstrip, "colorMode", currentState.ToString() == "Off" ? "SingleColor" : "Off", StateFlags.SendToThirdParty); + IInstanceContainer.Instance.DeviceStateManager.SetSingleState(ledstrip, "colorNumber", 4278190080, StateFlags.SendToThirdParty); #if DEBUG if (IInstanceContainer.Instance.DeviceManager.Devices.TryGetValue(ledstrip, out var ledStripDev)) ledStripDev.SendDataToAllSubscribers(); diff --git a/AppBrokerASP/AppBrokerASP.csproj b/AppBrokerASP/AppBrokerASP.csproj index 9d5bc6a..7cb2c21 100644 --- a/AppBrokerASP/AppBrokerASP.csproj +++ b/AppBrokerASP/AppBrokerASP.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable preview enable @@ -42,36 +42,37 @@ - - + + - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + - - - - - - - - - - + + + + + + + + + + - + diff --git a/AppBrokerASP/Dockerfile b/AppBrokerASP/Dockerfile index c4c04d3..1d4efa0 100644 --- a/AppBrokerASP/Dockerfile +++ b/AppBrokerASP/Dockerfile @@ -1,6 +1,6 @@ #See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. -FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base WORKDIR /app EXPOSE 80 EXPOSE 443 @@ -8,7 +8,7 @@ EXPOSE 5055 ARG TARGETPLATFORM -FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim-amd64 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY ["Nuget.Config", "."] COPY ["AppBrokerASP/AppBrokerASP.csproj", "AppBrokerASP/"] diff --git a/AppBrokerASP/Histories/HistoryManager.cs b/AppBrokerASP/Histories/HistoryManager.cs index 5fcf583..beaf722 100644 --- a/AppBrokerASP/Histories/HistoryManager.cs +++ b/AppBrokerASP/Histories/HistoryManager.cs @@ -3,7 +3,7 @@ using AppBroker.Core.Database.History; using AppBroker.Core.Models; -using Common.Logging; +using NLog; using Microsoft.EntityFrameworkCore; @@ -21,11 +21,11 @@ public class HistoryManager : IHistoryManager { static HeaterConfig emptyHeaderConfig = new(); - private ILog logger; + private Logger logger; public HistoryManager() { - logger = LogManager.GetLogger(); + logger = LogManager.GetLogger(nameof(HistoryManager)); } public void StoreNewState(long id, string name, JToken? oldValue, JToken? newValue) diff --git a/AppBrokerASP/Program.cs b/AppBrokerASP/Program.cs index 9551880..6f98478 100644 --- a/AppBrokerASP/Program.cs +++ b/AppBrokerASP/Program.cs @@ -17,7 +17,6 @@ using MQTTnet.Server; using MQTTnet; using Newtonsoft.Json; -using Esprima; namespace AppBrokerASP; @@ -34,7 +33,7 @@ public class Program public static void Main(string[] args) { - Console.OutputEncoding = Encoding.Unicode; + Console.OutputEncoding = Encoding.UTF8; Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); _ = new InstanceContainer(); diff --git a/AppBrokerASP/Smarthome.cs b/AppBrokerASP/Smarthome.cs index 725e3c0..f8c9b18 100644 --- a/AppBrokerASP/Smarthome.cs +++ b/AppBrokerASP/Smarthome.cs @@ -4,11 +4,14 @@ using AppBroker.Core.DynamicUI; using AppBroker.Core.Models; +using AppBrokerASP.Plugins; using Microsoft.AspNetCore.SignalR; using Newtonsoft.Json; +using NLog.Targets; + using System.Reflection; using System.Threading.Tasks; @@ -20,6 +23,8 @@ public SmartHome() { } + + public override Task OnConnectedAsync() => //foreach (var item in IInstanceContainer.Instance.DeviceManager.Devices.Values) // item.SendLastData(Clients.Caller); @@ -98,7 +103,7 @@ public record struct DeviceOverview(long Id, string TypeName, IReadOnlyCollectio public Task> GetIoBrokerHistories(long id, string dt) { - if (IInstanceContainer.Instance.DeviceManager.Devices.TryGetValue(id, out Device? device) ) + if (IInstanceContainer.Instance.DeviceManager.Devices.TryGetValue(id, out Device? device)) { DateTime date = DateTime.Parse(dt).Date; return device.GetHistory(date, date.AddDays(1).AddSeconds(-1)); @@ -113,12 +118,12 @@ public virtual Task GetIoBrokerHistory(long id, string dt, string prope DateTime date = DateTime.Parse(dt).Date; return device.GetHistory(date, date.AddDays(1).AddSeconds(-1), propertyName); } - return Task.FromResult(new History()); + return Task.FromResult(History.Empty); } public Task> GetIoBrokerHistoriesRange(long id, string dt, string dt2) { - if (IInstanceContainer.Instance.DeviceManager.Devices.TryGetValue(id, out Device? device) ) + if (IInstanceContainer.Instance.DeviceManager.Devices.TryGetValue(id, out Device? device)) { return device.GetHistory(DateTime.Parse(dt), DateTime.Parse(dt2)); } @@ -126,40 +131,21 @@ public Task> GetIoBrokerHistoriesRange(long id, string dt, string return Task.FromResult(new List()); } - // TODO: remove list, just return one item - public virtual async Task> GetIoBrokerHistoryRange(long id, string dt, string dt2, string propertyName) + public virtual async Task GetIoBrokerHistoryRange(long id, string dt, string dt2, string propertyName) { - if (IInstanceContainer.Instance.DeviceManager.Devices.TryGetValue(id, out Device? device) ) + if (IInstanceContainer.Instance.DeviceManager.Devices.TryGetValue(id, out Device? device)) { - return new List() - { - await device.GetHistory(DateTime.Parse(dt), DateTime.Parse(dt2), propertyName) - }; + return await device.GetHistory(DateTime.Parse(dt), DateTime.Parse(dt2), propertyName) + ; } - return new List(); + return History.Empty; } public List Subscribe(List DeviceIds) { - FieldInfo? proxyFieldInfo = Clients - .Caller - .GetType() - .GetRuntimeFields() - .First(x => x.Name == "_proxy"); - object? singeClientProxy = proxyFieldInfo!.GetValue(Clients.Caller)!; - FieldInfo? singeClientProxyFieldInfo = singeClientProxy - .GetType() - .GetRuntimeFields() - .First(x => x.Name == "_proxy"); - object? proxy = singeClientProxyFieldInfo!.GetValue(singeClientProxy)!; - FieldInfo? highlightedItemProperty = - proxy - .GetType() - .GetRuntimeFields() - .First(pi => pi.Name == "_connectionId"); - string connectionId = (string)highlightedItemProperty.GetValue(proxy)!; + string connectionId = Context.ConnectionId; var devices = new List(); string? subMessage = "User subscribed to "; foreach (long deviceId in DeviceIds) @@ -182,23 +168,11 @@ public List Subscribe(List DeviceIds) public void Unsubscribe(List DeviceIds) { - FieldInfo? proxyFieldInfo = Clients - .Caller - .GetType() - .GetRuntimeFields() - .First(x => x.Name == "_proxy"); - object? proxy = proxyFieldInfo!.GetValue(Clients.Caller)!; - FieldInfo? highlightedItemProperty = - proxy - .GetType() - .GetRuntimeFields() - .First(pi => pi.Name == "_connectionId"); - string connectionId = (string)highlightedItemProperty.GetValue(proxy)!; + string connectionId = Context.ConnectionId; var devices = new List(); string? subMessage = "User unsubscribed from "; foreach (long deviceId in DeviceIds) { - if (IInstanceContainer.Instance.DeviceManager.Devices.TryGetValue(deviceId, out Device? device)) { @@ -226,7 +200,6 @@ public void UpdateTime() public DeviceLayout? GetDeviceLayoutByDeviceId(long id) => DeviceLayoutService.GetDeviceLayout(id)?.layout; public List GetAllDeviceLayouts() => DeviceLayoutService.GetAllLayouts(); - public record LayoutNameWithHash(string Name, string Hash); public LayoutNameWithHash? GetDeviceLayoutHashByDeviceId(long id) { @@ -238,6 +211,14 @@ public record LayoutNameWithHash(string Name, string Hash); return new(layoutHash.Value.layout.UniqueName, layoutHash.Value.hash); } + public IEnumerable> GetAppConfig() + { + var loader = IInstanceContainer.Instance.GetDynamic(); + return loader.AppConfigurators.Select(x => x.GetConfigs()).Where(x => x is not null).SelectMany(x => x!); + } + + + //public DashboardDeviceLayout? GetDashboardDeviceLayoutByName(string typename) => DeviceLayoutService.GetDashboardDeviceLayout(typename); //public DashboardDeviceLayout? GetDashboardDeviceLayoutByDeviceId(long id) => DeviceLayoutService.GetDashboardDeviceLayout(id); //public DetailDeviceLayout? GetDetailDeviceLayoutByName(string typename) => DeviceLayoutService.GetDetailDeviceLayout(typename); diff --git a/AppBrokerASP/Startup.cs b/AppBrokerASP/Startup.cs index 18385a4..8de1114 100644 --- a/AppBrokerASP/Startup.cs +++ b/AppBrokerASP/Startup.cs @@ -13,9 +13,6 @@ using AppBroker.Core.Javascript; using AppBroker.Core; using AppBrokerASP.Plugins; -using MQTTnet.Server; -using MQTTnet; -using Newtonsoft.Json; namespace AppBrokerASP; @@ -46,7 +43,10 @@ public void ConfigureServices(IServiceCollection services) }); var signalRBuilder = services.AddSignalR( - opt => opt.EnableDetailedErrors = true + opt => + { + opt.EnableDetailedErrors = true; + } ) .AddNewtonsoftJsonProtocol(); @@ -74,7 +74,7 @@ public void ConfigureServices(IServiceCollection services) if (elsaSection.GetValue("Enabled", true)) { _ = services - .AddElsa(options => options + .AddElsaCore(options => options .UseEntityFrameworkPersistence(ef => ef.UseSqlite()) .AddConsoleActivities() .AddHttpActivities(elsaSection.GetSection("Server").Bind) @@ -90,8 +90,10 @@ public void ConfigureServices(IServiceCollection services) ) .AddJavaScriptTypeDefinitionProvider() .AddJavaScriptTypeDefinitionProvider() - .AddNotificationHandlersFrom() - .AddNotificationHandlersFrom(); + //.AddNotificationHandlersFrom() + //.AddNotificationHandlersFrom() + //; + ; _ = services .AddElsaApiEndpoints(); diff --git a/DbMigrator/DbMigrator.csproj b/DbMigrator/DbMigrator.csproj index 3e322fd..c66119b 100644 --- a/DbMigrator/DbMigrator.csproj +++ b/DbMigrator/DbMigrator.csproj @@ -2,25 +2,25 @@ Exe - net7.0 + net8.0 True - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + - - - + + + diff --git a/IoBrokerHistoryImporter/IoBrokerHistoryImporter.csproj b/IoBrokerHistoryImporter/IoBrokerHistoryImporter.csproj index b5ef5c1..192ccdb 100644 --- a/IoBrokerHistoryImporter/IoBrokerHistoryImporter.csproj +++ b/IoBrokerHistoryImporter/IoBrokerHistoryImporter.csproj @@ -2,19 +2,19 @@ Exe - net7.0 + net8.0 enable enable - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/TcpProxy/TcpProxy.csproj b/TcpProxy/TcpProxy.csproj index f26c19b..57ff3df 100644 --- a/TcpProxy/TcpProxy.csproj +++ b/TcpProxy/TcpProxy.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 enable enable Linux @@ -17,8 +17,8 @@ - - + + diff --git a/TestGenerator/TestGenerator.csproj b/TestGenerator/TestGenerator.csproj index 0b47cb3..22c905b 100644 --- a/TestGenerator/TestGenerator.csproj +++ b/TestGenerator/TestGenerator.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 enable diff --git a/TranslateTTMToHumanReadable/TranslateTTMToHumanReadable.csproj b/TranslateTTMToHumanReadable/TranslateTTMToHumanReadable.csproj index 5657feb..a97540f 100644 --- a/TranslateTTMToHumanReadable/TranslateTTMToHumanReadable.csproj +++ b/TranslateTTMToHumanReadable/TranslateTTMToHumanReadable.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 true @@ -14,4 +14,8 @@ preview + + + + From 31e229831cab40570d5a47ec347e507dd422e15d Mon Sep 17 00:00:00 2001 From: susch19 Date: Sun, 19 May 2024 17:21:30 +0200 Subject: [PATCH 2/2] Moved SocketIO into io broker plugin * since it is only used by this plugin and shouldn't be in the main app broker project * fixed SocketIO now beeing also a namepsace, so having to fully qualify the SocketIO name * fixed errors that happened during master rebase --- .github/workflows/main.yml | 32 ++++----- .github/workflows/manual.yml | 32 ++++----- .../AppBroker.Generators.csproj | 1 - AppBroker.IOBroker/AppBroker.IOBroker.csproj | 30 +++++--- AppBroker.IOBroker/Devices/Dummy.cs | 4 +- AppBroker.IOBroker/Devices/FloaltPanel.cs | 4 +- AppBroker.IOBroker/Devices/LumiRouter.cs | 4 +- AppBroker.IOBroker/Devices/OsramB40RW.cs | 4 +- AppBroker.IOBroker/Devices/OsramPlug.cs | 3 +- AppBroker.IOBroker/Devices/OsvallaPanel.cs | 6 +- .../Devices/TradfriControlOutlet.cs | 4 +- AppBroker.IOBroker/Devices/TradfriLedBulb.cs | 4 +- .../Devices/TradfriMotionSensor.cs | 4 +- .../Devices/TradfriRemoteControl.cs | 4 +- .../Devices/TuyaSwitchSensor.cs | 5 +- .../Devices/UpdateableZigbeeDevice.cs | 4 +- .../Devices/XiaomiTempSensor.cs | 4 +- .../Devices/ZigbeeContactSensor.cs | 4 +- AppBroker.IOBroker/Devices/ZigbeeDevice.cs | 39 +++++----- AppBroker.IOBroker/Devices/ZigbeeLamp.cs | 5 +- AppBroker.IOBroker/Devices/ZigbeeSwitch.cs | 4 +- AppBroker.IOBroker/Extensions.cs | 27 +++++++ AppBroker.IOBroker/IoBrokerManager.cs | 13 ++-- .../AppBroker.PainlessMesh.Elsa.csproj | 1 - .../Controller/PainlessController.cs | 15 ---- .../Devices/Painless/LedStrip.cs | 2 - .../PainlessMeshMqttManager.cs | 1 - .../SmarthomeMeshManager.cs | 1 - AppBroker.Zigbee2Mqtt/Devices/OsramPlug.cs | 1 - .../Devices/TradfriMotionSensor.cs | 1 - .../Devices/TradfriRemoteControl.cs | 1 - .../Devices/XiaomiTempSensor.cs | 1 - .../Devices/Zigbee2MqttDevice.cs | 1 - .../Devices/ZigbeeContactSensor.cs | 1 - AppBroker.Zigbee2Mqtt/Zigbee2MqttManager.cs | 12 ++-- AppBroker.sln | 11 --- AppBrokerASP/AppBrokerASP.csproj | 13 ++-- AppBrokerASP/Controllers/DevicesController.cs | 4 +- AppBrokerASP/Dockerfile | 11 +-- AppBrokerASP/Extension/Extensions.cs | 23 +----- AppBrokerASP/InstanceContainer.cs | 3 +- .../NewtonsoftJsonSmarthomeHubProtocol.cs | 1 - AppBrokerASP/Smarthome.cs | 7 -- AppBrokerASP/Startup.cs | 34 --------- AppBrokerASP/State/DeviceStateManager.cs | 1 - AppBrokerASP/TestWorkflow.cs | 71 ------------------- DbMigrator/Program.cs | 23 +----- 47 files changed, 137 insertions(+), 344 deletions(-) create mode 100644 AppBroker.IOBroker/Extensions.cs delete mode 100644 AppBrokerASP/TestWorkflow.cs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 584bae0..d4f8504 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,17 +20,14 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - with: - platforms: 'amd64,arm,arm64' + - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Get Git Submodules run: git submodule update --init --recursive - name: Log in to the Container registry - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -38,28 +35,27 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + uses: docker/metadata-action@v5 with: images: | ${{ env.REGISTRY }}/${{ env.REPO_NAME }} - name: Build AppBroker and push Docker image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + uses: docker/build-push-action@v5 with: context: . - platforms: linux/amd64,linux/arm/v7,linux/arm64 file: AppBrokerASP/Dockerfile push: ${{ github.event_name != 'pull_request' }} tags: ghcr.io/susch19/appbroker:latest labels: ${{ steps.meta.outputs.labels }} - - name: Build TCPProxy and push Docker image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - with: - context: . - platforms: linux/amd64,linux/arm/v7,linux/arm64 - file: TcpProxy/Dockerfile - push: ${{ github.event_name != 'pull_request' }} - tags: ghcr.io/susch19/appbroker-tcpproxy:latest - labels: ${{ steps.meta.outputs.labels }} + # - name: Build TCPProxy and push Docker image + # uses: docker/build-push-action@v5 + # with: + # context: . + # platforms: linux/amd64,linux/arm/v7,linux/arm64 + # file: TcpProxy/Dockerfile + # push: true + # tags: ghcr.io/susch19/appbroker-tcpproxy:${{ github.event.inputs.tag }} + # labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml index 79d7f84..2665e21 100644 --- a/.github/workflows/manual.yml +++ b/.github/workflows/manual.yml @@ -22,17 +22,14 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - with: - platforms: 'amd64,arm,arm64' + - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Get Git Submodules run: git submodule update --init --recursive - name: Log in to the Container registry - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -40,29 +37,28 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + uses: docker/metadata-action@v5 with: images: | ${{ env.REGISTRY }}/${{ env.REPO_NAME }} - name: Build AppBroker and push Docker image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + uses: docker/build-push-action@v5 with: context: . - platforms: linux/amd64,linux/arm/v7,linux/arm64 file: AppBrokerASP/Dockerfile push: true tags: ghcr.io/susch19/appbroker:${{ github.event.inputs.tag }} labels: ${{ steps.meta.outputs.labels }} - - name: Build TCPProxy and push Docker image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - with: - context: . - platforms: linux/amd64,linux/arm/v7,linux/arm64 - file: TcpProxy/Dockerfile - push: true - tags: ghcr.io/susch19/appbroker-tcpproxy:${{ github.event.inputs.tag }} - labels: ${{ steps.meta.outputs.labels }} + # - name: Build TCPProxy and push Docker image + # uses: docker/build-push-action@v5 + # with: + # context: . + # platforms: linux/amd64,linux/arm/v7,linux/arm64 + # file: TcpProxy/Dockerfile + # push: true + # tags: ghcr.io/susch19/appbroker-tcpproxy:${{ github.event.inputs.tag }} + # labels: ${{ steps.meta.outputs.labels }} diff --git a/AppBroker.Generators/AppBroker.Generators.csproj b/AppBroker.Generators/AppBroker.Generators.csproj index 88a0611..5f9c3f8 100644 --- a/AppBroker.Generators/AppBroker.Generators.csproj +++ b/AppBroker.Generators/AppBroker.Generators.csproj @@ -32,7 +32,6 @@ - diff --git a/AppBroker.IOBroker/AppBroker.IOBroker.csproj b/AppBroker.IOBroker/AppBroker.IOBroker.csproj index d919821..f837d00 100644 --- a/AppBroker.IOBroker/AppBroker.IOBroker.csproj +++ b/AppBroker.IOBroker/AppBroker.IOBroker.csproj @@ -1,15 +1,25 @@ - + - - net8.0 - enable - enable - + + net8.0 + enable + enable + - - - - + + + + + + + + + + + + + + diff --git a/AppBroker.IOBroker/Devices/Dummy.cs b/AppBroker.IOBroker/Devices/Dummy.cs index 9875c2f..e060ece 100644 --- a/AppBroker.IOBroker/Devices/Dummy.cs +++ b/AppBroker.IOBroker/Devices/Dummy.cs @@ -1,13 +1,11 @@ using AppBroker.Core.Devices; -using SocketIOClient; - namespace AppBroker.IOBroker.Devices; [DeviceName("SPZB0001")] public class Dummy : UpdateableZigbeeDevice { - public Dummy(long nodeId, SocketIO socket) : base(nodeId, socket, nameof(Dummy)) + public Dummy(long nodeId, SocketIOClient.SocketIO socket) : base(nodeId, socket, nameof(Dummy)) { } } diff --git a/AppBroker.IOBroker/Devices/FloaltPanel.cs b/AppBroker.IOBroker/Devices/FloaltPanel.cs index 9065fad..99a0ea7 100644 --- a/AppBroker.IOBroker/Devices/FloaltPanel.cs +++ b/AppBroker.IOBroker/Devices/FloaltPanel.cs @@ -1,13 +1,11 @@ using AppBroker.Core.Devices; -using SocketIOClient; - namespace AppBroker.IOBroker.Devices; [DeviceName("FLOALT panel WS 60x60", "L1529", "T2011")] public class FloaltPanel : ZigbeeLamp { - public FloaltPanel(long nodeId, SocketIO socket) : base(nodeId, socket, nameof(FloaltPanel)) + public FloaltPanel(long nodeId, SocketIOClient.SocketIO socket) : base(nodeId, socket, nameof(FloaltPanel)) { } diff --git a/AppBroker.IOBroker/Devices/LumiRouter.cs b/AppBroker.IOBroker/Devices/LumiRouter.cs index 88d9046..cb58ae9 100644 --- a/AppBroker.IOBroker/Devices/LumiRouter.cs +++ b/AppBroker.IOBroker/Devices/LumiRouter.cs @@ -1,13 +1,11 @@ using AppBroker.Core.Devices; -using SocketIOClient; - namespace AppBroker.IOBroker.Devices; [DeviceName("lumi.router")] public class LumiRouter : ZigbeeDevice { - public LumiRouter(long nodeId, SocketIO socket) : base(nodeId, socket, nameof(LumiRouter)) + public LumiRouter(long nodeId, SocketIOClient.SocketIO socket) : base(nodeId, socket, nameof(LumiRouter)) { ShowInApp = false; } diff --git a/AppBroker.IOBroker/Devices/OsramB40RW.cs b/AppBroker.IOBroker/Devices/OsramB40RW.cs index 37f6cd2..ed55003 100644 --- a/AppBroker.IOBroker/Devices/OsramB40RW.cs +++ b/AppBroker.IOBroker/Devices/OsramB40RW.cs @@ -1,13 +1,11 @@ using AppBroker.Core.Devices; -using SocketIOClient; - namespace AppBroker.IOBroker.Devices; [DeviceName("Classic B40 TW - LIGHTIFY", "AB32840")] public class OsramB40RW : ZigbeeLamp { - public OsramB40RW(long nodeId, SocketIO socket) : base(nodeId, socket, nameof(OsramB40RW)) + public OsramB40RW(long nodeId, SocketIOClient.SocketIO socket) : base(nodeId, socket, nameof(OsramB40RW)) { } } diff --git a/AppBroker.IOBroker/Devices/OsramPlug.cs b/AppBroker.IOBroker/Devices/OsramPlug.cs index ef4cfa2..598ff21 100644 --- a/AppBroker.IOBroker/Devices/OsramPlug.cs +++ b/AppBroker.IOBroker/Devices/OsramPlug.cs @@ -1,13 +1,12 @@ using AppBroker.Core.Devices; -using SocketIOClient; namespace AppBroker.IOBroker.Devices; [DeviceName("Plug 01", "AB3257001NJ")] public class OsramPlug : ZigbeeSwitch { - public OsramPlug(long nodeId, SocketIO socket) : base(nodeId, socket, nameof(OsramPlug)) + public OsramPlug(long nodeId, SocketIOClient.SocketIO socket) : base(nodeId, socket, nameof(OsramPlug)) { ShowInApp = true; } diff --git a/AppBroker.IOBroker/Devices/OsvallaPanel.cs b/AppBroker.IOBroker/Devices/OsvallaPanel.cs index 64e47dd..50f6776 100644 --- a/AppBroker.IOBroker/Devices/OsvallaPanel.cs +++ b/AppBroker.IOBroker/Devices/OsvallaPanel.cs @@ -1,11 +1,9 @@ -using SocketIOClient; - -namespace AppBroker.IOBroker.Devices; +namespace AppBroker.IOBroker.Devices; //[DeviceName("T2011")] public class OsvallaPanel : ZigbeeLamp { - public OsvallaPanel(long nodeId, SocketIO socket) : base(nodeId, socket, nameof(OsvallaPanel)) + public OsvallaPanel(long nodeId, SocketIOClient.SocketIO socket) : base(nodeId, socket, nameof(OsvallaPanel)) { } } diff --git a/AppBroker.IOBroker/Devices/TradfriControlOutlet.cs b/AppBroker.IOBroker/Devices/TradfriControlOutlet.cs index 9a1c521..850107e 100644 --- a/AppBroker.IOBroker/Devices/TradfriControlOutlet.cs +++ b/AppBroker.IOBroker/Devices/TradfriControlOutlet.cs @@ -1,13 +1,11 @@ using AppBroker.Core.Devices; -using SocketIOClient; - namespace AppBroker.IOBroker.Devices; [DeviceName("E1603/E1702")] public class TradfriControlOutlet : ZigbeeSwitch { - public TradfriControlOutlet(long nodeId, SocketIO socket) : base(nodeId, socket, nameof(TradfriControlOutlet)) + public TradfriControlOutlet(long nodeId, SocketIOClient.SocketIO socket) : base(nodeId, socket, nameof(TradfriControlOutlet)) { } } diff --git a/AppBroker.IOBroker/Devices/TradfriLedBulb.cs b/AppBroker.IOBroker/Devices/TradfriLedBulb.cs index f9b70d2..cabdfe1 100644 --- a/AppBroker.IOBroker/Devices/TradfriLedBulb.cs +++ b/AppBroker.IOBroker/Devices/TradfriLedBulb.cs @@ -1,13 +1,11 @@ using AppBroker.Core.Devices; -using SocketIOClient; - namespace AppBroker.IOBroker.Devices; [DeviceName("TRADFRI bulb E27 CWS opal 600lm", "TRADFRI bulb E14 CWS opal 600lm", "LED1624G9")] public partial class TradfriLedBulb : ZigbeeLamp { - public TradfriLedBulb(long nodeId, SocketIO socket) : + public TradfriLedBulb(long nodeId, SocketIOClient.SocketIO socket) : base(nodeId, socket, nameof(TradfriLedBulb)) { ShowInApp = true; diff --git a/AppBroker.IOBroker/Devices/TradfriMotionSensor.cs b/AppBroker.IOBroker/Devices/TradfriMotionSensor.cs index ac8a3d1..2f7f4d9 100644 --- a/AppBroker.IOBroker/Devices/TradfriMotionSensor.cs +++ b/AppBroker.IOBroker/Devices/TradfriMotionSensor.cs @@ -1,14 +1,12 @@ using AppBroker.Core.Devices; -using SocketIOClient; - namespace AppBroker.IOBroker.Devices; [DeviceName("E1525/E1745")] public partial class TradfriMotionSensor : ZigbeeDevice { - public TradfriMotionSensor(long nodeId, SocketIO socket) : base(nodeId, socket, nameof(TradfriMotionSensor)) + public TradfriMotionSensor(long nodeId, SocketIOClient.SocketIO socket) : base(nodeId, socket, nameof(TradfriMotionSensor)) { ShowInApp = true; } diff --git a/AppBroker.IOBroker/Devices/TradfriRemoteControl.cs b/AppBroker.IOBroker/Devices/TradfriRemoteControl.cs index 202e480..a3f8522 100644 --- a/AppBroker.IOBroker/Devices/TradfriRemoteControl.cs +++ b/AppBroker.IOBroker/Devices/TradfriRemoteControl.cs @@ -1,13 +1,11 @@ using AppBroker.Core.Devices; -using SocketIOClient; - namespace AppBroker.IOBroker.Devices; [DeviceName("TRADFRI remote control", "E1524/E1810")] public class TradfriRemoteControl : ZigbeeDevice { - public TradfriRemoteControl(long nodeId, SocketIO socket) : base(nodeId, socket, nameof(TradfriRemoteControl)) + public TradfriRemoteControl(long nodeId, SocketIOClient.SocketIO socket) : base(nodeId, socket, nameof(TradfriRemoteControl)) { ShowInApp = false; } diff --git a/AppBroker.IOBroker/Devices/TuyaSwitchSensor.cs b/AppBroker.IOBroker/Devices/TuyaSwitchSensor.cs index 049307e..14115cc 100644 --- a/AppBroker.IOBroker/Devices/TuyaSwitchSensor.cs +++ b/AppBroker.IOBroker/Devices/TuyaSwitchSensor.cs @@ -1,5 +1,4 @@ -using SocketIOClient; -using AppBroker.Core.Models; +using AppBroker.Core.Models; using AppBroker.Core.Devices; namespace AppBroker.IOBroker.Devices; @@ -8,7 +7,7 @@ namespace AppBroker.IOBroker.Devices; public partial class TuyaSwitchSensor : ZigbeeSwitch { - public TuyaSwitchSensor(long nodeId, SocketIO socket) : base(nodeId, socket, nameof(TuyaSwitchSensor)) + public TuyaSwitchSensor(long nodeId, SocketIOClient.SocketIO socket) : base(nodeId, socket, nameof(TuyaSwitchSensor)) { ShowInApp = true; } diff --git a/AppBroker.IOBroker/Devices/UpdateableZigbeeDevice.cs b/AppBroker.IOBroker/Devices/UpdateableZigbeeDevice.cs index d85adc9..0fc5d3e 100644 --- a/AppBroker.IOBroker/Devices/UpdateableZigbeeDevice.cs +++ b/AppBroker.IOBroker/Devices/UpdateableZigbeeDevice.cs @@ -4,13 +4,11 @@ using NiL.JS.Core; -using SocketIOClient; - namespace AppBroker.IOBroker.Devices; public class UpdateableZigbeeDevice : ZigbeeDevice { - public UpdateableZigbeeDevice(long nodeId, SocketIO socket, string typeName) : + public UpdateableZigbeeDevice(long nodeId, SocketIOClient.SocketIO socket, string typeName) : base(nodeId, socket, typeName) { diff --git a/AppBroker.IOBroker/Devices/XiaomiTempSensor.cs b/AppBroker.IOBroker/Devices/XiaomiTempSensor.cs index 401e87e..146ce46 100644 --- a/AppBroker.IOBroker/Devices/XiaomiTempSensor.cs +++ b/AppBroker.IOBroker/Devices/XiaomiTempSensor.cs @@ -1,7 +1,5 @@ using AppBroker.Core.Devices; -using SocketIOClient; - namespace AppBroker.IOBroker.Devices; [DeviceName("lumi.weather", "WSDCGQ11LM")] @@ -9,7 +7,7 @@ namespace AppBroker.IOBroker.Devices; public partial class XiaomiTempSensor : ZigbeeDevice { - public XiaomiTempSensor(long id, SocketIO socket) : base(id, socket, nameof(XiaomiTempSensor)) + public XiaomiTempSensor(long id, SocketIOClient.SocketIO socket) : base(id, socket, nameof(XiaomiTempSensor)) { ShowInApp = true; } diff --git a/AppBroker.IOBroker/Devices/ZigbeeContactSensor.cs b/AppBroker.IOBroker/Devices/ZigbeeContactSensor.cs index a9b2135..d811ab0 100644 --- a/AppBroker.IOBroker/Devices/ZigbeeContactSensor.cs +++ b/AppBroker.IOBroker/Devices/ZigbeeContactSensor.cs @@ -1,14 +1,12 @@ using AppBroker.Core.Devices; -using SocketIOClient; - namespace AppBroker.IOBroker.Devices; [DeviceName("MCCGQ11LM")] public partial class ZigbeeContactSensor : ZigbeeDevice { - public ZigbeeContactSensor(long nodeId, SocketIO socket) : base(nodeId, socket, nameof(ZigbeeContactSensor)) + public ZigbeeContactSensor(long nodeId, SocketIOClient.SocketIO socket) : base(nodeId, socket, nameof(ZigbeeContactSensor)) { ShowInApp = true; } diff --git a/AppBroker.IOBroker/Devices/ZigbeeDevice.cs b/AppBroker.IOBroker/Devices/ZigbeeDevice.cs index ed08e92..6d9e0b4 100644 --- a/AppBroker.IOBroker/Devices/ZigbeeDevice.cs +++ b/AppBroker.IOBroker/Devices/ZigbeeDevice.cs @@ -4,24 +4,18 @@ using AppBrokerASP; using AppBrokerASP.Devices; -using AppBrokerASP.Extension; - using Newtonsoft.Json; -using SocketIOClient.Transport; - using System.Collections.ObjectModel; using System.Reflection; using System.Text.RegularExpressions; -using SocketIo = SocketIOClient.SocketIO; - namespace AppBroker.IOBroker.Devices; [AppBroker.ClassPropertyChangedAppbroker] public partial class ZigbeeDevice : PropChangedJavaScriptDevice { - protected SocketIo Socket { get; } + protected SocketIOClient.SocketIO Socket { get; } public bool Available { @@ -61,7 +55,7 @@ public string LastReceivedFormatted [AppBroker.IgnoreField] private bool available; - public ZigbeeDevice(long nodeId, SocketIo socket, string typeName) : base(nodeId, typeName, new FileInfo(Path.Combine("JSExtensionDevices", typeName + ".js"))) + public ZigbeeDevice(long nodeId, SocketIOClient.SocketIO socket, string typeName) : base(nodeId, typeName, new FileInfo(Path.Combine("JSExtensionDevices", typeName + ".js"))) { TypeName = typeName; Socket = socket; @@ -84,7 +78,7 @@ public string LastReceivedFormatted .ToArray()); } - public ZigbeeDevice(long nodeId, SocketIo socket) : base(nodeId, null, null) + public ZigbeeDevice(long nodeId, SocketIOClient.SocketIO socket) : base(nodeId, null, null) { Socket = socket; @@ -278,20 +272,19 @@ private async Task GetHistoryRecords(DateTimeOffset start, Date var i = AdapterWithId + "." + type.ToLower(); var endMs = end.ToUnixTimeMilliseconds(); - return Array.Empty(); - //var history = await Socket.EmitAsync("getHistory", - // i, - // new - // { - // id = i, // probably not necessary to put it here again - // start = start.ToUnixTimeMilliseconds(), - // //end = end.ToUnixTimeMilliseconds(), - // ignoreNull = true, - // aggregate = "none", - // count = 2000 - // }); - - //return history is null ? Array.Empty() : history.GetValue(1).Where(x => x.Ts < endMs).ToArray(); + var history = await Socket.Emit("getHistory", + i, + new + { + id = i, // probably not necessary to put it here again + start = start.ToUnixTimeMilliseconds(), + //end = end.ToUnixTimeMilliseconds(), + ignoreNull = true, + aggregate = "none", + count = 2000 + }); + + return history is null ? Array.Empty() : history.GetValue(1).Where(x => x.Ts < endMs).ToArray(); } } diff --git a/AppBroker.IOBroker/Devices/ZigbeeLamp.cs b/AppBroker.IOBroker/Devices/ZigbeeLamp.cs index 4c50236..d9d2c94 100644 --- a/AppBroker.IOBroker/Devices/ZigbeeLamp.cs +++ b/AppBroker.IOBroker/Devices/ZigbeeLamp.cs @@ -2,16 +2,13 @@ using Newtonsoft.Json.Linq; - -using SocketIOClient; - namespace AppBroker.IOBroker.Devices; public abstract partial class ZigbeeLamp : UpdateableZigbeeDevice { - public ZigbeeLamp(long nodeId, SocketIO socket, string typeName) : base(nodeId, socket, typeName) + public ZigbeeLamp(long nodeId, SocketIOClient.SocketIO socket, string typeName) : base(nodeId, socket, typeName) { ShowInApp = true; } diff --git a/AppBroker.IOBroker/Devices/ZigbeeSwitch.cs b/AppBroker.IOBroker/Devices/ZigbeeSwitch.cs index 8eb90ac..446412c 100644 --- a/AppBroker.IOBroker/Devices/ZigbeeSwitch.cs +++ b/AppBroker.IOBroker/Devices/ZigbeeSwitch.cs @@ -2,14 +2,12 @@ using Newtonsoft.Json.Linq; -using SocketIOClient; - namespace AppBroker.IOBroker.Devices; public abstract partial class ZigbeeSwitch : UpdateableZigbeeDevice { - protected ZigbeeSwitch(long nodeId, SocketIO socket, string typeName) : base(nodeId, socket, typeName) + protected ZigbeeSwitch(long nodeId, SocketIOClient.SocketIO socket, string typeName) : base(nodeId, socket, typeName) { ShowInApp = true; } diff --git a/AppBroker.IOBroker/Extensions.cs b/AppBroker.IOBroker/Extensions.cs new file mode 100644 index 0000000..73e4e19 --- /dev/null +++ b/AppBroker.IOBroker/Extensions.cs @@ -0,0 +1,27 @@ +using SocketIOClient; + +namespace AppBroker.IOBroker; +public static class Extensions +{ + + public static async Task Emit(this SocketIOClient.SocketIO socket, string eventName, params object[] data) + { + var task = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + await socket.EmitAsync(eventName, response => + { + try + { + task.SetResult(response); + } + catch (Exception ex) + { + task.SetException(ex); + } + }, data); + + // Ensure follwoing tasks will run async + await Task.Yield(); + + return await task.Task; + } +} diff --git a/AppBroker.IOBroker/IoBrokerManager.cs b/AppBroker.IOBroker/IoBrokerManager.cs index 5e58406..2baa7b3 100644 --- a/AppBroker.IOBroker/IoBrokerManager.cs +++ b/AppBroker.IOBroker/IoBrokerManager.cs @@ -1,18 +1,17 @@ using Newtonsoft.Json.Linq; using Newtonsoft.Json; -using AppBrokerASP.Extension; -using SocketIOClient; using AppBroker.Core.Devices; using NonSucking.Framework.Extension.Threading; using AppBroker.Core.Database; using AppBroker.Core; using AppBroker.IOBroker.Devices; +using SocketIO.Core; namespace AppBroker.IOBroker; public class IoBrokerManager { - private SocketIO? client; + private SocketIOClient.SocketIO? client; private readonly NLog.Logger logger; private readonly ZigbeeConfig config; private static readonly HttpClient http = new(); @@ -25,7 +24,7 @@ public IoBrokerManager(NLog.Logger logger, ZigbeeConfig config) public async Task ConnectToIOBroker() { - client = new SocketIO(new Uri(config.SocketIOUrl), new SocketIOOptions() + client = new SocketIOClient.SocketIO(new Uri(config.SocketIOUrl), new SocketIOClient.SocketIOOptions() { EIO = config.NewSocketIoversion ? EngineIO.V4 : EngineIO.V3 }); @@ -89,7 +88,7 @@ public async Task ConnectToIOBroker() await client.ConnectAsync(); } - public async Task GetZigbeeDevices(SocketIO socket) + public async Task GetZigbeeDevices(SocketIOClient.SocketIO socket) { if (client is null) { @@ -98,7 +97,7 @@ public async Task GetZigbeeDevices(SocketIO socket) } var allObjectsResponse = await socket.Emit("getObjects"); - var allObjectscontentNew = allObjectsResponse?.GetValue(1).ToString(); + var allObjectscontentNew = allObjectsResponse?.GetValue(1); if (allObjectscontentNew is null) { @@ -207,7 +206,7 @@ public async Task GetZigbeeDevices(SocketIO socket) foreach (var item in deviceStates.Where(x => x._id.Contains(deviceRes.native.id))) { - var ioObject = new IoBrokerObject(BrokerEvent.StateChange, "", 0, item._id[(item._id.LastIndexOf(".") + 1)..], new Parameter(item.val)); + var ioObject = new IoBrokerObject(BrokerEvent.StateChange, "", 0, item._id[(item._id.LastIndexOf('.') + 1)..], new Parameter(item.val)); if (ioObject.ValueName == "msg_from_zigbee" || ioObject.ValueName == "device_query") continue; diff --git a/AppBroker.PainlessMesh.Elsa/AppBroker.PainlessMesh.Elsa.csproj b/AppBroker.PainlessMesh.Elsa/AppBroker.PainlessMesh.Elsa.csproj index b22a391..fe70022 100644 --- a/AppBroker.PainlessMesh.Elsa/AppBroker.PainlessMesh.Elsa.csproj +++ b/AppBroker.PainlessMesh.Elsa/AppBroker.PainlessMesh.Elsa.csproj @@ -20,7 +20,6 @@ - diff --git a/AppBroker.PainlessMesh/Controller/PainlessController.cs b/AppBroker.PainlessMesh/Controller/PainlessController.cs index a2f5630..e2431b2 100644 --- a/AppBroker.PainlessMesh/Controller/PainlessController.cs +++ b/AppBroker.PainlessMesh/Controller/PainlessController.cs @@ -1,22 +1,7 @@ using AppBroker.Core; -using AppBroker.Core.Devices; -using AppBroker.Core.Javascript; -using AppBroker.Core.Managers; - -using AppBrokerASP.Cloud; -using AppBrokerASP.Configuration; -using AppBrokerASP.Devices; - -using Elsa.Server.Api.Attributes; using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -using System.Security.Cryptography; -using System.Text; -using System.Text.Json; namespace AppBroker.PainlessMesh; [Route("painless")] diff --git a/AppBroker.PainlessMesh/Devices/Painless/LedStrip.cs b/AppBroker.PainlessMesh/Devices/Painless/LedStrip.cs index 2afd0cb..1c208a8 100644 --- a/AppBroker.PainlessMesh/Devices/Painless/LedStrip.cs +++ b/AppBroker.PainlessMesh/Devices/Painless/LedStrip.cs @@ -8,8 +8,6 @@ using System.Threading.Tasks; using System.Runtime.CompilerServices; -using Namotion.Reflection; -using Newtonsoft.Json; namespace AppBrokerASP.Devices.Painless; diff --git a/AppBroker.PainlessMesh/PainlessMeshMqttManager.cs b/AppBroker.PainlessMesh/PainlessMeshMqttManager.cs index 25819d9..446f856 100644 --- a/AppBroker.PainlessMesh/PainlessMeshMqttManager.cs +++ b/AppBroker.PainlessMesh/PainlessMeshMqttManager.cs @@ -12,7 +12,6 @@ using NLog; -using SocketIOClient.Transport; using System; using System.Collections.Generic; diff --git a/AppBroker.PainlessMesh/SmarthomeMeshManager.cs b/AppBroker.PainlessMesh/SmarthomeMeshManager.cs index a8f4407..2f794c4 100644 --- a/AppBroker.PainlessMesh/SmarthomeMeshManager.cs +++ b/AppBroker.PainlessMesh/SmarthomeMeshManager.cs @@ -2,7 +2,6 @@ using AppBrokerASP.Devices.Painless; -using Fluid.Ast.BinaryExpressions; using Newtonsoft.Json; diff --git a/AppBroker.Zigbee2Mqtt/Devices/OsramPlug.cs b/AppBroker.Zigbee2Mqtt/Devices/OsramPlug.cs index 009aa0f..ea9dea4 100644 --- a/AppBroker.Zigbee2Mqtt/Devices/OsramPlug.cs +++ b/AppBroker.Zigbee2Mqtt/Devices/OsramPlug.cs @@ -1,6 +1,5 @@ using AppBroker.Core.Devices; -using SocketIOClient; namespace AppBroker.Zigbee2Mqtt.Devices; diff --git a/AppBroker.Zigbee2Mqtt/Devices/TradfriMotionSensor.cs b/AppBroker.Zigbee2Mqtt/Devices/TradfriMotionSensor.cs index b64f8e6..f53f53e 100644 --- a/AppBroker.Zigbee2Mqtt/Devices/TradfriMotionSensor.cs +++ b/AppBroker.Zigbee2Mqtt/Devices/TradfriMotionSensor.cs @@ -1,6 +1,5 @@ using AppBroker.Core.Devices; -using SocketIOClient; namespace AppBroker.Zigbee2Mqtt.Devices; diff --git a/AppBroker.Zigbee2Mqtt/Devices/TradfriRemoteControl.cs b/AppBroker.Zigbee2Mqtt/Devices/TradfriRemoteControl.cs index f3338d6..303f302 100644 --- a/AppBroker.Zigbee2Mqtt/Devices/TradfriRemoteControl.cs +++ b/AppBroker.Zigbee2Mqtt/Devices/TradfriRemoteControl.cs @@ -1,6 +1,5 @@ using AppBroker.Core.Devices; -using SocketIOClient; namespace AppBroker.Zigbee2Mqtt.Devices; diff --git a/AppBroker.Zigbee2Mqtt/Devices/XiaomiTempSensor.cs b/AppBroker.Zigbee2Mqtt/Devices/XiaomiTempSensor.cs index 59cb6d7..be367d2 100644 --- a/AppBroker.Zigbee2Mqtt/Devices/XiaomiTempSensor.cs +++ b/AppBroker.Zigbee2Mqtt/Devices/XiaomiTempSensor.cs @@ -1,7 +1,6 @@ using AppBroker.Core.Devices; using AppBroker.Zigbee2Mqtt; -using SocketIOClient; namespace AppBroker.Zigbee2Mqtt.Devices; diff --git a/AppBroker.Zigbee2Mqtt/Devices/Zigbee2MqttDevice.cs b/AppBroker.Zigbee2Mqtt/Devices/Zigbee2MqttDevice.cs index 6158924..c005180 100644 --- a/AppBroker.Zigbee2Mqtt/Devices/Zigbee2MqttDevice.cs +++ b/AppBroker.Zigbee2Mqtt/Devices/Zigbee2MqttDevice.cs @@ -14,7 +14,6 @@ using NLog; -using Org.BouncyCastle.Asn1.Cmp; namespace AppBroker.Zigbee2Mqtt.Devices; diff --git a/AppBroker.Zigbee2Mqtt/Devices/ZigbeeContactSensor.cs b/AppBroker.Zigbee2Mqtt/Devices/ZigbeeContactSensor.cs index a6b3c3a..edf6b25 100644 --- a/AppBroker.Zigbee2Mqtt/Devices/ZigbeeContactSensor.cs +++ b/AppBroker.Zigbee2Mqtt/Devices/ZigbeeContactSensor.cs @@ -1,6 +1,5 @@ using AppBroker.Core.Devices; -using SocketIOClient; namespace AppBroker.Zigbee2Mqtt.Devices; diff --git a/AppBroker.Zigbee2Mqtt/Zigbee2MqttManager.cs b/AppBroker.Zigbee2Mqtt/Zigbee2MqttManager.cs index 55e22b7..c039350 100644 --- a/AppBroker.Zigbee2Mqtt/Zigbee2MqttManager.cs +++ b/AppBroker.Zigbee2Mqtt/Zigbee2MqttManager.cs @@ -10,12 +10,13 @@ using AppBroker.Core.Database; using AppBrokerASP; -using ZigbeeConfig = AppBroker.Zigbee2Mqtt.Zigbee2MqttConfig; using AppBroker.Zigbee2Mqtt.Devices; using System.Diagnostics.CodeAnalysis; using AppBroker.Core.Devices; using AppBroker.Core.DynamicUI; +using ZigbeeConfig = AppBroker.Zigbee2Mqtt.Zigbee2MqttConfig; + namespace AppBroker.Zigbee2Mqtt; public class Zigbee2MqttManager : IAsyncDisposable @@ -253,11 +254,10 @@ private void TryInterpretTopicAsStateUpdate(string deviceName, string payload) .DeviceStateManager .SetMultipleStates(id, ReplaceCustomStates(id, JsonConvert.DeserializeObject>(payload)!)); - InstanceContainer - .Instance - .DeviceStateManager - .SetSingleState(id, "lastReceived", DateTime.UtcNow); - } + InstanceContainer + .Instance + .DeviceStateManager + .SetSingleState(id, "lastReceived", DateTime.UtcNow); } } diff --git a/AppBroker.sln b/AppBroker.sln index 3432802..ad4e22b 100644 --- a/AppBroker.sln +++ b/AppBroker.sln @@ -15,8 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestGenerator", "TestGenera EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppBroker.Generators.Test", "AppBroker.Generators.Test\AppBroker.Generators.Test.csproj", "{A553ED81-487F-49A0-8ACB-DD49BEBBCA48}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppBroker.Elsa", "AppBroker.Elsa\AppBroker.Elsa.csproj", "{49CD08E7-D07D-4952-B4F7-6FDEBEF37240}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E76B3A29-D64E-4881-BAAE-19D87C124334}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig @@ -102,14 +100,6 @@ Global {A553ED81-487F-49A0-8ACB-DD49BEBBCA48}.Release_Ubuntu|Any CPU.Build.0 = Release|Any CPU {A553ED81-487F-49A0-8ACB-DD49BEBBCA48}.Release|Any CPU.ActiveCfg = Release|Any CPU {A553ED81-487F-49A0-8ACB-DD49BEBBCA48}.Release|Any CPU.Build.0 = Release|Any CPU - {49CD08E7-D07D-4952-B4F7-6FDEBEF37240}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug|Any CPU - {49CD08E7-D07D-4952-B4F7-6FDEBEF37240}.Debug_Ubuntu|Any CPU.Build.0 = Debug|Any CPU - {49CD08E7-D07D-4952-B4F7-6FDEBEF37240}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {49CD08E7-D07D-4952-B4F7-6FDEBEF37240}.Debug|Any CPU.Build.0 = Debug|Any CPU - {49CD08E7-D07D-4952-B4F7-6FDEBEF37240}.Release_Ubuntu|Any CPU.ActiveCfg = Release|Any CPU - {49CD08E7-D07D-4952-B4F7-6FDEBEF37240}.Release_Ubuntu|Any CPU.Build.0 = Release|Any CPU - {49CD08E7-D07D-4952-B4F7-6FDEBEF37240}.Release|Any CPU.ActiveCfg = Release|Any CPU - {49CD08E7-D07D-4952-B4F7-6FDEBEF37240}.Release|Any CPU.Build.0 = Release|Any CPU {6579337A-A00D-4912-839D-F28C3604FD31}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug|Any CPU {6579337A-A00D-4912-839D-F28C3604FD31}.Debug_Ubuntu|Any CPU.Build.0 = Debug|Any CPU {6579337A-A00D-4912-839D-F28C3604FD31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -185,7 +175,6 @@ Global {9410CEB2-5BE1-4BFC-BF8E-7F5EEA30401C} = {5170C7C5-6EB2-4AE9-B17A-FB9A15AF1401} {50833AB1-C7AA-4524-A48D-BD6423020D89} = {46309ADE-8FD9-4291-B1CF-EA44AD5486CF} {A553ED81-487F-49A0-8ACB-DD49BEBBCA48} = {5170C7C5-6EB2-4AE9-B17A-FB9A15AF1401} - {49CD08E7-D07D-4952-B4F7-6FDEBEF37240} = {5170C7C5-6EB2-4AE9-B17A-FB9A15AF1401} {6579337A-A00D-4912-839D-F28C3604FD31} = {5170C7C5-6EB2-4AE9-B17A-FB9A15AF1401} {09DAEE5A-8C1C-4A31-B26F-6DD5AF782A0C} = {46309ADE-8FD9-4291-B1CF-EA44AD5486CF} {AD2C1BBA-8ED2-4CEC-8318-ABDAB3D0FE35} = {B2C2A9FB-EB02-4355-BE9E-330D0F6F7482} diff --git a/AppBrokerASP/AppBrokerASP.csproj b/AppBrokerASP/AppBrokerASP.csproj index 7cb2c21..2956128 100644 --- a/AppBrokerASP/AppBrokerASP.csproj +++ b/AppBrokerASP/AppBrokerASP.csproj @@ -14,6 +14,13 @@ Linux + + + + + + + @@ -42,8 +49,6 @@ - - @@ -70,14 +75,13 @@ - - + @@ -94,6 +98,7 @@ + diff --git a/AppBrokerASP/Controllers/DevicesController.cs b/AppBrokerASP/Controllers/DevicesController.cs index 483e217..ed33de0 100644 --- a/AppBrokerASP/Controllers/DevicesController.cs +++ b/AppBrokerASP/Controllers/DevicesController.cs @@ -7,8 +7,6 @@ using AppBrokerASP.Configuration; using AppBrokerASP.Devices; -using Elsa.Server.Api.Attributes; - using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; @@ -81,7 +79,7 @@ public async Task SetDeviceStates(long id) } [HttpGet("history/{id}")] - public ActionResult GetHistory(long id, [RequiredFromQuery] DateTime from, [RequiredFromQuery] DateTime to, [RequiredFromQuery] string propName) + public ActionResult GetHistory(long id, [FromQuery] DateTime from, [FromQuery] DateTime to, [FromQuery] string propName) { return Content(JsonConvert.SerializeObject(historyManager.GetHistoryFor(id, propName, from, to))); } diff --git a/AppBrokerASP/Dockerfile b/AppBrokerASP/Dockerfile index 1d4efa0..fec7ed9 100644 --- a/AppBrokerASP/Dockerfile +++ b/AppBrokerASP/Dockerfile @@ -15,21 +15,12 @@ COPY ["AppBrokerASP/AppBrokerASP.csproj", "AppBrokerASP/"] COPY ["AppBroker.Elsa/AppBroker.Elsa.csproj", "AppBroker.Elsa/"] COPY ["AppBroker.Core/AppBroker.Core.csproj", "AppBroker.Core/"] COPY ["AppBroker.Generators/AppBroker.Generators.csproj", "AppBroker.Generators/"] -RUN dotnet restore "AppBrokerASP/AppBrokerASP.csproj" COPY . . WORKDIR "/src/AppBrokerASP" FROM build AS publish ARG TARGETPLATFORM -RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ - RID=linux-x64 ; \ - elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ - RID=linux-arm64 ; \ - elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ - RID=linux-arm ; \ - fi \ - && dotnet publish -c Release -r $RID -o /app/publish /p:UseAppHost=false --self-contained false - +RUN dotnet publish -c Release -o /app/publish /p:UseAppHost=false --self-contained false FROM base AS final WORKDIR /app diff --git a/AppBrokerASP/Extension/Extensions.cs b/AppBrokerASP/Extension/Extensions.cs index 684d0fd..abac788 100644 --- a/AppBrokerASP/Extension/Extensions.cs +++ b/AppBrokerASP/Extension/Extensions.cs @@ -1,5 +1,4 @@ -using SocketIOClient; - + using System.Threading.Tasks; namespace AppBrokerASP.Extension; @@ -78,24 +77,4 @@ public static List IndexesOf(this Span span, T value) where T : IEqua } } - public static async Task Emit(this SocketIO socket, string eventName, params object[] data) - { - var task = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - await socket.EmitAsync(eventName, response => - { - try - { - task.SetResult(response); - } - catch (Exception ex) - { - task.SetException(ex); - } - }, data); - - // Ensure follwoing tasks will run async - await Task.Yield(); - - return await task.Task; - } } diff --git a/AppBrokerASP/InstanceContainer.cs b/AppBrokerASP/InstanceContainer.cs index c00d383..7d41450 100644 --- a/AppBrokerASP/InstanceContainer.cs +++ b/AppBrokerASP/InstanceContainer.cs @@ -4,7 +4,6 @@ using AppBroker.Core.Managers; using AppBrokerASP.Configuration; -using AppBrokerASP.Devices.Elsa; using AppBrokerASP.Histories; using AppBrokerASP.State; @@ -38,7 +37,7 @@ public InstanceContainer() var localDeviceManager = new DeviceManager(); DeviceManager = localDeviceManager; localDeviceManager.LoadDevices(); - DeviceTypeMetaDataManager = new DeviceTypeMetaDataManager(localDeviceManager); + //DeviceTypeMetaDataManager = new DeviceTypeMetaDataManager(localDeviceManager); } diff --git a/AppBrokerASP/SignalR/NewtonsoftJsonSmarthomeHubProtocol.cs b/AppBrokerASP/SignalR/NewtonsoftJsonSmarthomeHubProtocol.cs index 42d469c..bfe8d3e 100644 --- a/AppBrokerASP/SignalR/NewtonsoftJsonSmarthomeHubProtocol.cs +++ b/AppBrokerASP/SignalR/NewtonsoftJsonSmarthomeHubProtocol.cs @@ -15,7 +15,6 @@ using System.Text; using System.Linq; using System; -using Elsa.Activities.Signaling.Models; using System.IO.Compression; using AppBroker.Core; diff --git a/AppBrokerASP/Smarthome.cs b/AppBrokerASP/Smarthome.cs index f8c9b18..3386751 100644 --- a/AppBrokerASP/Smarthome.cs +++ b/AppBrokerASP/Smarthome.cs @@ -211,13 +211,6 @@ public record LayoutNameWithHash(string Name, string Hash); return new(layoutHash.Value.layout.UniqueName, layoutHash.Value.hash); } - public IEnumerable> GetAppConfig() - { - var loader = IInstanceContainer.Instance.GetDynamic(); - return loader.AppConfigurators.Select(x => x.GetConfigs()).Where(x => x is not null).SelectMany(x => x!); - } - - //public DashboardDeviceLayout? GetDashboardDeviceLayoutByName(string typename) => DeviceLayoutService.GetDashboardDeviceLayout(typename); //public DashboardDeviceLayout? GetDashboardDeviceLayoutByDeviceId(long id) => DeviceLayoutService.GetDashboardDeviceLayout(id); diff --git a/AppBrokerASP/Startup.cs b/AppBrokerASP/Startup.cs index 8de1114..3f3836a 100644 --- a/AppBrokerASP/Startup.cs +++ b/AppBrokerASP/Startup.cs @@ -1,12 +1,7 @@  using AppBrokerASP.Cloud; -using AppBrokerASP.Devices.Elsa; using AppBrokerASP.SignalR; -using Elsa; -using Elsa.Persistence.EntityFramework.Core.Extensions; -using Elsa.Persistence.EntityFramework.Sqlite; - using MQTTnet.AspNetCore; using Microsoft.AspNetCore.SignalR.Protocol; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -55,7 +50,6 @@ public void ConfigureServices(IServiceCollection services) _ = services.AddRazorPages(); - _ = services.AddApiVersioning(); _ = services.AddSingleton(); var container = InstanceContainer.Instance; _ = services.AddSingleton(new CloudConnector()); @@ -69,35 +63,7 @@ public void ConfigureServices(IServiceCollection services) _ = services.AddSingleton(container.DeviceStateManager); _ = services.AddSingleton(container.HistoryManager); - var elsaSection = Configuration.GetSection("Elsa"); - - if (elsaSection.GetValue("Enabled", true)) - { - _ = services - .AddElsaCore(options => options - .UseEntityFrameworkPersistence(ef => ef.UseSqlite()) - .AddConsoleActivities() - .AddHttpActivities(elsaSection.GetSection("Server").Bind) - .AddEmailActivities(elsaSection.GetSection("Smtp").Bind) - .AddQuartzTemporalActivities() - .AddJavaScriptActivities() - .AddFileActivities() - .AddPropertyActivities() - .AddActivitiesFrom() - .AddFeatures(new[] { typeof(Startup) }, Configuration) - .AddWorkflowsFrom() - .WithContainerName(elsaSection.GetSection("Server:ContainerName").Get()) - ) - .AddJavaScriptTypeDefinitionProvider() - .AddJavaScriptTypeDefinitionProvider() - //.AddNotificationHandlersFrom() - //.AddNotificationHandlersFrom() - //; - ; - _ = services - .AddElsaApiEndpoints(); - } if (InstanceContainer.Instance.ConfigManager.MqttConfig.Enabled) { diff --git a/AppBrokerASP/State/DeviceStateManager.cs b/AppBrokerASP/State/DeviceStateManager.cs index 513f5e0..1106b2b 100644 --- a/AppBrokerASP/State/DeviceStateManager.cs +++ b/AppBrokerASP/State/DeviceStateManager.cs @@ -2,7 +2,6 @@ using AppBroker.Core.Database; using AppBroker.Core.Devices; -using Elsa.Activities.StateMachine; using Microsoft.EntityFrameworkCore.Metadata.Internal; diff --git a/AppBrokerASP/TestWorkflow.cs b/AppBrokerASP/TestWorkflow.cs deleted file mode 100644 index 0f896c7..0000000 --- a/AppBrokerASP/TestWorkflow.cs +++ /dev/null @@ -1,71 +0,0 @@ - -using Elsa.Activities.Console; -using Elsa.Activities.File.Models; -using Elsa.Activities.File; -using Elsa.Builders; - -using System.Text; -using AppBroker.Elsa.Models; -using AppBroker.Elsa.Signaler; - -namespace AppBrokerASP -{ - public class SignalerCreatorWorkflow : IWorkflow - { - public SignalerCreatorWorkflow(WorkflowDeviceSignaler a, WorkflowPropertySignaler b) - { - - } - - public void Build(IWorkflowBuilder builder) { } - } - - //public class TestWorkflow : IWorkflow - //{ - - // public void Build(IWorkflowBuilder builder) - // { - - - // _ = builder.Then(setup: (setup) => - // { - - // //.Set(x => x.DeviceId, 6066005697233659) - // //.Set(x => x.DeviceName, "Sascha Zimmer"); - - // }) - // .WriteLine(setup: (setup) => - // { - // _ = setup.WithText(async context => - // { - // var device = await context.WorkflowExecutionContext.GetActivityPropertyAsync("activity-1", a => a.Output!); - // var line = $"{GetType().Name}-{device!.DeviceName}-{device.DeviceId}-{device.TypeName}-{device.ToJson()}"; - // return line; - // }); - // }); - - // } - //} - - //public class TestWorkflow2 : IWorkflow - //{ - - // public void Build(IWorkflowBuilder builder) - // { - // _ = builder.Then(setup: (setup) => - // { - // setup.Set(x => x.PropertyName, "Temperature"); - // }) - // .WriteLine(setup: (setup) => - // { - // _ = setup.WithText(async context => - // { - // PropertyChangedEvent? device = await context.WorkflowExecutionContext.GetActivityPropertyAsync("activity-1", a => a.Output!); - // var line = $"{GetType().Name}-{device!.DeviceName}-{device.DeviceId}-{device.TypeName}-{device.ToJson()}"; - // return line; - // }); - // }); - - // } - //} -} diff --git a/DbMigrator/Program.cs b/DbMigrator/Program.cs index 598e85c..6642c6b 100644 --- a/DbMigrator/Program.cs +++ b/DbMigrator/Program.cs @@ -1,34 +1,17 @@ - -using AppBroker.Core; -using AppBroker.Core.Configuration; -using AppBroker.Core.Database; -using AppBroker.Core.Database.History; - -using AppBrokerASP.Configuration; - -using Elsa.ActivityResults; +using AppBroker.Core.Database.History; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.Configuration; -using NonSucking.Framework.Extension.EntityFrameworkCore; - using System; using System.Collections.Generic; -using System.Configuration; using System.Diagnostics; -using System.IO; using System.Linq; using System.Threading; -using static Org.BouncyCastle.Math.EC.ECCurve; - namespace DbMigrator; - class DbConfig { @@ -110,7 +93,7 @@ private static void MigrateHistory() //AddRange<>(target, source.ValueBases); } - static void AddRange(IEntityType et/*, Func startAt*/) + static void AddRange(IEntityType et/*, Func startAt*/) where T : class where TTarget : DbContext, new() where TSource : DbContext, new() @@ -132,7 +115,7 @@ static void AddRange(IEntityType et/*, Func { using var source = new TSource(); var target = new TTarget(); - + //using var trans = target.Database.BeginTransaction(); //target.Database.ExecuteSqlRaw($"SET IDENTITY_INSERT {tableName} ON"); /*trans = */