Skip to content

Commit

Permalink
Merge pull request #217 from pkuehnel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pkuehnel authored Jul 30, 2022
2 parents bb2b8d6 + 3974e54 commit ec63136
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion TeslaSolarCharger/Server/Services/GridService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal NodePatternType DecideNotePatternType(string? jsonPattern, string? xmlP
pattern = xmlPattern;
}

var power = (int?)GetValueFromResult(pattern, result, nodePatternType, false);
var power = (double?)GetValueFromResult(pattern, result, nodePatternType, false);

return (int?)(power * (double)_configurationWrapper.CurrentInverterPowerCorrectionFactor());
}
Expand Down
15 changes: 12 additions & 3 deletions TeslaSolarCharger/Server/Services/PvValueService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ await _telegramService.SendMessage(
var inverterRequestUrl = _configurationWrapper.CurrentInverterPowerUrl();
var inverterRequestHeaders = _configurationWrapper.CurrentInverterPowerHeaders();

var areInverterAndGridRequestUrlSame = string.Equals(gridRequestUrl, inverterRequestUrl,
StringComparison.InvariantCultureIgnoreCase);
_logger.LogTrace("inverter and grid request urls same: {value}", areInverterAndGridRequestUrlSame);

var areInverterAndGridHeadersSame = gridRequestHeaders.Count == inverterRequestHeaders.Count
&& !gridRequestHeaders.Except(inverterRequestHeaders).Any();
_logger.LogTrace("inverter and grid headers same: {value}", areInverterAndGridHeadersSame);

if (inverterRequestUrl != null
&& (!string.Equals(gridRequestUrl, inverterRequestUrl, StringComparison.InvariantCultureIgnoreCase)
|| !(gridRequestHeaders.Count == inverterRequestHeaders.Count
&& !gridRequestHeaders.Except(inverterRequestHeaders).Any())))
&& (!areInverterAndGridRequestUrlSame
|| !areInverterAndGridHeadersSame))
{
_logger.LogTrace("Send another request for inverter power");
httpResponse = await GetHttpResponse(inverterRequestUrl, inverterRequestHeaders).ConfigureAwait(false);
}

Expand All @@ -79,6 +87,7 @@ await _telegramService.SendMessage(

private async Task<HttpResponseMessage> GetHttpResponse(string? gridRequestUrl, Dictionary<string, string> requestHeaders)
{
_logger.LogTrace("{method}({url}, {headers})", nameof(GetHttpResponse), gridRequestUrl, requestHeaders);
if (string.IsNullOrEmpty(gridRequestUrl))
{
throw new ArgumentNullException(nameof(gridRequestUrl));
Expand Down

0 comments on commit ec63136

Please sign in to comment.