Files
HomeAssistant/LightMonitor.Manager/PresenceService.cs
T
gitea_admin ada3c77778 Fix culture-sensitive parsing, log swallowing and closure capture
- DateTimeTypeConverter parses with the invariant culture instead of the
  ambient one (NordPool timestamps arrive as ISO-8601)
- Shower last-shower-time state is formatted with the invariant culture
- PresenceServiceTests no longer captures the loop variable in a Moq setup
- CheapestIntervalsFinderTests compare prices with a tolerance instead of
  floating-point equality
- MqttRecreateApp logs the unit_of_measurement read failure instead of
  silently swallowing every exception
- LightMonitorOptions moves to LightMonitor.Models so the namespace matches
  the project and file location
2026-11-29 21:31:45 +02:00

39 lines
1.1 KiB
C#

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NetDaemon.HassModel;
using LightMonitor.Models;
using LightMonitorManager.Interface;
namespace LightMonitorManager;
public sealed class PresenceService(
IHaContext haContext,
ILogger<PresenceService> logger,
IOptions<LightMonitorOptions> options) : IPresenceService
{
private readonly LightMonitorOptions _options = options.Value;
public bool IsAnyoneHome()
{
foreach (var personEntityId in _options.PersonEntityIds)
{
var state = haContext.GetState(personEntityId);
if (state?.State is null or LightMonitorConsts.UnavailableState or LightMonitorConsts.UnknownState)
{
continue;
}
if (string.Equals(state.State, LightMonitorConsts.PersonHomeState, StringComparison.OrdinalIgnoreCase))
{
logger.LogDebug("Person {EntityId} is home", personEntityId);
return true;
}
}
return false;
}
}