This commit is contained in:
2026-06-28 13:58:35 +03:00
parent 8f45028715
commit e6bf8258bb
114 changed files with 4365 additions and 874 deletions
+10 -20
View File
@@ -7,42 +7,32 @@ using LightMonitorManager.Models;
namespace LightMonitorManager;
public sealed class PresenceService : IPresenceService
public sealed class PresenceService(
IHaContext haContext,
ILogger<PresenceService> logger,
IOptions<LightMonitorOptions> options) : IPresenceService
{
private readonly IHaContext _haContext;
private readonly ILogger<PresenceService> _logger;
private readonly LightMonitorOptions _options;
public PresenceService(
IHaContext haContext,
ILogger<PresenceService> logger,
IOptions<LightMonitorOptions> options)
{
_haContext = haContext;
_logger = logger;
_options = options.Value;
}
private readonly LightMonitorOptions _options = options.Value;
public bool IsAnyoneHome()
{
foreach (var personEntityId in _options.PersonEntityIds)
{
var state = _haContext.GetState(personEntityId);
var state = haContext.GetState(personEntityId);
if (state?.State is null or "unavailable" or "unknown")
if (state?.State is null or LightMonitorConsts.UnavailableState or LightMonitorConsts.UnknownState)
{
_logger.LogDebug("Person entity {EntityId} state unavailable", personEntityId);
continue;
}
if (string.Equals(state.State, LightMonitorConsts.PersonHomeState, StringComparison.OrdinalIgnoreCase))
{
_logger.LogDebug("Person {EntityId} is home", personEntityId);
logger.LogDebug("Person {EntityId} is home", personEntityId);
return true;
}
}
_logger.LogDebug("No person is currently home");
return false;
}
}