Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane Senart committed Dec 9, 2024
2 parents d7150f8 + 15d3b65 commit fa523fb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.3.11] - 2024-12-09

### Fixed
[#72](https://github.com/ssenart/home-assistant-gazpar/issues/72): Fatal error if GrDF returns no start index/end index/volume/energy data in the record.

## [1.3.10] - 2024-10-09

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion custom_components/gazpar/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"requirements": [
"pygazpar>=1.2.4"
],
"version": "1.3.10"
"version": "1.3.11"
}
25 changes: 21 additions & 4 deletions custom_components/gazpar/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,31 @@ def toState(pygazparData: dict[str, list[dict[str, Any]]]) -> Union[float, None]

# For low consumption, we also use the energy column in addition to the volume index columns
# and compute more accurately the consumed energy.
while (currentIndex < len(dailyData)) and (float(dailyData[currentIndex][PropertyName.START_INDEX.value]) == float(dailyData[currentIndex][PropertyName.END_INDEX.value])):
cumulativeEnergy += float(dailyData[currentIndex][PropertyName.ENERGY.value])
startIndex = dailyData[currentIndex][PropertyName.START_INDEX.value]
endIndex = dailyData[currentIndex][PropertyName.END_INDEX.value]

while (startIndex is not None) and (endIndex is not None) and (currentIndex < len(dailyData)) and (float(startIndex) == float(endIndex)):
energy = dailyData[currentIndex][PropertyName.ENERGY.value]
if energy is not None:
cumulativeEnergy += float(energy)
currentIndex += 1
startIndex = dailyData[currentIndex][PropertyName.START_INDEX.value]
endIndex = dailyData[currentIndex][PropertyName.END_INDEX.value]

currentIndex = min(currentIndex, len(dailyData) - 1)

volumeEndIndex = float(dailyData[currentIndex][PropertyName.END_INDEX.value])
converterFactor = float(dailyData[currentIndex][PropertyName.CONVERTER_FACTOR.value])
endIndex = dailyData[currentIndex][PropertyName.END_INDEX.value]
converterFactorStr = dailyData[currentIndex][PropertyName.CONVERTER_FACTOR.value]

if endIndex is not None:
volumeEndIndex = float(endIndex)
else:
raise ValueError("End index is missing in the daily data.")

if converterFactorStr is not None:
converterFactor = float(converterFactorStr)
else:
raise ValueError("Converter factor is missing in the daily data.")

res = volumeEndIndex * converterFactor + cumulativeEnergy

Expand Down

0 comments on commit fa523fb

Please sign in to comment.