feat: add device relay and telemetry support
This commit is contained in:
@@ -11,6 +11,8 @@ public sealed class GreenHomeDbContext : DbContext
|
||||
public DbSet<Domain.DeviceSettings> DeviceSettings => Set<Domain.DeviceSettings>();
|
||||
public DbSet<Domain.AlertCondition> AlertConditions => Set<Domain.AlertCondition>();
|
||||
public DbSet<Domain.AlertRule> AlertRules => Set<Domain.AlertRule>();
|
||||
public DbSet<Domain.DeviceRelay> DeviceRelays => Set<Domain.DeviceRelay>();
|
||||
public DbSet<Domain.RelayRule> RelayRules => Set<Domain.RelayRule>();
|
||||
public DbSet<Domain.User> Users => Set<Domain.User>();
|
||||
public DbSet<Domain.VerificationCode> VerificationCodes => Set<Domain.VerificationCode>();
|
||||
public DbSet<Domain.DeviceUser> DeviceUsers => Set<Domain.DeviceUser>();
|
||||
@@ -82,6 +84,39 @@ public sealed class GreenHomeDbContext : DbContext
|
||||
.HasForeignKey(x => x.DeviceId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
b.HasIndex(x => x.DeviceId).IsUnique();
|
||||
b.HasMany(x => x.Relays)
|
||||
.WithOne(r => r.DeviceSettings)
|
||||
.HasForeignKey(r => r.DeviceSettingsId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Domain.DeviceRelay>(b =>
|
||||
{
|
||||
b.ToTable("DeviceRelays");
|
||||
b.HasKey(x => x.Id);
|
||||
b.Property(x => x.RelayIndex).IsRequired();
|
||||
b.Property(x => x.Name).HasMaxLength(100);
|
||||
b.Property(x => x.RelayKind).IsRequired().HasConversion<int>();
|
||||
b.Property(x => x.Mode).IsRequired().HasConversion<int>();
|
||||
b.HasIndex(x => new { x.DeviceSettingsId, x.RelayIndex }).IsUnique();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Domain.RelayRule>(b =>
|
||||
{
|
||||
b.ToTable("RelayRules");
|
||||
b.HasKey(x => x.Id);
|
||||
b.Property(x => x.SensorType).IsRequired().HasConversion<int>();
|
||||
b.Property(x => x.ComparisonType).IsRequired().HasConversion<int>();
|
||||
b.Property(x => x.Action).IsRequired().HasConversion<int>();
|
||||
b.Property(x => x.TimeType).IsRequired().HasConversion<int>();
|
||||
b.Property(x => x.Value1).IsRequired().HasColumnType("decimal(18,2)");
|
||||
b.Property(x => x.Value2).HasColumnType("decimal(18,2)");
|
||||
b.Property(x => x.Order).IsRequired();
|
||||
b.HasOne(x => x.DeviceRelay)
|
||||
.WithMany(r => r.Rules)
|
||||
.HasForeignKey(x => x.DeviceRelayId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
b.HasIndex(x => x.DeviceRelayId);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Domain.AlertCondition>(b =>
|
||||
|
||||
Reference in New Issue
Block a user