Skip to content

Commit 7fbcc0f

Browse files
Added [NotNullWhen(true)] (#856)
1 parent 29e891d commit 7fbcc0f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/HassModel/NetDeamon.HassModel/Entities/EntityExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ public static class EntityExtensions
1010
/// </summary>
1111
/// <param name="entityState">The state to check</param>
1212
/// <returns>true if the state equals "on", otherwise false</returns>
13-
public static bool IsOn(this EntityState? entityState) => string.Equals(entityState?.State, "on", StringComparison.OrdinalIgnoreCase);
13+
public static bool IsOn([NotNullWhen(true)] this EntityState? entityState) => string.Equals(entityState?.State, "on", StringComparison.OrdinalIgnoreCase);
1414

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

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

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

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

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

0 commit comments

Comments
 (0)