24729ee267
- 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
35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
using LightMonitor.Models;
|
|
using LightMonitorManager.Interface;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using NetDaemon.HassModel;
|
|
|
|
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)) continue;
|
|
|
|
if (logger.IsEnabled(LogLevel.Debug)) logger.LogDebug("Person {EntityId} is home", personEntityId);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |