Skip to content

Commit

Permalink
Merge pull request #135 from pkuehnel/feat/useDbChargerPilot
Browse files Browse the repository at this point in the history
feat(Model): Add TeslaMate DB Model
  • Loading branch information
pkuehnel authored Jul 3, 2022
2 parents 316adc8 + fd9abef commit dd71095
Show file tree
Hide file tree
Showing 48 changed files with 1,390 additions and 38 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ Note: TeslaMateApi has to be configured to allow any command without authenticat
| **CurrentInverterPowerJsonPattern** | string | If Power from inverter is json formated use this to extract the correct value | $.data.overage |
| **TelegramBotKey** | string | Telegram Bot API key | 1234567890:ASDFuiauhwerlfvasedr |
| **TelegramChannelId** | string | ChannelId Telegram bot should send messages to | -156480125 |
| **TeslaMateDbServer** | string | Name or IP Address of the TeslaMate database service | database |
| **TeslaMateDbPort** | int | Port of the TeslaMate database service | 5432 |
| **TeslaMateDbDatabaseName** | string | Database Name of the TeslaMate database service | teslamate |
| **TeslaMateDbUser** | string | Database user name of the TeslaMate database service | teslamate |
| **TeslaMateDbPassword** | string | Database user's password of the TeslaMate database service | secret |

### Car Priorities
If you set `CarPriorities` environment variable like the example above, the car with ID 2 will only start charing, if car 1 is charging at full speed and there is still power left, or if car 1 is not charging due to reached battery limit or not within specified geofence. Note: You always have to add the car Ids to this list separated by `|`. Even if you only have one car you need to ad the car's Id but then without `|`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace SmartTeslaAmpSetter.Model.Contracts;

public interface IDbConnectionStringHelper
{
string GetConnectionString();
}
21 changes: 21 additions & 0 deletions SmartTeslaAmpSetter.Model/Contracts/ITeslamateContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore;
using SmartTeslaAmpSetter.Model.Entities;

namespace SmartTeslaAmpSetter.Model.Contracts;

public interface ITeslamateContext
{
DbSet<Address> Addresses { get; set; }
DbSet<Car> Cars { get; set; }
DbSet<CarSetting> CarSettings { get; set; }
DbSet<Charge> Charges { get; set; }
DbSet<ChargingProcess> ChargingProcesses { get; set; }
DbSet<Drive> Drives { get; set; }
DbSet<Geofence> Geofences { get; set; }
DbSet<Position> Positions { get; set; }
DbSet<SchemaMigration> SchemaMigrations { get; set; }
DbSet<Setting> Settings { get; set; }
DbSet<State> States { get; set; }
DbSet<Token> Tokens { get; set; }
DbSet<Update> Updates { get; set; }
}
36 changes: 36 additions & 0 deletions SmartTeslaAmpSetter.Model/Entities/Address.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace SmartTeslaAmpSetter.Model.Entities
{
public class Address
{
public Address()
{
ChargingProcesses = new HashSet<ChargingProcess>();
DriveEndAddresses = new HashSet<Drive>();
DriveStartAddresses = new HashSet<Drive>();
}

public int Id { get; set; }
public string? DisplayName { get; set; }
public decimal? Latitude { get; set; }
public decimal? Longitude { get; set; }
public string? Name { get; set; }
public string? HouseNumber { get; set; }
public string? Road { get; set; }
public string? Neighbourhood { get; set; }
public string? City { get; set; }
public string? County { get; set; }
public string? Postcode { get; set; }
public string? State { get; set; }
public string? StateDistrict { get; set; }
public string? Country { get; set; }
public string? Raw { get; set; }
public DateTime InsertedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public long? OsmId { get; set; }
public string? OsmType { get; set; }

public virtual ICollection<ChargingProcess> ChargingProcesses { get; set; }
public virtual ICollection<Drive> DriveEndAddresses { get; set; }
public virtual ICollection<Drive> DriveStartAddresses { get; set; }
}
}
37 changes: 37 additions & 0 deletions SmartTeslaAmpSetter.Model/Entities/Car.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace SmartTeslaAmpSetter.Model.Entities
{
public class Car
{
public Car()
{
ChargingProcesses = new HashSet<ChargingProcess>();
Drives = new HashSet<Drive>();
Positions = new HashSet<Position>();
States = new HashSet<State>();
Updates = new HashSet<Update>();
}

public short Id { get; set; }
public long Eid { get; set; }
public long Vid { get; set; }
public string? Model { get; set; }
public double? Efficiency { get; set; }
public DateTime InsertedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public string? Vin { get; set; }
public string? Name { get; set; }
public string? TrimBadging { get; set; }
public long SettingsId { get; set; }
public string? ExteriorColor { get; set; }
public string? SpoilerType { get; set; }
public string? WheelType { get; set; }
public short DisplayPriority { get; set; }

public virtual CarSetting Settings { get; set; } = null!;
public virtual ICollection<ChargingProcess> ChargingProcesses { get; set; }
public virtual ICollection<Drive> Drives { get; set; }
public virtual ICollection<Position> Positions { get; set; }
public virtual ICollection<State> States { get; set; }
public virtual ICollection<Update> Updates { get; set; }
}
}
14 changes: 14 additions & 0 deletions SmartTeslaAmpSetter.Model/Entities/CarSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace SmartTeslaAmpSetter.Model.Entities
{
public class CarSetting
{
public long Id { get; set; }
public int SuspendMin { get; set; }
public int SuspendAfterIdleMin { get; set; }
public bool ReqNotUnlocked { get; set; }
public bool FreeSupercharging { get; set; }
public bool? UseStreamingApi { get; set; }

public virtual Car Car { get; set; } = null!;
}
}
30 changes: 30 additions & 0 deletions SmartTeslaAmpSetter.Model/Entities/Charge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace SmartTeslaAmpSetter.Model.Entities
{
public class Charge
{
public int Id { get; set; }
public DateTime Date { get; set; }
public bool? BatteryHeaterOn { get; set; }
public short? BatteryLevel { get; set; }
public decimal ChargeEnergyAdded { get; set; }
public short? ChargerActualCurrent { get; set; }
public short? ChargerPhases { get; set; }
public short? ChargerPilotCurrent { get; set; }
public short ChargerPower { get; set; }
public short? ChargerVoltage { get; set; }
public bool? FastChargerPresent { get; set; }
public string? ConnChargeCable { get; set; }
public string? FastChargerBrand { get; set; }
public string? FastChargerType { get; set; }
public decimal IdealBatteryRangeKm { get; set; }
public bool? NotEnoughPowerToHeat { get; set; }
public decimal? OutsideTemp { get; set; }
public int ChargingProcessId { get; set; }
public bool? BatteryHeater { get; set; }
public bool? BatteryHeaterNoPower { get; set; }
public decimal? RatedBatteryRangeKm { get; set; }
public short? UsableBatteryLevel { get; set; }

public virtual ChargingProcess ChargingProcess { get; set; } = null!;
}
}
35 changes: 35 additions & 0 deletions SmartTeslaAmpSetter.Model/Entities/ChargingProcess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace SmartTeslaAmpSetter.Model.Entities
{
public class ChargingProcess
{
public ChargingProcess()
{
Charges = new HashSet<Charge>();
}

public int Id { get; set; }
public DateTime StartDate { get; set; }
public DateTime? EndDate { get; set; }
public decimal? ChargeEnergyAdded { get; set; }
public decimal? StartIdealRangeKm { get; set; }
public decimal? EndIdealRangeKm { get; set; }
public short? StartBatteryLevel { get; set; }
public short? EndBatteryLevel { get; set; }
public short? DurationMin { get; set; }
public decimal? OutsideTempAvg { get; set; }
public short CarId { get; set; }
public int PositionId { get; set; }
public int? AddressId { get; set; }
public decimal? StartRatedRangeKm { get; set; }
public decimal? EndRatedRangeKm { get; set; }
public int? GeofenceId { get; set; }
public decimal? ChargeEnergyUsed { get; set; }
public decimal? Cost { get; set; }

public Address? Address { get; set; }
public Car Car { get; set; } = null!;
public Geofence? Geofence { get; set; }
public Position Position { get; set; } = null!;
public ICollection<Charge> Charges { get; set; }
}
}
43 changes: 43 additions & 0 deletions SmartTeslaAmpSetter.Model/Entities/Drive.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace SmartTeslaAmpSetter.Model.Entities
{
public class Drive
{
public Drive()
{
Positions = new HashSet<Position>();
}

public int Id { get; set; }
public DateTime StartDate { get; set; }
public DateTime? EndDate { get; set; }
public decimal? OutsideTempAvg { get; set; }
public short? SpeedMax { get; set; }
public short? PowerMax { get; set; }
public short? PowerMin { get; set; }
public decimal? StartIdealRangeKm { get; set; }
public decimal? EndIdealRangeKm { get; set; }
public double? StartKm { get; set; }
public double? EndKm { get; set; }
public double? Distance { get; set; }
public short? DurationMin { get; set; }
public short CarId { get; set; }
public decimal? InsideTempAvg { get; set; }
public int? StartAddressId { get; set; }
public int? EndAddressId { get; set; }
public decimal? StartRatedRangeKm { get; set; }
public decimal? EndRatedRangeKm { get; set; }
public int? StartPositionId { get; set; }
public int? EndPositionId { get; set; }
public int? StartGeofenceId { get; set; }
public int? EndGeofenceId { get; set; }

public Car Car { get; set; } = null!;
public Address? EndAddress { get; set; }
public Geofence? EndGeofence { get; set; }
public Position? EndPosition { get; set; }
public Address? StartAddress { get; set; }
public Geofence? StartGeofence { get; set; }
public Position? StartPosition { get; set; }
public ICollection<Position> Positions { get; set; }
}
}
26 changes: 26 additions & 0 deletions SmartTeslaAmpSetter.Model/Entities/Geofence.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace SmartTeslaAmpSetter.Model.Entities
{
public class Geofence
{
public Geofence()
{
ChargingProcesses = new HashSet<ChargingProcess>();
DriveEndGeofences = new HashSet<Drive>();
DriveStartGeofences = new HashSet<Drive>();
}

public int Id { get; set; }
public string Name { get; set; } = null!;
public decimal Latitude { get; set; }
public decimal Longitude { get; set; }
public short Radius { get; set; }
public DateTime InsertedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public decimal? CostPerUnit { get; set; }
public decimal? SessionFee { get; set; }

public ICollection<ChargingProcess> ChargingProcesses { get; set; }
public ICollection<Drive> DriveEndGeofences { get; set; }
public ICollection<Drive> DriveStartGeofences { get; set; }
}
}
45 changes: 45 additions & 0 deletions SmartTeslaAmpSetter.Model/Entities/Position.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace SmartTeslaAmpSetter.Model.Entities
{
public class Position
{
public Position()
{
ChargingProcesses = new HashSet<ChargingProcess>();
DriveEndPositions = new HashSet<Drive>();
DriveStartPositions = new HashSet<Drive>();
}

public int Id { get; set; }
public DateTime Date { get; set; }
public decimal Latitude { get; set; }
public decimal Longitude { get; set; }
public short? Speed { get; set; }
public short? Power { get; set; }
public double? Odometer { get; set; }
public decimal? IdealBatteryRangeKm { get; set; }
public short? BatteryLevel { get; set; }
public decimal? OutsideTemp { get; set; }
public short? Elevation { get; set; }
public int? FanStatus { get; set; }
public decimal? DriverTempSetting { get; set; }
public decimal? PassengerTempSetting { get; set; }
public bool? IsClimateOn { get; set; }
public bool? IsRearDefrosterOn { get; set; }
public bool? IsFrontDefrosterOn { get; set; }
public short CarId { get; set; }
public int? DriveId { get; set; }
public decimal? InsideTemp { get; set; }
public bool? BatteryHeater { get; set; }
public bool? BatteryHeaterOn { get; set; }
public bool? BatteryHeaterNoPower { get; set; }
public decimal? EstBatteryRangeKm { get; set; }
public decimal? RatedBatteryRangeKm { get; set; }
public short? UsableBatteryLevel { get; set; }

public Car Car { get; set; } = null!;
public Drive? Drive { get; set; }
public ICollection<ChargingProcess> ChargingProcesses { get; set; }
public ICollection<Drive> DriveEndPositions { get; set; }
public ICollection<Drive> DriveStartPositions { get; set; }
}
}
8 changes: 8 additions & 0 deletions SmartTeslaAmpSetter.Model/Entities/SchemaMigration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SmartTeslaAmpSetter.Model.Entities
{
public class SchemaMigration
{
public long Version { get; set; }
public DateTime? InsertedAt { get; set; }
}
}
12 changes: 12 additions & 0 deletions SmartTeslaAmpSetter.Model/Entities/Setting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace SmartTeslaAmpSetter.Model.Entities
{
public class Setting
{
public long Id { get; set; }
public DateTime InsertedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public string? BaseUrl { get; set; }
public string? GrafanaUrl { get; set; }
public string Language { get; set; } = null!;
}
}
12 changes: 12 additions & 0 deletions SmartTeslaAmpSetter.Model/Entities/State.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace SmartTeslaAmpSetter.Model.Entities
{
public class State
{
public int Id { get; set; }
public DateTime StartDate { get; set; }
public DateTime? EndDate { get; set; }
public short CarId { get; set; }

public virtual Car Car { get; set; } = null!;
}
}
11 changes: 11 additions & 0 deletions SmartTeslaAmpSetter.Model/Entities/Token.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace SmartTeslaAmpSetter.Model.Entities
{
public class Token
{
public int Id { get; set; }
public string Access { get; set; } = null!;
public string Refresh { get; set; } = null!;
public DateTime InsertedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
}
13 changes: 13 additions & 0 deletions SmartTeslaAmpSetter.Model/Entities/Update.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace SmartTeslaAmpSetter.Model.Entities
{
public class Update
{
public int Id { get; set; }
public DateTime StartDate { get; set; }
public DateTime? EndDate { get; set; }
public string? Version { get; set; }
public short CarId { get; set; }

public virtual Car Car { get; set; } = null!;
}
}
Loading

0 comments on commit dd71095

Please sign in to comment.