Update
This commit is contained in:
@@ -29,7 +29,8 @@ public sealed class BoilerMonitorEntityService(
|
||||
BudgetPercentageEntityId,
|
||||
BudgetExhaustedEntityId,
|
||||
SessionCountEntityId,
|
||||
BudgetOverrideEntityId
|
||||
BudgetOverrideEntityId,
|
||||
AutoManagementEntityId
|
||||
];
|
||||
|
||||
private static object CreateDeviceBlock() => new
|
||||
@@ -77,7 +78,8 @@ public sealed class BoilerMonitorEntityService(
|
||||
ResetBudgetPercentageAsync(),
|
||||
ResetBudgetExhaustedAsync(),
|
||||
ResetSessionCountAsync(),
|
||||
ResetBudgetOverrideAsync()
|
||||
ResetBudgetOverrideAsync(),
|
||||
ResetAutoManagementAsync()
|
||||
).ConfigureAwait(false);
|
||||
|
||||
logger.LogInformation("All BoilerMonitor runtime entity states reset to defaults");
|
||||
@@ -280,6 +282,10 @@ public sealed class BoilerMonitorEntityService(
|
||||
new BoilerMonitorEntity("switch", "boilermonitor_budget_override", "Override budget enforcement")
|
||||
{
|
||||
AdditionalConfig = new { optimistic = true, icon = "mdi:shield-off-outline", device }
|
||||
},
|
||||
new BoilerMonitorEntity("switch", "boilermonitor_auto_management", "Automatic boiler control")
|
||||
{
|
||||
AdditionalConfig = new { optimistic = true, icon = "mdi:robot-outline", device }
|
||||
}
|
||||
];
|
||||
}
|
||||
@@ -366,6 +372,11 @@ public sealed class BoilerMonitorEntityService(
|
||||
await SetEntityStateSafe(BudgetOverrideEntityId, "OFF").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task ResetAutoManagementAsync()
|
||||
{
|
||||
await SetEntityStateSafe(AutoManagementEntityId, "ON").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task UpdateWaterReadyAsync(BoilerMonitorUpdateContext ctx, string timestamp)
|
||||
{
|
||||
await SetEntityStateSafe(WaterReadyEntityId, ctx.WaterReady ? "yes" : "no").ConfigureAwait(false);
|
||||
@@ -373,6 +384,7 @@ public sealed class BoilerMonitorEntityService(
|
||||
{
|
||||
boiler_switch_state = ctx.BoilerSwitchState ?? "unknown",
|
||||
boiler_power_watts = ctx.BoilerPowerWatts,
|
||||
cooldown_since = ctx.CooldownSince?.ToString("O"),
|
||||
friendly_name = "Boiler water ready",
|
||||
last_updated = timestamp
|
||||
}).ConfigureAwait(false);
|
||||
@@ -429,6 +441,45 @@ public sealed class BoilerMonitorEntityService(
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public DateTimeOffset? ReadPersistedCooldownTimestamp()
|
||||
{
|
||||
try
|
||||
{
|
||||
var entity = haContext.GetState(WaterReadyEntityId);
|
||||
if (entity?.Attributes is not IDictionary<string, object> attributes)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!attributes.TryGetValue("cooldown_since", out var value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var stringValue = value switch
|
||||
{
|
||||
string s => s,
|
||||
System.Text.Json.JsonElement { ValueKind: System.Text.Json.JsonValueKind.String } jsonElement =>
|
||||
jsonElement.GetString(),
|
||||
_ => null
|
||||
};
|
||||
|
||||
if (stringValue is not null &&
|
||||
DateTimeOffset.TryParse(stringValue, CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.RoundtripKind, out var parsed))
|
||||
{
|
||||
logger.LogInformation("Read persisted cooldown timestamp: {CooldownSince}", parsed);
|
||||
return parsed;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Error reading persisted cooldown timestamp");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task SetEntityStateSafe(string entityId, string state)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user