Apply code formatting cleanup across monitor projects
- Reindent appsettings.json and the MSBuild project files - Collapse single-statement guard blocks and tidy using and member order - Normalize XML doc indentation and file endings - Reorder BatteryMonitor test-data helpers and move the exclusion tests into their own region - Carry the same formatting through the boiler config, control, entity and test files
This commit is contained in:
@@ -4,9 +4,9 @@ using NetDaemon.HassModel.Entities;
|
||||
namespace LightMonitor.Manager.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Deterministic, reusable fixtures for the LightMonitor tests.
|
||||
/// Keeping the option builder, state builders and generated state tables here
|
||||
/// avoids copy-pasted setup across the test classes.
|
||||
/// Deterministic, reusable fixtures for the LightMonitor tests.
|
||||
/// Keeping the option builder, state builders and generated state tables here
|
||||
/// avoids copy-pasted setup across the test classes.
|
||||
/// </summary>
|
||||
internal static class LightMonitorTestData
|
||||
{
|
||||
@@ -33,36 +33,9 @@ internal static class LightMonitorTestData
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Builds light monitor options with production-compatible defaults.
|
||||
/// </summary>
|
||||
public static LightMonitorOptions CreateOptions(
|
||||
string lightEntityId = LightEntityId,
|
||||
string sunEntityId = SunEntityId,
|
||||
IEnumerable<string>? personEntityIds = null,
|
||||
bool enabled = true) => new()
|
||||
{
|
||||
Enabled = enabled,
|
||||
LightEntityId = lightEntityId,
|
||||
SunEntityId = sunEntityId,
|
||||
PersonEntityIds = personEntityIds?.ToArray() ?? [.. PersonEntityIds]
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Builds an <see cref="EntityState"/> carrying <paramref name="state"/>.
|
||||
/// </summary>
|
||||
public static EntityState CreateState(string? state) => new() { State = state };
|
||||
|
||||
/// <summary>
|
||||
/// Builds an <see cref="EntityState"/>, or <c>null</c> when the entity has no state at all
|
||||
/// (as returned by <c>IHaContext.GetState</c> for a missing entity).
|
||||
/// </summary>
|
||||
public static EntityState? CreateOptionalState(string? state) =>
|
||||
state is null ? null : CreateState(state);
|
||||
|
||||
/// <summary>
|
||||
/// Sun states that should (<c>true</c>) or should not (<c>false</c>) cause a light turn on.
|
||||
/// "below_horizon" is compared case-insensitively; unavailable, unknown, blank and
|
||||
/// missing states must never turn the light on.
|
||||
/// Sun states that should (<c>true</c>) or should not (<c>false</c>) cause a light turn on.
|
||||
/// "below_horizon" is compared case-insensitively; unavailable, unknown, blank and
|
||||
/// missing states must never turn the light on.
|
||||
/// </summary>
|
||||
public static TheoryData<string?, bool> SunStateTurnOnCases { get; } = new()
|
||||
{
|
||||
@@ -79,8 +52,8 @@ internal static class LightMonitorTestData
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Light states evaluated while the sun is below the horizon. Only "on" (any casing)
|
||||
/// suppresses the turn on call; everything else, including missing state, turns it on.
|
||||
/// Light states evaluated while the sun is below the horizon. Only "on" (any casing)
|
||||
/// suppresses the turn on call; everything else, including missing state, turns it on.
|
||||
/// </summary>
|
||||
public static TheoryData<string?, bool> LightStateTurnOnCases { get; } = new()
|
||||
{
|
||||
@@ -97,8 +70,8 @@ internal static class LightMonitorTestData
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Person states checked against the "arrived home" transition.
|
||||
/// Only "home" in any casing counts.
|
||||
/// Person states checked against the "arrived home" transition.
|
||||
/// Only "home" in any casing counts.
|
||||
/// </summary>
|
||||
public static TheoryData<string?, bool> PersonNewStateCases { get; } = new()
|
||||
{
|
||||
@@ -116,8 +89,8 @@ internal static class LightMonitorTestData
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Old person states for a transition to "home". Recovery from unavailable, unknown or
|
||||
/// missing state must be ignored; every other old state is a real arrival.
|
||||
/// Old person states for a transition to "home". Recovery from unavailable, unknown or
|
||||
/// missing state must be ignored; every other old state is a real arrival.
|
||||
/// </summary>
|
||||
public static TheoryData<string?, bool> PersonArrivalTransitions { get; } = new()
|
||||
{
|
||||
@@ -130,8 +103,8 @@ internal static class LightMonitorTestData
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Old sun states for a transition to "below_horizon". Recovery from unavailable, unknown
|
||||
/// or missing state must be ignored.
|
||||
/// Old sun states for a transition to "below_horizon". Recovery from unavailable, unknown
|
||||
/// or missing state must be ignored.
|
||||
/// </summary>
|
||||
public static TheoryData<string?, bool> SunBelowHorizonTransitions { get; } = new()
|
||||
{
|
||||
@@ -143,13 +116,13 @@ internal static class LightMonitorTestData
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Every 4^3 = 64 combination of home / not_home / unavailable / missing state across the
|
||||
/// three configured person entities.
|
||||
/// Every 4^3 = 64 combination of home / not_home / unavailable / missing state across the
|
||||
/// three configured person entities.
|
||||
/// </summary>
|
||||
public static TheoryData<string?[]> PresenceStateMatrix { get; } = CreatePresenceStateMatrix();
|
||||
|
||||
/// <summary>
|
||||
/// Person id configurations that resolve to "nobody tracked".
|
||||
/// Person id configurations that resolve to "nobody tracked".
|
||||
/// </summary>
|
||||
public static TheoryData<string[]> NoPersonEntityIdSets { get; } =
|
||||
[
|
||||
@@ -158,21 +131,50 @@ internal static class LightMonitorTestData
|
||||
[" "]
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Builds light monitor options with production-compatible defaults.
|
||||
/// </summary>
|
||||
public static LightMonitorOptions CreateOptions(
|
||||
string lightEntityId = LightEntityId,
|
||||
string sunEntityId = SunEntityId,
|
||||
IEnumerable<string>? personEntityIds = null,
|
||||
bool enabled = true)
|
||||
{
|
||||
return new LightMonitorOptions
|
||||
{
|
||||
Enabled = enabled,
|
||||
LightEntityId = lightEntityId,
|
||||
SunEntityId = sunEntityId,
|
||||
PersonEntityIds = personEntityIds?.ToArray() ?? [.. PersonEntityIds]
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds an <see cref="EntityState" /> carrying <paramref name="state" />.
|
||||
/// </summary>
|
||||
public static EntityState CreateState(string? state)
|
||||
{
|
||||
return new EntityState { State = state };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds an <see cref="EntityState" />, or <c>null</c> when the entity has no state at all
|
||||
/// (as returned by <c>IHaContext.GetState</c> for a missing entity).
|
||||
/// </summary>
|
||||
public static EntityState? CreateOptionalState(string? state)
|
||||
{
|
||||
return state is null ? null : CreateState(state);
|
||||
}
|
||||
|
||||
private static TheoryData<string?[]> CreatePresenceStateMatrix()
|
||||
{
|
||||
var matrix = new TheoryData<string?[]>();
|
||||
|
||||
foreach (var first in PresenceStates)
|
||||
{
|
||||
foreach (var second in PresenceStates)
|
||||
{
|
||||
foreach (var third in PresenceStates)
|
||||
{
|
||||
matrix.Add([first, second, third]);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var second in PresenceStates)
|
||||
foreach (var third in PresenceStates)
|
||||
matrix.Add([first, second, third]);
|
||||
|
||||
return matrix;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user