Date: Wed, 2 Nov 2022 00:01:43 +0100
Subject: [PATCH 5/5] feat(PvValueService): allow dynamic inversion of home
battery power
---
.../Client/Pages/BaseConfiguration.razor | 8 ++++++++
.../Server/Services/PvValueService.cs | 15 +++++++++++++++
.../Shared/Contracts/IConfigurationWrapper.cs | 2 ++
.../BaseConfiguration/BaseConfigurationBase.cs | 2 ++
.../Shared/Wrappers/ConfigurationWrapper.cs | 10 ++++++++++
5 files changed, 37 insertions(+)
diff --git a/TeslaSolarCharger/Client/Pages/BaseConfiguration.razor b/TeslaSolarCharger/Client/Pages/BaseConfiguration.razor
index d3df87cb0..448ce670c 100644
--- a/TeslaSolarCharger/Client/Pages/BaseConfiguration.razor
+++ b/TeslaSolarCharger/Client/Pages/BaseConfiguration.razor
@@ -275,6 +275,14 @@ else
+
+
diff --git a/TeslaSolarCharger/Server/Services/PvValueService.cs b/TeslaSolarCharger/Server/Services/PvValueService.cs
index 8cfcdce52..a86af2b92 100644
--- a/TeslaSolarCharger/Server/Services/PvValueService.cs
+++ b/TeslaSolarCharger/Server/Services/PvValueService.cs
@@ -126,6 +126,21 @@ public async Task UpdatePvValues()
var homeBatteryPowerXmlPattern = _configurationWrapper.HomeBatteryPowerXmlPattern();
var homeBatteryPowerCorrectionFactor = (double)_configurationWrapper.HomeBatteryPowerCorrectionFactor();
var homeBatteryPower = await GetValueByHttpResponse(homeBatteryPowerHttpResponse, homeBatteryPowerJsonPattern, homeBatteryPowerXmlPattern, homeBatteryPowerCorrectionFactor).ConfigureAwait(false);
+ var homeBatteryPowerInversionRequestUrl = _configurationWrapper.HomeBatteryPowerInversionUrl();
+ if (!string.IsNullOrEmpty(homeBatteryPowerInversionRequestUrl))
+ {
+ var homeBatteryPowerInversionHeaders = _configurationWrapper.HomeBatteryPowerInversionHeaders();
+ //ToDo: implement setting Headers in frontend
+ var homeBatteryPowerInversionRequest = GenerateHttpRequestMessage(homeBatteryPowerInversionRequestUrl, homeBatteryPowerInversionHeaders);
+ var homeBatteryPowerInversionHttpResponse = await GetHttpResponse(homeBatteryPowerInversionRequest).ConfigureAwait(false);
+ var shouldInvertHomeBatteryPowerInt = await GetValueByHttpResponse(homeBatteryPowerInversionHttpResponse, null, null, 1).ConfigureAwait(false);
+ var shouldInvertHomeBatteryPower = Convert.ToBoolean(shouldInvertHomeBatteryPowerInt);
+ if (shouldInvertHomeBatteryPower)
+ {
+ homeBatteryPower = -homeBatteryPower;
+ }
+ }
+
_settings.HomeBatteryPower = homeBatteryPower;
}
}
diff --git a/TeslaSolarCharger/Shared/Contracts/IConfigurationWrapper.cs b/TeslaSolarCharger/Shared/Contracts/IConfigurationWrapper.cs
index 746c1a3cd..4bbccc464 100644
--- a/TeslaSolarCharger/Shared/Contracts/IConfigurationWrapper.cs
+++ b/TeslaSolarCharger/Shared/Contracts/IConfigurationWrapper.cs
@@ -71,4 +71,6 @@ public interface IConfigurationWrapper
Task TryAutoFillUrls();
string? SolarMqttUsername();
string? SolarMqttPassword();
+ string? HomeBatteryPowerInversionUrl();
+ Dictionary HomeBatteryPowerInversionHeaders();
}
diff --git a/TeslaSolarCharger/Shared/Dtos/BaseConfiguration/BaseConfigurationBase.cs b/TeslaSolarCharger/Shared/Dtos/BaseConfiguration/BaseConfigurationBase.cs
index 888d5db7c..be90fecbe 100644
--- a/TeslaSolarCharger/Shared/Dtos/BaseConfiguration/BaseConfigurationBase.cs
+++ b/TeslaSolarCharger/Shared/Dtos/BaseConfiguration/BaseConfigurationBase.cs
@@ -17,7 +17,9 @@ public class BaseConfigurationBase
public Dictionary HomeBatterySocHeaders { get; set; } = new();
public string? HomeBatteryPowerMqttTopic { get; set; }
public string? HomeBatteryPowerUrl { get; set; }
+ public string? HomeBatteryPowerInversionUrl { get; set; }
public Dictionary HomeBatteryPowerHeaders { get; set; } = new();
+ public Dictionary HomeBatteryPowerInversionHeaders { get; set; } = new();
public bool IsModbusGridUrl { get; set; }
public bool IsModbusHomeBatterySocUrl { get; set; }
public bool IsModbusHomeBatteryPowerUrl { get; set; }
diff --git a/TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs b/TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs
index 1791c8d32..53db19bd2 100644
--- a/TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs
+++ b/TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs
@@ -189,11 +189,21 @@ public Dictionary HomeBatterySocHeaders()
return GetBaseConfiguration().HomeBatteryPowerUrl;
}
+ public string? HomeBatteryPowerInversionUrl()
+ {
+ return GetBaseConfiguration().HomeBatteryPowerInversionUrl;
+ }
+
public Dictionary HomeBatteryPowerHeaders()
{
return GetBaseConfiguration().HomeBatteryPowerHeaders;
}
+ public Dictionary HomeBatteryPowerInversionHeaders()
+ {
+ return GetBaseConfiguration().HomeBatteryPowerInversionHeaders;
+ }
+
public string? CurrentPowerToGridJsonPattern()
{
return GetBaseConfiguration().CurrentPowerToGridJsonPattern;