f919d6b25b
- Wrap using directives in `#region` blocks across the Battery, Boiler and NordPool sources and tests - Expand single-statement guards and loops into braced blocks - Realign wrapped method arguments, chained calls and continuations - Replace target-typed `new()` with explicit generic construction and empty string literals with `string.Empty` - Flatten the boiler config expression and reindent the remaining touched files
47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
#region
|
|
|
|
using LightMonitor.Models;
|
|
using LightMonitorManager.Interface;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using NetDaemon.HassModel;
|
|
|
|
#endregion
|
|
|
|
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;
|
|
}
|
|
} |