Improves parking state detection and logging
All checks were successful
Build, Push and Run Container / build (push) Successful in 28s

Enhances parking state logic by setting the initial gear to "P" and adding more detailed logging for state changes and parking events.

This provides better insight into vehicle states and parking behaviors.
This commit is contained in:
2025-08-21 09:41:51 +02:00
parent c0a14e070c
commit df999abf6c
2 changed files with 13 additions and 3 deletions

View File

@@ -2,7 +2,7 @@ namespace ProofOfConcept.Models;
public class TeslaState public class TeslaState
{ {
private string gear = ""; private string gear = "P";
private bool locked; private bool locked;
private bool driverSeatOccupied; private bool driverSeatOccupied;
private bool gpsState; private bool gpsState;

View File

@@ -69,12 +69,18 @@ public class MessageProcessor : IMessageProcessor
} }
} }
this.logger.LogTrace("State updated"); this.logger.LogTrace("State updated for {VIN}. Current state is Gear: {Gear}, Locked: {locked}, driver seat occupied: {DriverSeatOccupied}, Location: {Latitude},{Longitude}", vin, this.teslaState.Gear, this.teslaState.Locked, this.teslaState.DriverSeatOccupied, this.teslaState.Latitude, this.teslaState.Longitude);
if (this.teslaState is { Gear: "P", Locked: true, DriverSeatOccupied: false }) if (this.teslaState is { Gear: "P", Locked: true, DriverSeatOccupied: false })
{
this.parkingState.SetCarParked(); this.parkingState.SetCarParked();
this.logger.LogInformation("{vin} is in parked state", vin);
}
else else
{
this.parkingState.SetCarMoved(); this.parkingState.SetCarMoved();
this.logger.LogInformation("{vin} moved (not parking anymore)", vin);
}
if (this.parkingState is { ParkingInProgress: false, CarParked: true }) if (this.parkingState is { ParkingInProgress: false, CarParked: true })
await StartParkingAsync(vin); await StartParkingAsync(vin);
@@ -85,6 +91,8 @@ public class MessageProcessor : IMessageProcessor
private async Task StartParkingAsync(string vin) private async Task StartParkingAsync(string vin)
{ {
this.logger.LogTrace("Start parking for {vin}...", vin);
//Get parking zone //Get parking zone
Result<string> zoneLookupResult = await this.zoneDeterminatorService.DetermineZoneCodeAsync(this.teslaState.Latitude, this.teslaState.Longitude); Result<string> zoneLookupResult = await this.zoneDeterminatorService.DetermineZoneCodeAsync(this.teslaState.Latitude, this.teslaState.Longitude);
bool sendNotification = this.configuration.VinNotifications.TryGetValue(vin, out string? pushoverToken); bool sendNotification = this.configuration.VinNotifications.TryGetValue(vin, out string? pushoverToken);
@@ -124,6 +132,8 @@ public class MessageProcessor : IMessageProcessor
private async Task StopParkingAsync(string vin) private async Task StopParkingAsync(string vin)
{ {
this.logger.LogTrace("Stopping parking for {vin}...", vin);
// Push parking stopped // Push parking stopped
this.parkingState.SetParkingStopped(); this.parkingState.SetParkingStopped();
if (this.configuration.VinNotifications.TryGetValue(vin, out string? pushoverToken)) if (this.configuration.VinNotifications.TryGetValue(vin, out string? pushoverToken))