feat: add BatteryMonitor implementation with discovery, notification, and scheduling services
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
namespace ShowerMonitor.Models.Enums;
|
||||
|
||||
public enum ShowerState
|
||||
{
|
||||
Idle,
|
||||
Suspected,
|
||||
Active,
|
||||
Declining,
|
||||
Completed
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>ShowerMonitor.Models</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HomeAssistant.Models\HomeAssistant.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NetDaemon.Extensions.Mqtt" Version="26.11.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace ShowerMonitor.Models;
|
||||
|
||||
public static class ShowerMonitorConsts
|
||||
{
|
||||
public const int DefaultPollIntervalSeconds = 30;
|
||||
|
||||
public const double DefaultSpikeRateThreshold = 4.0;
|
||||
public const double DefaultMinDifferentialHumidity = 8.0;
|
||||
public const double DefaultPeakHumidityThreshold = 58.0;
|
||||
public const int DefaultConfirmationWindowMinutes = 2;
|
||||
public const double DefaultRecoveryDifferentialThreshold = 5.0;
|
||||
public const int DefaultRateWindowSize = 5;
|
||||
|
||||
public static readonly TimeSpan DefaultMaxShowerDuration = TimeSpan.FromMinutes(60);
|
||||
public static readonly TimeSpan DefaultFanRunAfterShower = TimeSpan.FromMinutes(10);
|
||||
|
||||
public const string BathroomHumidityEntityId = "sensor.bathroom_humidity";
|
||||
public const string MainHomeHumidityEntityId = "sensor.main_home_humidity";
|
||||
public const string BathroomTemperatureEntityId = "sensor.bathroom_temperature";
|
||||
public const string ExhaustFanEntityId = "switch.exhaust_fan";
|
||||
|
||||
public const string ActiveEntityId = "binary_sensor.showermonitor_active";
|
||||
public const string StateEntityId = "sensor.showermonitor_state";
|
||||
public const string DifferentialEntityId = "sensor.showermonitor_differential_humidity";
|
||||
public const string HumidityRateEntityId = "sensor.showermonitor_humidity_rate";
|
||||
public const string TodaySessionCountEntityId = "sensor.showermonitor_today_session_count";
|
||||
public const string LastShowerDurationEntityId = "sensor.showermonitor_last_shower_duration";
|
||||
public const string LastShowerTimeEntityId = "sensor.showermonitor_last_shower_time";
|
||||
public const string CleanupButtonEntityId = "button.showermonitor_cleanup";
|
||||
|
||||
public const string DeviceIdentifier = "shower_monitor";
|
||||
public const string DeviceName = "Shower Monitor";
|
||||
public const string DeviceManufacturer = "HomeAssistant App Daemon";
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using HomeAssistant.Models;
|
||||
using NetDaemon.Extensions.MqttEntityManager;
|
||||
|
||||
namespace ShowerMonitor.Models;
|
||||
|
||||
public class ShowerMonitorEntity : EntityCreateModel
|
||||
{
|
||||
public string Domain { get; set; }
|
||||
public string Identifier { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public ShowerMonitorEntity(string domain, string identifier, string name)
|
||||
{
|
||||
Domain = domain;
|
||||
Identifier = identifier;
|
||||
EntityId = $"{Domain}.{Identifier}";
|
||||
Name = string.IsNullOrWhiteSpace(name) ? identifier : name;
|
||||
|
||||
Options = new EntityCreationOptions
|
||||
{
|
||||
UniqueId = EntityId,
|
||||
Name = Name
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace ShowerMonitor.Models;
|
||||
|
||||
public sealed class ShowerSession
|
||||
{
|
||||
public required DateTimeOffset StartTime { get; init; }
|
||||
public DateTimeOffset? EndTime { get; set; }
|
||||
public double PreEventHumidity { get; init; }
|
||||
public double PeakHumidity { get; set; }
|
||||
public DateTimeOffset? PeakTime { get; set; }
|
||||
|
||||
public TimeSpan Duration => EndTime.HasValue
|
||||
? EndTime.Value - StartTime
|
||||
: DateTimeOffset.UtcNow - StartTime;
|
||||
}
|
||||
Reference in New Issue
Block a user