Update
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user