using LightMonitor.Models;
using LightMonitorManager.Models;
using NetDaemon.HassModel.Entities;
namespace LightMonitor.Manager.Tests;
///
/// 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.
///
internal static class LightMonitorTestData
{
public const string LightEntityId = "light.sonoff_1002214d40";
public const string SunEntityId = "sun.sun";
public const string PrimaryPersonEntityId = "person.marius";
public const string SecondaryPersonEntityId = "person.erika";
public const string PhonePersonEntityId = "person.home_phone";
public static readonly string[] PersonEntityIds =
[
PrimaryPersonEntityId,
SecondaryPersonEntityId,
PhonePersonEntityId
];
private static readonly string?[] PresenceStates =
[
LightMonitorConsts.PersonHomeState,
"not_home",
LightMonitorConsts.UnavailableState,
null
];
///
/// Builds light monitor options with production-compatible defaults.
///
public static LightMonitorOptions CreateOptions(
string lightEntityId = LightEntityId,
string sunEntityId = SunEntityId,
IEnumerable? personEntityIds = null,
bool enabled = true) => new()
{
Enabled = enabled,
LightEntityId = lightEntityId,
SunEntityId = sunEntityId,
PersonEntityIds = personEntityIds?.ToArray() ?? [.. PersonEntityIds]
};
///
/// Builds an carrying .
///
public static EntityState CreateState(string? state) => new() { State = state };
///
/// Builds an , or null when the entity has no state at all
/// (as returned by IHaContext.GetState for a missing entity).
///
public static EntityState? CreateOptionalState(string? state) =>
state is null ? null : CreateState(state);
///
/// Sun states that should (true) or should not (false) cause a light turn on.
/// "below_horizon" is compared case-insensitively; unavailable, unknown, blank and
/// missing states must never turn the light on.
///
public static TheoryData SunStateTurnOnCases { get; } = new()
{
{ LightMonitorConsts.SunBelowHorizon, true },
{ LightMonitorConsts.SunBelowHorizon.ToUpperInvariant(), true },
{ "Below_Horizon", true },
{ LightMonitorConsts.SunAboveHorizon, false },
{ LightMonitorConsts.SunAboveHorizon.ToUpperInvariant(), false },
{ LightMonitorConsts.UnavailableState, false },
{ LightMonitorConsts.UnknownState, false },
{ string.Empty, false },
{ " ", false },
{ null, false }
};
///
/// 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.
///
public static TheoryData LightStateTurnOnCases { get; } = new()
{
{ LightMonitorConsts.LightOnState, false },
{ LightMonitorConsts.LightOnState.ToUpperInvariant(), false },
{ "On", false },
{ "off", true },
{ "OFF", true },
{ LightMonitorConsts.UnavailableState, true },
{ LightMonitorConsts.UnknownState, true },
{ string.Empty, true },
{ " ", true },
{ null, true }
};
///
/// Person states checked against the "arrived home" transition.
/// Only "home" in any casing counts.
///
public static TheoryData PersonNewStateCases { get; } = new()
{
{ LightMonitorConsts.PersonHomeState, true },
{ "HOME", true },
{ "Home", true },
{ "hOmE", true },
{ "not_home", false },
{ "not_home ", false },
{ LightMonitorConsts.UnavailableState, false },
{ LightMonitorConsts.UnknownState, false },
{ string.Empty, false },
{ " ", false },
{ null, false }
};
///
/// 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.
///
public static TheoryData PersonArrivalTransitions { get; } = new()
{
{ "not_home", true },
{ "work", true },
{ string.Empty, true },
{ LightMonitorConsts.UnavailableState, false },
{ LightMonitorConsts.UnknownState, false },
{ null, false }
};
///
/// Old sun states for a transition to "below_horizon". Recovery from unavailable, unknown
/// or missing state must be ignored.
///
public static TheoryData SunBelowHorizonTransitions { get; } = new()
{
{ LightMonitorConsts.SunAboveHorizon, true },
{ string.Empty, true },
{ LightMonitorConsts.UnavailableState, false },
{ LightMonitorConsts.UnknownState, false },
{ null, false }
};
///
/// Every 4^3 = 64 combination of home / not_home / unavailable / missing state across the
/// three configured person entities.
///
public static TheoryData PresenceStateMatrix { get; } = CreatePresenceStateMatrix();
///
/// Person id configurations that resolve to "nobody tracked".
///
public static TheoryData NoPersonEntityIdSets { get; } = new()
{
{ [] },
{ [string.Empty] },
{ [" "] }
};
private static TheoryData CreatePresenceStateMatrix()
{
var matrix = new TheoryData();
foreach (var first in PresenceStates)
{
foreach (var second in PresenceStates)
{
foreach (var third in PresenceStates)
{
matrix.Add([first, second, third]);
}
}
}
return matrix;
}
}