Skip to content

Commit

Permalink
Merge b09c0a0 into c0153c4
Browse files Browse the repository at this point in the history
  • Loading branch information
helto4real committed Dec 6, 2020
2 parents c0153c4 + b09c0a0 commit 89348a4
Show file tree
Hide file tree
Showing 25 changed files with 116 additions and 108 deletions.
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

FROM mcr.microsoft.com/dotnet/sdk:5.0.100

RUN apt-get update && apt-get install openssh-client
# This Dockerfile adds a non-root 'vscode' user with sudo access. However, for Linux,
# this user's GID/UID must match your local user UID/GID to avoid permission issues
# with bind mounts. Update USER_UID / USER_GID if yours is not 1000. See
Expand Down
2 changes: 1 addition & 1 deletion src/App/NetDaemon.App/Common/AppRuntimeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public sealed class AppRuntimeInfo
/// in app switch
/// </summary>
[JsonPropertyName("app_attributes")]
public Dictionary<string, object> AppAttributes { get; set; } = new Dictionary<string, object>();
public Dictionary<string, object> AppAttributes { get; set; } = new();


}
Expand Down
2 changes: 1 addition & 1 deletion src/App/NetDaemon.App/Common/DelayResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public DelayResult(TaskCompletionSource<bool> delayTaskCompletionSource, INetDae
/// <inheritdoc/>
public Task<bool> Task => _delayTaskCompletionSource.Task;

internal ConcurrentBag<string> StateSubscriptions { get; set; } = new ConcurrentBag<string>();
internal ConcurrentBag<string> StateSubscriptions { get; set; } = new();

/// <inheritdoc/>
public void Cancel()
Expand Down
2 changes: 1 addition & 1 deletion src/App/NetDaemon.App/Common/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static dynamic ToDynamic(this (string name, object val)[] attributeNameVa

foreach (PropertyDescriptor? property in TypeDescriptor.GetProperties(obj.GetType()))
{
if (property is object)
if (property is not null)
expando.Add(property.Name, property.GetValue(obj));
}

Expand Down
6 changes: 3 additions & 3 deletions src/App/NetDaemon.App/Common/Fluent/FluentCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public IExecuteAsync PlayStream(string mediaPlayerId, string? format = null)

serviceData.media_player = mediaPlayerId;

if (format is object)
if (format is not null)
serviceData.format = format;

_serviceCall = ("play_stream", serviceData);
Expand All @@ -128,9 +128,9 @@ public IExecuteAsync Record(string fileName, int? duration = null, int? lookback

serviceData.filename = fileName;

if (duration is object)
if (duration is not null)
serviceData.duration = duration;
if (lookback is object)
if (lookback is not null)
serviceData.lookback = lookback;

_serviceCall = ("record", serviceData);
Expand Down
4 changes: 2 additions & 2 deletions src/App/NetDaemon.App/Common/Fluent/FluentExpandoObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace NetDaemon.Common.Fluent
/// </remarks>
public class FluentExpandoObject : DynamicObject, IDictionary<string, object>
{
private readonly Dictionary<string, object> _dict = new Dictionary<string, object>();
private readonly Dictionary<string, object> _dict = new();
private readonly NetDaemonAppBase? _daemonApp;
private readonly bool _ignoreCase;
private readonly bool _returnNullMissingProperties;
Expand Down Expand Up @@ -194,7 +194,7 @@ public dynamic CopyFrom(IDictionary<string, object?> obj)
if (keyValuePair.Value is JsonElement val)
{
var dynValue = val.ToDynamicValue();
if (dynValue is object)
if (dynValue is not null)
{
UpdateDictionary(keyValuePair.Key, dynValue);
}
Expand Down
2 changes: 1 addition & 1 deletion src/App/NetDaemon.App/Common/Fluent/FluentInputSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public InputSelectManager(IEnumerable<string> entityIds, INetDaemon daemon, INet
/// <inheritdoc/>
public Task ExecuteAsync()
{
List<Task> tasks = new List<Task>();
List<Task> tasks = new();
foreach (var entityId in _entityIds)
{
dynamic data = new FluentExpandoObject();
Expand Down
14 changes: 7 additions & 7 deletions src/App/NetDaemon.App/Common/Fluent/IEntityProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ public interface IEntityProperties
/// <summary>
/// Filter on area where the entity device are at
/// </summary>
string? Area { get; set; }
string? Area { get; }

/// <summary>
/// Filter on attribute
/// </summary>
dynamic? Attribute { get; set; }
dynamic? Attribute { get; }

/// <summary>
/// Filter on unique id of the entity
/// </summary>
string EntityId { get; set; }
string EntityId { get; }

/// <summary>
/// Filter on last changed time
/// </summary>
DateTime LastChanged { get; set; }
DateTime LastChanged { get; }

/// <summary>
/// Filter on last updated time
/// </summary>
DateTime LastUpdated { get; set; }
DateTime LastUpdated { get; }

/// <summary>
/// Filter on state
/// </summary>
dynamic? State { get; set; }
dynamic? State { get; }

/// <summary>
/// Context
/// </summary>
public Context? Context { get; set; }
public Context? Context { get; }
}
}
58 changes: 29 additions & 29 deletions src/App/NetDaemon.App/Common/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,98 +9,98 @@ namespace NetDaemon.Common
/// <summary>
/// Home assistant config parameters
/// </summary>
public class Config
public record Config
{
/// <summary>
/// Components being installed and used
/// </summary>
public List<string>? Components { get; set; } = null;
public List<string>? Components { get; init; } = null;

/// <summary>
/// Local config directory
/// </summary>
public string? ConfigDir { get; set; } = null;
public string? ConfigDir { get; init; } = null;

/// <summary>
/// Elevation of Home Assistant instance
/// </summary>
public int? Elevation { get; set; } = null;
public int? Elevation { get; init; } = null;

/// <summary>
/// Latitude of Home Assistant instance
/// </summary>
public float? Latitude { get; set; } = null;
public float? Latitude { get; init; } = null;

/// <summary>
/// The name of the location
/// </summary>
public string? LocationName { get; set; } = null;
public string? LocationName { get; init; } = null;

/// <summary>
/// Longitude of Home Assistant instance
/// </summary>
public float? Longitude { get; set; } = null;
public float? Longitude { get; init; } = null;

/// <summary>
/// The timezone
/// </summary>
public string? TimeZone { get; set; } = null;
public string? TimeZone { get; init; } = null;

/// <summary>
/// Unity system being configured
/// </summary>
public HassUnitSystem? UnitSystem { get; set; } = null;
public HassUnitSystem? UnitSystem { get; init; } = null;

/// <summary>
/// Current Home Assistant version
/// </summary>
public string? Version { get; set; } = null;
public string? Version { get; init; } = null;

/// <summary>
/// Whitelisted external directories
/// </summary>
public List<string>? WhitelistExternalDirs { get; set; } = null;
public List<string>? WhitelistExternalDirs { get; init; } = null;
}

/// <summary>
/// Detailed state information
/// </summary>
public class EntityState : IEntityProperties
public record EntityState : IEntityProperties
{
/// <summary>
/// The name of the Area in home assistant
/// </summary>
public string? Area { get; set; }
public string? Area { get; init; }

/// <summary>
/// Attributes of the entity
/// </summary>
public dynamic? Attribute { get; set; } = new FluentExpandoObject(true, true);
public dynamic? Attribute { get; init; } = new FluentExpandoObject(true, true);

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

/// <summary>
/// Last changed, when state changed from and to different values
/// </summary>
public DateTime LastChanged { get; set; } = DateTime.MinValue;
public DateTime LastChanged { get; init; } = DateTime.MinValue;

/// <summary>
/// Last updated, when entity state or attributes changed
/// </summary>
public DateTime LastUpdated { get; set; } = DateTime.MinValue;
public DateTime LastUpdated { get; init; } = DateTime.MinValue;

/// <summary>
/// The state
/// </summary>
public dynamic? State { get; set; } = "";
public dynamic? State { get; init; } = "";

/// <summary>
/// Context
/// </summary>
public Context? Context { get; set; }
public Context? Context { get; init; }

/// <summary>
/// returns a pretty print of EntityState
Expand All @@ -113,7 +113,7 @@ public override string ToString()
{
foreach (var key in attr.Keys)
{
if (key is object)
if (key is not null)
{
attributes = attributes + string.Format(" {0}:{1}", key, attr[key]);
}
Expand All @@ -135,48 +135,48 @@ public override string ToString()
/// <summary>
/// Unit system parameters for Home Assistant
/// </summary>
public class HassUnitSystem
public record HassUnitSystem
{
/// <summary>
/// Lenght unit
/// </summary>
public string? Length { get; set; } = null;
public string? Length { get; init; } = null;

/// <summary>
/// Mass unit
/// </summary>
public string? Mass { get; set; } = null;
public string? Mass { get; init; } = null;

/// <summary>
/// Temperature unit
/// </summary>
public string? Temperature { get; set; } = null;
public string? Temperature { get; init; } = null;

/// <summary>
/// Volume unit
/// </summary>
public string? Volume { get; set; } = null;
public string? Volume { get; init; } = null;
}

/// <summary>
/// Event from CallService
/// </summary>
public class ServiceEvent
public record ServiceEvent
{
/// <summary>
/// Home Assistant domain
/// </summary>
public string Domain { get; set; } = "";
public string Domain { get; init; } = "";

/// <summary>
/// Service being called
/// </summary>
public string Service { get; set; } = "";
public string Service { get; init; } = "";

/// <summary>
/// Data being sent by the service
/// </summary>
/// <value></value>
public JsonElement? ServiceData { get; set; } = null;
public JsonElement? ServiceData { get; init; } = null;
}
}
18 changes: 9 additions & 9 deletions src/App/NetDaemon.App/Common/NetDaemonAppBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class NetDaemonAppBase : INetDaemonAppBase
/// <summary>
/// A set of properties found in static analysis of code for each app
/// </summary>
public static Dictionary<string, Dictionary<string, string>> CompileTimeProperties { get; set; } = new Dictionary<string, Dictionary<string, string>>();
public static Dictionary<string, Dictionary<string, string>> CompileTimeProperties { get; set; } = new();

/// <summary>
/// The NetDaemonHost instance
Expand All @@ -40,9 +40,9 @@ public abstract class NetDaemonAppBase : INetDaemonAppBase


// This is declared as static since it will contain state shared globally
private static ConcurrentDictionary<string, object> _global = new ConcurrentDictionary<string, object>();
private static ConcurrentDictionary<string, object> _global = new();

private readonly ConcurrentDictionary<string, object> _attributes = new ConcurrentDictionary<string, object>();
private readonly ConcurrentDictionary<string, object> _attributes = new();

// To handle state saves max once at a time, internal due to tests
private readonly Channel<bool> _lazyStoreStateQueue =
Expand Down Expand Up @@ -120,7 +120,7 @@ public string Description
/// <param name="other">The instance to compare</param>
public bool Equals([AllowNull] INetDaemonAppBase other)
{
if (other is object && other.Id is object && this.Id is object && this.Id == other.Id)
if (other is not null && other.Id is not null && this.Id is not null && this.Id == other.Id)
return true;

return false;
Expand Down Expand Up @@ -251,7 +251,7 @@ private async Task HandleLazyStorage()
public async virtual ValueTask DisposeAsync()
{
_cancelSource.Cancel();
if (_manageRuntimeInformationUpdatesTask is object)
if (_manageRuntimeInformationUpdatesTask is not null)
await _manageRuntimeInformationUpdatesTask.ConfigureAwait(false);

_daemonCallBacksForServiceCalls.Clear();
Expand Down Expand Up @@ -283,7 +283,7 @@ public void ListenServiceCall(string domain, string service, Func<dynamic?, Task
/// <inheritdoc/>
public void Log(LogLevel level, string message, params object[] param)
{
if (param is object && param.Length > 0)
if (param is not null && param.Length > 0)
{
var result = param.Prepend(Id).ToArray();
Logger.Log(level, $" {{Id}}: {message}", result);
Expand All @@ -300,7 +300,7 @@ public void Log(LogLevel level, string message, params object[] param)
/// <inheritdoc/>
public void Log(LogLevel level, Exception exception, string message, params object[] param)
{
if (param is object && param.Length > 0)
if (param is not null && param.Length > 0)
{
var result = param.Prepend(Id).ToArray();
Logger.Log(level, exception, $" {{Id}}: {message}", result);
Expand Down Expand Up @@ -399,7 +399,7 @@ public void LogError(Exception exception, string message, params object[] param)
/// <inheritdoc/>
public void SetAttribute(string attribute, object? value)
{
if (value is object)
if (value is not null)
{
RuntimeInfo.AppAttributes[attribute] = value;
}
Expand Down Expand Up @@ -452,7 +452,7 @@ private async Task HandleUpdateRuntimeInformation()
{
_ = _daemon ?? throw new NullReferenceException($"{nameof(_daemon)} cant be null!");

if (RuntimeInfo.LastErrorMessage is object)
if (RuntimeInfo.LastErrorMessage is not null)
{
RuntimeInfo.HasError = true;
}
Expand Down
Loading

0 comments on commit 89348a4

Please sign in to comment.