Skip to content

Commit

Permalink
Remove dead code and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
helto4real committed Feb 6, 2021
1 parent 2358913 commit 4f259df
Show file tree
Hide file tree
Showing 22 changed files with 37 additions and 197 deletions.
50 changes: 0 additions & 50 deletions src/App/NetDaemon.App/Common/ExternalEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,4 @@ public class ExternalEventBase
public class AppsInformationEvent : ExternalEventBase
{
}

/// <summary>
/// Information about the application
/// </summary>
public class ApplicationInfo
{
/// <summary>
/// Unique id
/// </summary>
public string? Id { get; set; }
/// <summary>
/// All application dependencies
/// </summary>
public IEnumerable<string>? Dependencies { get; set; }

/// <summary>
/// If app is enabled or disabled
/// </summary>
public bool IsEnabled { get; set; }

/// <summary>
/// Application description
/// </summary>
public string? Description { get; set; }

/// <summary>
/// Next scheduled event
/// </summary>
public DateTime? NextScheduledEvent { get; set; }

/// <summary>
/// Last known error message
/// </summary>
public string? LastErrorMessage { get; set; }
}

/// <summary>
/// All config information
/// </summary>
public class ConfigInfo
{
/// <summary>
/// Settings for NetDaemon
/// </summary>
public NetDaemonSettings? DaemonSettings { get; set; }
/// <summary>
/// Settings Home Assistant related
/// </summary>
public HomeAssistantSettings? HomeAssistantSettings { get; set; }
}
}
1 change: 0 additions & 1 deletion src/App/NetDaemon.App/Common/INetDaemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public interface INetDaemon : INetDaemonCommon
/// <param name="waitForResponse">If we should wait for the service to get response from Home Assistant or send/forget scenario</param>
Task CallServiceAsync(string domain, string service, dynamic? data = null, bool waitForResponse = false);


/// <summary>
/// Get application instance by application instance id
/// </summary>
Expand Down
85 changes: 0 additions & 85 deletions src/App/NetDaemon.App/Common/IScheduler.cs

This file was deleted.

22 changes: 0 additions & 22 deletions src/Daemon/NetDaemon.Daemon/Daemon/Config/ConfigExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

namespace NetDaemon.Daemon.Config
{
// public interface IDaemonAppConfig
// {
// Task InstanceFromDaemonAppConfigs(IEnumerable<Type> netDaemonApps, string codeFolder);
// }
public static class TaskExtensions
{
public static async Task InvokeAsync(this MethodInfo mi, object? obj, params object?[]? parameters)
Expand All @@ -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 ??
Expand Down
2 changes: 1 addition & 1 deletion src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlAppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public IEnumerable<INetDaemonAppBase> Instances
throw new MissingMemberException($"{scalarPropertyName} is missing from the type {instanceType}");

var valueType = entry.Value.NodeType;
Object? result = null;
object? result = null;

switch (valueType)
{
Expand Down
10 changes: 3 additions & 7 deletions src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
Expand Down Expand Up @@ -40,12 +39,9 @@ public IEnumerable<string> 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)
{
Expand Down Expand Up @@ -101,7 +97,7 @@ internal static Dictionary<string, Dictionary<string, string>> GetAllSecretsFrom

if (!result.ContainsKey(fileDirectory))
{
result[fileDirectory] = (Dictionary<string, string>?)GetSecretsFromSecretsYaml(file) ??
result[fileDirectory] = GetSecretsFromSecretsYaml(file) ??
new Dictionary<string, string>();
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Daemon/NetDaemon.Daemon/Daemon/Config/YamlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,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, object? parent)
Expand Down
2 changes: 1 addition & 1 deletion src/Daemon/NetDaemon.Daemon/Daemon/IHassClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
10 changes: 4 additions & 6 deletions src/Daemon/NetDaemon.Daemon/Daemon/NetDaemonHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class NetDaemonHost : INetDaemonHost, IAsyncDisposable
/// <summary>
/// Constructor
/// </summary>
/// <param name="hassClient">Client to use</param>
/// <param name="hassClientFactory">Factory to use for instance HassClients</param>
/// <param name="repository">Repository to use</param>
/// <param name="loggerFactory">The loggerfactory</param>
/// <param name="httpHandler">Http handler to use</param>
Expand Down Expand Up @@ -814,10 +814,8 @@ internal static IList<INetDaemonAppBase> SortByDependency(IEnumerable<INetDaemon
edges.Add(new Tuple<INetDaemonAppBase, INetDaemonAppBase>(instance, dependentApp));
}
}
var sortedInstances = TopologicalSort<INetDaemonAppBase>(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();
}
Expand Down Expand Up @@ -1378,7 +1376,7 @@ private async Task PostExternalEvent(ExternalEventBase ev)

await callbackTaskList.WhenAll(_cancelToken).ConfigureAwait(false);
}

/// <inheritdoc/>
public bool HomeAssistantHasNetDaemonIntegration() => HasNetDaemonIntegration;
}
}
}
6 changes: 3 additions & 3 deletions src/Daemon/NetDaemon.Daemon/Daemon/Storage/DataRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task Save<T>(string id, T data)

using var jsonStream = File.Open(storageJsonFile, FileMode.Create, FileAccess.Write);

await JsonSerializer.SerializeAsync<T>(jsonStream, data).ConfigureAwait(false);
await JsonSerializer.SerializeAsync(jsonStream, data).ConfigureAwait(false);
}
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public override void Write(
Dictionary<string, object?> value,
JsonSerializerOptions options)
{
JsonSerializer.Serialize<Dictionary<string, object?>>(writer, value, options);
JsonSerializer.Serialize(writer, value, options);
}
}

Expand All @@ -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
};
}
Expand Down
10 changes: 10 additions & 0 deletions src/Daemon/NetDaemon.Daemon/Daemon/Storage/IPersistData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ namespace NetDaemon.Daemon.Storage
{
public interface IDataRepository
{
/// <summary>
/// Saves data in a generic repository
/// </summary>
/// <param name="id">Unique id of data to save</param>
/// <param name="data">The data to save</param>
/// <typeparam name="T">The type of the data saved</typeparam>
Task Save<T>(string id, T data);

/// <summary>
/// Gets data from repositiry
/// </summary>
/// <typeparam name="T?">Type of data</typeparam>
ValueTask<T?> Get<T>(string id) where T : class;
}
}
7 changes: 3 additions & 4 deletions src/Daemon/NetDaemon.Daemon/Daemon/StringParser.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System;
using System.Globalization;
using System.Globalization;

namespace NetDaemon.Daemon
{
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal static class JsonElementExtensions
{
list.Add(val.ConvertToDynamicValue());
}
return (IEnumerable<object?>)list;
return list;

case JsonValueKind.Object:
var obj = new Dictionary<string, object?>();
Expand All @@ -42,7 +42,7 @@ internal static class JsonElementExtensions
{
obj[prop.Name] = prop.Value.ConvertToDynamicValue();
}
return (IDictionary<string, object?>)obj;
return obj;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using NetDaemon.Daemon;

namespace NetDaemon.Infrastructure.Extensions
{
Expand Down
4 changes: 4 additions & 0 deletions src/Daemon/NetDaemon.Daemon/Mapping/ContextMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ namespace NetDaemon.Mapping
{
public static class ContextMapper
{
/// <summary>
/// Maps HassContext to Context
/// </summary>
/// <param name="hassContext">The HassContext to map</param>
public static Context Map(HassContext? hassContext)
{
if (hassContext == null)
Expand Down
2 changes: 1 addition & 1 deletion src/Daemon/NetDaemon.Daemon/Mapping/EntityStateMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class EntityStateMapper
/// <summary>
/// Converts HassState to EntityState
/// </summary>
/// <param name="hassState"></param>
/// <param name="hassState">HassState object to map</param>
public static EntityState Map(this HassState hassState)
{
_ = hassState ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Loading

0 comments on commit 4f259df

Please sign in to comment.