Skip to content

Commit

Permalink
Merge pull request #1330 from pkuehnel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pkuehnel authored Jun 17, 2024
2 parents 8b3bd00 + e1e988a commit 9a38dc5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
9 changes: 9 additions & 0 deletions TeslaSolarCharger/Client/Pages/BaseConfiguration.razor
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ else
<hr />
}
<h3>TeslaMate:</h3>
<div class="mb-3">
<InputCheckbox class="form-check-input" id="useTeslaMateAsDataSource" @bind-Value="_dtoBaseConfiguration.UseTeslaMateAsDataSource" />
<label class="form-check-label" for="useTeslaMateAsDataSource">
Use TeslaMate as car data source
</label>
<div>
<small id="useTeslaMateAsDataSourceHelp" class="form-text text-muted">If enabled TeslaMate MQTT is used as datasource. If disabled Tesla API is directly called.</small>
</div>
</div>
<InputComponent ValueId="teslaMateDbUser"
LabelText="TeslaMate Database Username"
UnitText=""
Expand Down
14 changes: 8 additions & 6 deletions TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ public async Task StartCharging(int carId, int startAmp, CarStateEnum? carState)
await SetAmp(carId, startAmp).ConfigureAwait(false);

var result = await SendCommandToTeslaApi<DtoVehicleCommandResult>(vin, ChargeStartRequest, HttpMethod.Post).ConfigureAwait(false);
if (result?.Response?.Result == true)
if (result?.Response?.Result == true && configurationWrapper.GetVehicleDataFromTesla())
{
var car = settings.Cars.First(c => c.Id == carId);
car.State = CarStateEnum.Charging;
car.ChargerActualCurrent = startAmp;
car.ChargerVoltage = settings.AverageHomeGridVoltage ?? 230;
}
}

Expand All @@ -128,7 +129,7 @@ public async Task StopCharging(int carId)
logger.LogTrace("{method}({carId})", nameof(StopCharging), carId);
var vin = GetVinByCarId(carId);
var result = await SendCommandToTeslaApi<DtoVehicleCommandResult>(vin, ChargeStopRequest, HttpMethod.Post).ConfigureAwait(false);
if (result?.Response?.Result == true)
if (result?.Response?.Result == true && configurationWrapper.GetVehicleDataFromTesla())
{
var car = settings.Cars.First(c => c.Id == carId);
car.State = CarStateEnum.Online;
Expand All @@ -149,7 +150,7 @@ public async Task SetAmp(int carId, int amps)
var commandData = $"{{\"charging_amps\":{amps}}}";
var result = await SendCommandToTeslaApi<DtoVehicleCommandResult>(vin, SetChargingAmpsRequest, HttpMethod.Post, commandData, amps).ConfigureAwait(false);
car.LastSetAmp = amps;
if (result?.Response?.Result == true)
if (result?.Response?.Result == true && configurationWrapper.GetVehicleDataFromTesla())
{
car.ChargerRequestedCurrent = amps;
car.ChargerActualCurrent = car.State == CarStateEnum.Charging ? amps : 0;
Expand Down Expand Up @@ -506,16 +507,17 @@ private async Task WakeUpCarIfNeeded(int carId, CarStateEnum? carState)
if (fleetApiRequest.RequestUrl == ChargeStartRequest.RequestUrl)
{
result = await bleService.StartCharging(vin);
if (result.Success)
if (result.Success && configurationWrapper.GetVehicleDataFromTesla())
{
car.State = CarStateEnum.Charging;
car.ChargerActualCurrent = car.ChargerRequestedCurrent;
car.ChargerVoltage = settings.AverageHomeGridVoltage ?? 230;
}
}
else if (fleetApiRequest.RequestUrl == ChargeStopRequest.RequestUrl)
{
result = await bleService.StopCharging(vin);
if (result.Success)
if (result.Success && configurationWrapper.GetVehicleDataFromTesla())
{
car.State = CarStateEnum.Online;
car.ChargerActualCurrent = 0;
Expand All @@ -524,7 +526,7 @@ private async Task WakeUpCarIfNeeded(int carId, CarStateEnum? carState)
else if (fleetApiRequest.RequestUrl == SetChargingAmpsRequest.RequestUrl)
{
result = await bleService.SetAmp(vin, amp!.Value);
if (result.Success)
if (result.Success && configurationWrapper.GetVehicleDataFromTesla())
{
car.ChargerRequestedCurrent = amp!.Value;
car.ChargerActualCurrent = car.State == CarStateEnum.Charging ? amp!.Value : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class BaseConfigurationBase
public int? MaxCombinedCurrent { get; set; }
public int? MaxInverterAcPower { get; set; }
public string? BleApiBaseUrl { get; set; }
public bool UseTeslaMateAsDataSource { get; set; }

public FrontendConfiguration? FrontendConfiguration { get; set; }

Expand Down
5 changes: 2 additions & 3 deletions TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ public bool UseFleetApi()

public bool GetVehicleDataFromTesla()
{
var environmentVariableName = "GetVehicleDataFromTesla";
var value = configuration.GetValue<bool>(environmentVariableName);
return value;
var value = GetBaseConfiguration().UseTeslaMateAsDataSource;
return !value;
}
public bool GetVehicleDataFromTeslaDebug()
{
Expand Down

0 comments on commit 9a38dc5

Please sign in to comment.