Skip to content

Commit

Permalink
Merge 848f823 into 29a31ea
Browse files Browse the repository at this point in the history
  • Loading branch information
helto4real committed Dec 27, 2020
2 parents 29a31ea + 848f823 commit 23a623e
Show file tree
Hide file tree
Showing 98 changed files with 2,157 additions and 2,038 deletions.
16 changes: 16 additions & 0 deletions .linting/roslynator.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Roslynator>
<Settings>
<General>
<!-- <PrefixFieldIdentifierWithUnderscore>true</PrefixFieldIdentifierWithUnderscore> -->
</General>
<Refactorings>
<!-- <Refactoring Id="RRxxxx" IsEnabled="false" /> -->
</Refactorings>
<CodeFixes>
<!-- <CodeFix Id="CSxxxx.RCFxxxx" IsEnabled="false" /> -->
<!-- <CodeFix Id="CSxxxx" IsEnabled="false" /> -->
<!-- <CodeFix Id="RCFxxxx" IsEnabled="false" /> -->
</CodeFixes>
</Settings>
</Roslynator>
40 changes: 40 additions & 0 deletions .linting/roslynator.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This rule set can be used to:
1) Enable/disable analyzer(s) by DEFAULT.
2) Change DEFAULT severity (action) of the analyzer(s).
Default configuration is applied once when analyzers are loaded.
Therefore, it may be neccessary to restart IDE for changes to take effect.
Although it is possible to edit ruleset manually, Visual Studio has built-in support for editing ruleset.
Just add ruleset file to a solution and open it.
-->
<RuleSet Name="roslynator.ruleset" ToolsVersion="16.0">

<!-- Specify default action that should be applied to all analyzers except those explicitly specified. -->
<!-- <IncludeAll Action="None,Hidden,Info,Warning,Error" /> -->

<!-- Specify zero or more paths to other rulesets that should be included. -->
<!-- <Include Path="" Action="Default,None,Hidden,Info,Warning,Error" /> -->

<Rules AnalyzerId="Roslynator.CSharp.Analyzers" RuleNamespace="Roslynator.CSharp.Analyzers">

<!-- Specify default action that should be applied to a specified analyzer. -->
<Rule Id="RCS0044" Action="None" />
<Rule Id="RCS1308" Action="None" />
<Rule Id="CA1014" Action="None" />
<Rule Id="CA1308" Action="None" />
<Rule Id="CA1054" Action="None" />
<Rule Id="CA1716" Action="None" />
<Rule Id="CA2234" Action="None" />
<!-- Lots of catching rare null pointer exceptions in properties. Might refactor those in the future -->
<Rule Id="CA1065" Action="None" />


</Rules>

</RuleSet>
8 changes: 8 additions & 0 deletions .vscode/daemon.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
// "description": "Log output to console"
// }
{
"nullcheck": {
"scope": "csharp",
"prefix": "nullcheck",
"body": [
"_ = $1 ??",
" throw new NetDaemonArgumentNullException(nameof($1));"
]
},
"fact": {
"scope": "csharp",
"prefix": "fact",
Expand Down
23 changes: 22 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,26 @@
"**/obj": true,
"**/Properties": true,
"**/TestResults": true
}
},
"omnisharp.enableRoslynAnalyzers": true,
"cSpell.words": [
"Expando",
"Finalizers",
"Hass",
"Usings",
"Xunit",
"dayofweek",
"entityid",
"hassio",
"idguid",
"mulitinstance",
"mydomain",
"myevent",
"mylight",
"myscript",
"noexist",
"noquotes",
"parentidguid",
"useridguid"
]
}
6 changes: 1 addition & 5 deletions src/App/NetDaemon.App/Common/AppRuntimeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ public sealed class AppRuntimeInfo
/// in app switch
/// </summary>
[JsonPropertyName("app_attributes")]
public Dictionary<string, object> AppAttributes { get; set; } = new();


public Dictionary<string, object> AppAttributes { get; } = new();
}


}


40 changes: 16 additions & 24 deletions src/App/NetDaemon.App/Common/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@ public sealed class DisableLogAttribute : System.Attribute
{
// See the attribute guidelines at
// http://go.microsoft.com/fwlink/?LinkId=85236
private SupressLogType[] _logTypesToSupress;
private readonly SupressLogType[]? _logTypesToSupress;

/// <summary>
/// Default constructor
/// </summary>
/// <param name="logTypes">List of logtypes to supress</param>
public DisableLogAttribute(params SupressLogType[] logTypes)
{
_logTypesToSupress = logTypes;
}
public DisableLogAttribute(params SupressLogType[] logTypes) => _logTypesToSupress = logTypes;

/// <summary>
/// Log types to supress
/// </summary>
public IEnumerable<SupressLogType> LogTypesToSupress => _logTypesToSupress;
public IEnumerable<SupressLogType>? LogTypesToSupress => _logTypesToSupress;

/// <summary>
/// Log tupes used
/// </summary>
public SupressLogType[]? LogTypes { get; }
}

/// <summary>
Expand All @@ -50,16 +52,6 @@ public sealed class HomeAssistantServiceCallAttribute : System.Attribute { }
[System.AttributeUsage(System.AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
public sealed class HomeAssistantStateChangedAttribute : System.Attribute
{
private readonly bool _allChanges;

private readonly object? _from;

private readonly object? _to;

// See the attribute guidelines at
// http://go.microsoft.com/fwlink/?LinkId=85236
private string _entityId;

/// <summary>
/// Default constructor
/// </summary>
Expand All @@ -69,30 +61,30 @@ public sealed class HomeAssistantStateChangedAttribute : System.Attribute
/// <param name="allChanges">Get all changes, ie also attribute changes</param>
public HomeAssistantStateChangedAttribute(string entityId, object? to = null, object? from = null, bool allChanges = false)
{
_entityId = entityId;
_to = to;
_from = from;
_allChanges = allChanges;
EntityId = entityId;
To = to;
From = from;
AllChanges = allChanges;
}

/// <summary>
/// Get all changes, even if only attribute changes
/// </summary>
public bool AllChanges => _allChanges;
public bool AllChanges { get; }

/// <summary>
/// Unique id of the entity
/// </summary>
public string EntityId => _entityId;
public string EntityId { get; }

/// <summary>
/// From state filter
/// </summary>
public object? From => _from;
public object? From { get; }

/// <summary>
/// To state filter
/// </summary>
public object? To => _to;
public object? To { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class HomeAssistantSettings
/// <summary>
/// Connect using ssl
/// </summary>
public bool Ssl { get; set; } = false;
public bool Ssl { get; set; }
/// <summary>
/// Token to authorize
/// Token to authorize
/// </summary>
public string Token { get; set; } = string.Empty;
}
Expand Down
11 changes: 7 additions & 4 deletions src/App/NetDaemon.App/Common/Configuration/NetDaemonSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Globalization;
using System.IO;
using NetDaemon.Common.Exceptions;

namespace NetDaemon.Common.Configuration
{
Expand Down Expand Up @@ -27,21 +29,22 @@ public class NetDaemonSettings
/// the apps to be in the file paths and tries to find
/// all apps recursivly
/// </remarks>
public string? AppSource { get; set; } = null;
public string? AppSource { get; set; }

/// <summary>
/// Returns the directory path of AppSource
/// Returns the directory path of AppSource
/// </summary>
public string GetAppSourceDirectory()
{
var source = AppSource?.Trim() ?? Directory.GetCurrentDirectory();

if (source.EndsWith(".csproj") || source.EndsWith(".dll"))
if (source.EndsWith(".csproj", true, CultureInfo.InvariantCulture)
|| source.EndsWith(".dll", true, CultureInfo.InvariantCulture))
{
source = Path.GetDirectoryName(source);
}

return source ?? throw new NullReferenceException("Source cannot be null!");
return source ?? throw new NetDaemonNullReferenceException("Source cannot be null!");
}
}
}
7 changes: 5 additions & 2 deletions src/App/NetDaemon.App/Common/DelayResult.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
Expand All @@ -13,7 +14,7 @@ public class DelayResult : IDelayResult
{
private readonly INetDaemonApp _daemonApp;
private readonly TaskCompletionSource<bool> _delayTaskCompletionSource;
private bool _isCanceled = false;
private bool _isCanceled;

/// <summary>
/// Constructor
Expand Down Expand Up @@ -51,7 +52,7 @@ public void Cancel()

#region IDisposable Support

private bool disposedValue = false; // To detect redundant calls
private bool disposedValue; // To detect redundant calls

/// <summary>
/// Disposes the object and cancel delay
Expand All @@ -60,6 +61,8 @@ public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Dispose(true);
// Suppress finalization.
GC.SuppressFinalize(this);
}

/// <summary>
Expand Down
66 changes: 66 additions & 0 deletions src/App/NetDaemon.App/Common/Exceptions/Exceptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;

namespace NetDaemon.Common.Exceptions
{
/// <inheritdoc/>
public class NetDaemonNullReferenceException : NullReferenceException
{
/// <inheritdoc/>
public NetDaemonNullReferenceException()
{
}

/// <inheritdoc/>
public NetDaemonNullReferenceException(string? message) : base(message)
{
}

/// <inheritdoc/>
public NetDaemonNullReferenceException(string? message, Exception? innerException) : base(message, innerException)
{
}
}

/// <inheritdoc/>
public class NetDaemonException : Exception
{
/// <inheritdoc/>
public NetDaemonException()
{
}

/// <inheritdoc/>
public NetDaemonException(string? message) : base(message)
{
}

/// <inheritdoc/>
public NetDaemonException(string? message, Exception? innerException) : base(message, innerException)
{
}
}

/// <inheritdoc/>
public class NetDaemonArgumentNullException : ArgumentNullException
{
/// <inheritdoc/>
public NetDaemonArgumentNullException()
{
}

/// <inheritdoc/>
public NetDaemonArgumentNullException(string? paramName) : base(paramName)
{
}

/// <inheritdoc/>
public NetDaemonArgumentNullException(string? message, Exception? innerException) : base(message, innerException)
{
}

/// <inheritdoc/>
public NetDaemonArgumentNullException(string? paramName, string? message) : base(paramName, message)
{
}
}
}
Loading

0 comments on commit 23a623e

Please sign in to comment.