Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/HassModel/NetDeamon.HassModel/Entities/EntityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ public static class EntityExtensions
/// </summary>
/// <param name="entityState">The state to check</param>
/// <returns>true if the state equals "on", otherwise false</returns>
public static bool IsOn(this EntityState? entityState) => string.Equals(entityState?.State, "on", StringComparison.OrdinalIgnoreCase);
public static bool IsOn([NotNullWhen(true)] this EntityState? entityState) => string.Equals(entityState?.State, "on", StringComparison.OrdinalIgnoreCase);

/// <summary>
/// Checks if an EntityState has the state "off"
/// </summary>
/// <param name="entityState">The state to check</param>
/// <returns>true if the state equals "off", otherwise false</returns>
public static bool IsOff(this EntityState? entityState) => string.Equals(entityState?.State, "off", StringComparison.OrdinalIgnoreCase);
public static bool IsOff([NotNullWhen(true)] this EntityState? entityState) => string.Equals(entityState?.State, "off", StringComparison.OrdinalIgnoreCase);

/// <summary>
/// Checks if an Entity has the state "on"
/// </summary>
/// <param name="entity">The state to check</param>
/// <returns>true if the state equals "on", otherwise false</returns>
public static bool IsOn(this Entity? entity) => entity?.EntityState?.IsOn() ?? false;
public static bool IsOn([NotNullWhen(true)] this Entity? entity) => entity?.EntityState?.IsOn() ?? false;

/// <summary>
/// Checks if an Entity has the state "off"
/// </summary>
/// <param name="entity">The state to check</param>
/// <returns>true if the state equals "off", otherwise false</returns>
public static bool IsOff(this Entity? entity) => entity?.EntityState?.IsOff() ?? false;
public static bool IsOff([NotNullWhen(true)] this Entity? entity) => entity?.EntityState?.IsOff() ?? false;

/// <summary>Gets a NumericEntity from a given Entity</summary>
public static NumericEntity AsNumeric(this Entity entity) => new(entity);
Expand All @@ -56,4 +56,4 @@ public static NumericEntity<TAttributes> WithAttributesAs<TAttributes>(this Nume

internal static IObservable<T> StateChangesOnly<T>(this IObservable<T> changes) where T : StateChange
=> changes.Where(c => c.New?.State != c.Old?.State);
}
}