diff --git a/src/App/NetDaemon.App/Common/ExternalEvents.cs b/src/App/NetDaemon.App/Common/ExternalEvents.cs index 73efea5d5..6c0043cc3 100644 --- a/src/App/NetDaemon.App/Common/ExternalEvents.cs +++ b/src/App/NetDaemon.App/Common/ExternalEvents.cs @@ -18,54 +18,4 @@ public class ExternalEventBase public class AppsInformationEvent : ExternalEventBase { } - - /// - /// Information about the application - /// - public class ApplicationInfo - { - /// - /// Unique id - /// - public string? Id { get; set; } - /// - /// All application dependencies - /// - public IEnumerable? Dependencies { get; set; } - - /// - /// If app is enabled or disabled - /// - public bool IsEnabled { get; set; } - - /// - /// Application description - /// - public string? Description { get; set; } - - /// - /// Next scheduled event - /// - public DateTime? NextScheduledEvent { get; set; } - - /// - /// Last known error message - /// - public string? LastErrorMessage { get; set; } - } - - /// - /// All config information - /// - public class ConfigInfo - { - /// - /// Settings for NetDaemon - /// - public NetDaemonSettings? DaemonSettings { get; set; } - /// - /// Settings Home Assistant related - /// - public HomeAssistantSettings? HomeAssistantSettings { get; set; } - } } \ No newline at end of file diff --git a/src/App/NetDaemon.App/Common/INetDaemon.cs b/src/App/NetDaemon.App/Common/INetDaemon.cs index e57487f90..341bd747a 100644 --- a/src/App/NetDaemon.App/Common/INetDaemon.cs +++ b/src/App/NetDaemon.App/Common/INetDaemon.cs @@ -40,7 +40,6 @@ public interface INetDaemon : INetDaemonCommon /// If we should wait for the service to get response from Home Assistant or send/forget scenario Task CallServiceAsync(string domain, string service, dynamic? data = null, bool waitForResponse = false); - /// /// Get application instance by application instance id /// diff --git a/src/App/NetDaemon.App/Common/IScheduler.cs b/src/App/NetDaemon.App/Common/IScheduler.cs deleted file mode 100644 index 58d4796e5..000000000 --- a/src/App/NetDaemon.App/Common/IScheduler.cs +++ /dev/null @@ -1,85 +0,0 @@ -// using System; -// using System.Collections.Generic; -// using System.Threading; -// using System.Threading.Tasks; - -// namespace NetDaemon.Common -// { -// /// -// /// Interface for scheduler actions -// /// -// [Obsolete("You are using V1 of API and it is deprecated, next release it will be moved.Please replace it wiht V2 NetDaemonRxApp", false)] -// public interface IScheduler : IAsyncDisposable -// { -// /// -// /// Run daily tasks -// /// -// /// The time in the format HH:mm:ss -// /// The action to run -// /// -// ISchedulerResult RunDaily(string time, Func func); - -// /// -// /// Run daily tasks -// /// -// /// The time in the format HH:mm:ss -// /// A list of days the scheduler will run on -// /// The action to run -// /// -// ISchedulerResult RunDaily(string time, IEnumerable? runOnDays, Func func); - -// /// -// /// Run function every milliseconds -// /// -// /// Number of milliseconds -// /// The function to run -// ISchedulerResult RunEvery(int millisecondsDelay, Func func); - -// /// -// /// Run function every time span -// /// -// /// Timespan between runs -// /// The function to run -// ISchedulerResult RunEvery(TimeSpan timeSpan, Func func); - -// /// -// /// Run task every minute at given second -// /// -// /// The second in a minute to start (0-59) -// /// The task to run -// /// -// /// It is safe to supress the task since it is handled internally in the scheduler -// /// -// ISchedulerResult RunEveryMinute(short second, Func func); - -// /// -// /// Run in milliseconds delay -// /// -// /// Number of milliseconds before run -// /// The function to run -// ISchedulerResult RunIn(int millisecondsDelay, Func func); - -// /// -// /// Run in function in time span -// /// -// /// Timespan time before run function -// /// The function to run -// ISchedulerResult RunIn(TimeSpan timeSpan, Func func); -// } - -// /// -// /// Scheduler result lets you manage scheduled tasks like check completion, cancel the tasks etc. -// /// -// public interface ISchedulerResult -// { -// /// -// /// Use to cancel any scheduled execution -// /// -// CancellationTokenSource CancelSource { get; } - -// /// -// /// Current running task -// /// -// Task Task { get; } -// } -// } \ No newline at end of file diff --git a/src/Daemon/NetDaemon.Daemon/Daemon/Config/ConfigExtensions.cs b/src/Daemon/NetDaemon.Daemon/Daemon/Config/ConfigExtensions.cs index f413e67c6..88ded2b93 100644 --- a/src/Daemon/NetDaemon.Daemon/Daemon/Config/ConfigExtensions.cs +++ b/src/Daemon/NetDaemon.Daemon/Daemon/Config/ConfigExtensions.cs @@ -9,10 +9,6 @@ namespace NetDaemon.Daemon.Config { - // public interface IDaemonAppConfig - // { - // Task InstanceFromDaemonAppConfigs(IEnumerable netDaemonApps, string codeFolder); - // } public static class TaskExtensions { public static async Task InvokeAsync(this MethodInfo mi, object? obj, params object?[]? parameters) @@ -28,24 +24,6 @@ public static async Task InvokeAsync(this MethodInfo mi, object? obj, params obj public static class ConfigStringExtensions { - public static string ToPythonStyle(this string str) - { - _ = str ?? - throw new NetDaemonArgumentNullException(nameof(str)); - - var build = new StringBuilder(str.Length); - bool isStart = true; - foreach (char c in str) - { - if (char.IsUpper(c) && !isStart) - build.Append('_'); - else - isStart = false; - build.Append(char.ToLower(c, CultureInfo.InvariantCulture)); - } - return build.ToString(); - } - public static string ToCamelCase(this string str) { _ = str ?? diff --git a/src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlAppConfig.cs b/src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlAppConfig.cs index 6cb10e8b2..5dd9cffd9 100644 --- a/src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlAppConfig.cs +++ b/src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlAppConfig.cs @@ -153,7 +153,7 @@ public IEnumerable Instances throw new MissingMemberException($"{scalarPropertyName} is missing from the type {instanceType}"); var valueType = entry.Value.NodeType; - Object? result = null; + object? result = null; switch (valueType) { diff --git a/src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlConfig.cs b/src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlConfig.cs index 538137a71..5838681bb 100644 --- a/src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlConfig.cs +++ b/src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlConfig.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; @@ -40,12 +39,9 @@ public IEnumerable GetAllConfigFilePaths() public string? GetSecretFromPath(string secret, string configPath) { - if (_secrets.ContainsKey(configPath)) + if (_secrets.ContainsKey(configPath) && _secrets[configPath].ContainsKey(secret)) { - if (_secrets[configPath].ContainsKey(secret)) - { - return _secrets[configPath][secret]; - } + return _secrets[configPath][secret]; } if (configPath != _configFolder) { @@ -101,7 +97,7 @@ public IEnumerable GetAllConfigFilePaths() if (!result.ContainsKey(fileDirectory)) { - result[fileDirectory] = (Dictionary?)GetSecretsFromSecretsYaml(file) ?? + result[fileDirectory] = GetSecretsFromSecretsYaml(file) ?? new Dictionary(); } } diff --git a/src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlExtensions.cs b/src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlExtensions.cs index 0b13fe40f..59bcdef5c 100644 --- a/src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlExtensions.cs +++ b/src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlExtensions.cs @@ -31,8 +31,7 @@ public static class YamlExtensions // Lets try convert from python style to CamelCase - var prop = type.GetProperty(propertyName) ?? type.GetProperty(propertyName.ToCamelCase()); - return prop; + return type.GetProperty(propertyName) ?? type.GetProperty(propertyName.ToCamelCase()); } public static object? ToObject(this YamlScalarNode node, Type valueType) diff --git a/src/Daemon/NetDaemon.Daemon/Daemon/IHassClientFactory.cs b/src/Daemon/NetDaemon.Daemon/Daemon/IHassClientFactory.cs index 3772fde0a..22e0b140b 100644 --- a/src/Daemon/NetDaemon.Daemon/Daemon/IHassClientFactory.cs +++ b/src/Daemon/NetDaemon.Daemon/Daemon/IHassClientFactory.cs @@ -18,7 +18,7 @@ public interface IHassClientFactory public class HassClientFactory : IHassClientFactory { - readonly IServiceProvider _serviceProvider; + private readonly IServiceProvider _serviceProvider; public HassClientFactory(IServiceProvider? serviceProvider = null) { _serviceProvider = serviceProvider ?? throw new NetDaemonArgumentNullException(nameof(serviceProvider)); diff --git a/src/Daemon/NetDaemon.Daemon/Daemon/NetDaemonHost.cs b/src/Daemon/NetDaemon.Daemon/Daemon/NetDaemonHost.cs index c6cd15aaf..ef4f3e090 100644 --- a/src/Daemon/NetDaemon.Daemon/Daemon/NetDaemonHost.cs +++ b/src/Daemon/NetDaemon.Daemon/Daemon/NetDaemonHost.cs @@ -91,7 +91,7 @@ public class NetDaemonHost : INetDaemonHost, IAsyncDisposable /// /// Constructor /// - /// Client to use + /// Factory to use for instance HassClients /// Repository to use /// The loggerfactory /// Http handler to use @@ -814,10 +814,8 @@ internal static IList SortByDependency(IEnumerable(instance, dependentApp)); } } - var sortedInstances = TopologicalSort(unsortedList.ToHashSet(), edges) ?? + return TopologicalSort(unsortedList.ToHashSet(), edges) ?? throw new NetDaemonException("Application dependencies is wrong, please check dependencies for circular dependencies!"); - - return sortedInstances; } return unsortedList.ToList(); } @@ -1378,7 +1376,7 @@ private async Task PostExternalEvent(ExternalEventBase ev) await callbackTaskList.WhenAll(_cancelToken).ConfigureAwait(false); } - + /// public bool HomeAssistantHasNetDaemonIntegration() => HasNetDaemonIntegration; } -} \ No newline at end of file +} diff --git a/src/Daemon/NetDaemon.Daemon/Daemon/Storage/DataRepository.cs b/src/Daemon/NetDaemon.Daemon/Daemon/Storage/DataRepository.cs index 8ffb496e6..c1f935d17 100644 --- a/src/Daemon/NetDaemon.Daemon/Daemon/Storage/DataRepository.cs +++ b/src/Daemon/NetDaemon.Daemon/Daemon/Storage/DataRepository.cs @@ -61,7 +61,7 @@ public async Task Save(string id, T data) using var jsonStream = File.Open(storageJsonFile, FileMode.Create, FileAccess.Write); - await JsonSerializer.SerializeAsync(jsonStream, data).ConfigureAwait(false); + await JsonSerializer.SerializeAsync(jsonStream, data).ConfigureAwait(false); } } @@ -91,7 +91,7 @@ public class ExpandoDictionaryConverter : JsonConverter value, JsonSerializerOptions options) { - JsonSerializer.Serialize>(writer, value, options); + JsonSerializer.Serialize(writer, value, options); } } @@ -113,7 +113,7 @@ public static class ExpandoExtensions JsonValueKind.String => ParseString(elem.GetString()), JsonValueKind.False => false, JsonValueKind.True => true, - JsonValueKind.Number => elem.TryGetInt64(out Int64 intValue) ? intValue : elem.GetDouble(), + JsonValueKind.Number => elem.TryGetInt64(out long intValue) ? intValue : elem.GetDouble(), _ => null }; } diff --git a/src/Daemon/NetDaemon.Daemon/Daemon/Storage/IPersistData.cs b/src/Daemon/NetDaemon.Daemon/Daemon/Storage/IPersistData.cs index b30ae5097..f7c4faf07 100644 --- a/src/Daemon/NetDaemon.Daemon/Daemon/Storage/IPersistData.cs +++ b/src/Daemon/NetDaemon.Daemon/Daemon/Storage/IPersistData.cs @@ -4,8 +4,18 @@ namespace NetDaemon.Daemon.Storage { public interface IDataRepository { + /// + /// Saves data in a generic repository + /// + /// Unique id of data to save + /// The data to save + /// The type of the data saved Task Save(string id, T data); + /// + /// Gets data from repositiry + /// + /// Type of data ValueTask Get(string id) where T : class; } } \ No newline at end of file diff --git a/src/Daemon/NetDaemon.Daemon/Daemon/StringParser.cs b/src/Daemon/NetDaemon.Daemon/Daemon/StringParser.cs index 948577c80..1d1131e26 100644 --- a/src/Daemon/NetDaemon.Daemon/Daemon/StringParser.cs +++ b/src/Daemon/NetDaemon.Daemon/Daemon/StringParser.cs @@ -1,5 +1,4 @@ -using System; -using System.Globalization; +using System.Globalization; namespace NetDaemon.Daemon { @@ -7,10 +6,10 @@ internal static class StringParser { public static object? ParseDataType(string? state) { - if (Int64.TryParse(state, NumberStyles.Number, CultureInfo.InvariantCulture, out Int64 intValue)) + if (long.TryParse(state, NumberStyles.Number, CultureInfo.InvariantCulture, out long intValue)) return intValue; - if (Double.TryParse(state, NumberStyles.Number, CultureInfo.InvariantCulture, out Double doubleValue)) + if (double.TryParse(state, NumberStyles.Number, CultureInfo.InvariantCulture, out double doubleValue)) return doubleValue; return state; diff --git a/src/Daemon/NetDaemon.Daemon/Infrastructure/Extensions/JsonElementExtensions.cs b/src/Daemon/NetDaemon.Daemon/Infrastructure/Extensions/JsonElementExtensions.cs index b6b031ea0..8dcab948a 100644 --- a/src/Daemon/NetDaemon.Daemon/Infrastructure/Extensions/JsonElementExtensions.cs +++ b/src/Daemon/NetDaemon.Daemon/Infrastructure/Extensions/JsonElementExtensions.cs @@ -33,7 +33,7 @@ internal static class JsonElementExtensions { list.Add(val.ConvertToDynamicValue()); } - return (IEnumerable)list; + return list; case JsonValueKind.Object: var obj = new Dictionary(); @@ -42,7 +42,7 @@ internal static class JsonElementExtensions { obj[prop.Name] = prop.Value.ConvertToDynamicValue(); } - return (IDictionary)obj; + return obj; } return null; diff --git a/src/Daemon/NetDaemon.Daemon/Infrastructure/Extensions/TaskExtensions.cs b/src/Daemon/NetDaemon.Daemon/Infrastructure/Extensions/TaskExtensions.cs index b3a24f384..300d88efb 100644 --- a/src/Daemon/NetDaemon.Daemon/Infrastructure/Extensions/TaskExtensions.cs +++ b/src/Daemon/NetDaemon.Daemon/Infrastructure/Extensions/TaskExtensions.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using NetDaemon.Daemon; namespace NetDaemon.Infrastructure.Extensions { diff --git a/src/Daemon/NetDaemon.Daemon/Mapping/ContextMapper.cs b/src/Daemon/NetDaemon.Daemon/Mapping/ContextMapper.cs index 68237ef31..b28e4f32f 100644 --- a/src/Daemon/NetDaemon.Daemon/Mapping/ContextMapper.cs +++ b/src/Daemon/NetDaemon.Daemon/Mapping/ContextMapper.cs @@ -5,6 +5,10 @@ namespace NetDaemon.Mapping { public static class ContextMapper { + /// + /// Maps HassContext to Context + /// + /// The HassContext to map public static Context Map(HassContext? hassContext) { if (hassContext == null) diff --git a/src/Daemon/NetDaemon.Daemon/Mapping/EntityStateMapper.cs b/src/Daemon/NetDaemon.Daemon/Mapping/EntityStateMapper.cs index 5ca4ca720..0379084af 100644 --- a/src/Daemon/NetDaemon.Daemon/Mapping/EntityStateMapper.cs +++ b/src/Daemon/NetDaemon.Daemon/Mapping/EntityStateMapper.cs @@ -13,7 +13,7 @@ public static class EntityStateMapper /// /// Converts HassState to EntityState /// - /// + /// HassState object to map public static EntityState Map(this HassState hassState) { _ = hassState ?? diff --git a/src/DaemonRunner/DaemonRunner/Infrastructure/Config/HassioConfig.cs b/src/DaemonRunner/DaemonRunner/Infrastructure/Config/HassioConfig.cs index 74e9c091c..40591dea8 100644 --- a/src/DaemonRunner/DaemonRunner/Infrastructure/Config/HassioConfig.cs +++ b/src/DaemonRunner/DaemonRunner/Infrastructure/Config/HassioConfig.cs @@ -8,7 +8,7 @@ public class HassioConfig public string? LogLevel { get; set; } [JsonPropertyName("app_source")] - public string? AppSource { get; set; } = null; + public string? AppSource { get; set; } [JsonPropertyName("log_messages")] public bool? LogMessages { get; set; } diff --git a/src/DaemonRunner/DaemonRunner/Service/API/WsHandler.cs b/src/DaemonRunner/DaemonRunner/Service/API/WsHandler.cs index 2efa208ab..7e47bec59 100644 --- a/src/DaemonRunner/DaemonRunner/Service/API/WsHandler.cs +++ b/src/DaemonRunner/DaemonRunner/Service/API/WsHandler.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; diff --git a/src/DaemonRunner/DaemonRunner/Service/API/WsMessages.cs b/src/DaemonRunner/DaemonRunner/Service/API/WsMessages.cs index 056b83155..777c98c26 100644 --- a/src/DaemonRunner/DaemonRunner/Service/API/WsMessages.cs +++ b/src/DaemonRunner/DaemonRunner/Service/API/WsMessages.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; @@ -12,7 +10,7 @@ public class WsMessage { [JsonPropertyName("type")] public string Type { get; set; } = "unknown"; [JsonPropertyName("app")] public string? App { get; set; } - [JsonPropertyName("data")] public JsonElement? ServiceData { get; set; } = null; + [JsonPropertyName("data")] public JsonElement? ServiceData { get; set; } } public class WsAppCommand @@ -23,6 +21,6 @@ public class WsAppCommand public class WsExternalEvent { [JsonPropertyName("type")] public string Type { get; set; } = "unknown"; - [JsonPropertyName("data")] public object? Data { get; set; } = null; + [JsonPropertyName("data")] public object? Data { get; set; } } } \ No newline at end of file diff --git a/src/DaemonRunner/DaemonRunner/Service/App/CodeGenerator.cs b/src/DaemonRunner/DaemonRunner/Service/App/CodeGenerator.cs index b91023f1d..6798630bc 100644 --- a/src/DaemonRunner/DaemonRunner/Service/App/CodeGenerator.cs +++ b/src/DaemonRunner/DaemonRunner/Service/App/CodeGenerator.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Runtime.CompilerServices; using JoySoftware.HomeAssistant.Client; @@ -67,8 +66,8 @@ public static class CodeGenerator public string EntityId => EntityIds.First(); public EntityState? EntityState => DaemonRxApp?.State(EntityId); - - public string? Area => DaemonRxApp?.State(EntityId)?.Area; +using System.Globalization; +xApp?.State(EntityId)?.Area; public dynamic? Attribute => DaemonRxApp?.State(EntityId)?.Attribute; diff --git a/src/DaemonRunner/DaemonRunner/Service/App/IDaemonAppCompiler.cs b/src/DaemonRunner/DaemonRunner/Service/App/IDaemonAppCompiler.cs index 7f737d7ae..2d03a4800 100644 --- a/src/DaemonRunner/DaemonRunner/Service/App/IDaemonAppCompiler.cs +++ b/src/DaemonRunner/DaemonRunner/Service/App/IDaemonAppCompiler.cs @@ -8,7 +8,6 @@ public interface IDaemonAppCompiler /// /// Temporary /// - /// IEnumerable GetApps(); } } \ No newline at end of file diff --git a/src/DaemonRunner/DaemonRunner/Service/App/LocalDaemonAppCompiler.cs b/src/DaemonRunner/DaemonRunner/Service/App/LocalDaemonAppCompiler.cs index f78bbf6b6..fdbf45492 100644 --- a/src/DaemonRunner/DaemonRunner/Service/App/LocalDaemonAppCompiler.cs +++ b/src/DaemonRunner/DaemonRunner/Service/App/LocalDaemonAppCompiler.cs @@ -44,9 +44,7 @@ private IEnumerable LoadAll() .Select(x => x.Location) .ToList(); - var netDaemonDllsToLoadDynamically = netDaemonDlls.Except(alreadyLoadedAssemblies); - - foreach (var netDaemonDllToLoadDynamically in netDaemonDllsToLoadDynamically) + foreach (var netDaemonDllToLoadDynamically in netDaemonDlls.Except(alreadyLoadedAssemblies)) { _logger.LogTrace("Loading {dll} into AssemblyLoadContext", netDaemonDllToLoadDynamically); AssemblyLoadContext.Default.LoadFromAssemblyPath(netDaemonDllToLoadDynamically);