Files
HomeAssistant/LightMonitor.Manager/PresenceService.cs
T
gitea_admin 77458383d1 Add braces to single-statement guards and refactor NordPool price fetching
- Expand inline guard, return and logger blocks across the monitor services, init classes and tests
- Have INordPoolPriceService take a per-date fetch delegate and expose ParseAndAdjust, moving the HA fetch call into NordPoolInit so the service can be registered singleton
- Record the NordPool and boiler service lifetimes in AGENTS.md
- Drop the unused persisted-state argument from the boiler test data helper
2026-12-01 11:59:31 +02:00

40 lines
1.1 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;
}
}