Skip to content

Commit

Permalink
Merge pull request #58 from remuslazar/handle-0-soc
Browse files Browse the repository at this point in the history
Handle 0% SOC Gracefully
  • Loading branch information
remuslazar authored Oct 19, 2024
2 parents 6b06e8d + e15fb7a commit de0d879
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions custom_components/nissan_carwings/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def native_value(self) -> str | None:
if self.coordinator.data[DATA_BATTERY_STATUS_KEY] is None:
return None

# 0% SOC is not a valid value
if self.coordinator.data[DATA_BATTERY_STATUS_KEY].battery_percent == 0:
return None

return round(self.coordinator.data[DATA_BATTERY_STATUS_KEY].battery_percent)

@property
Expand Down Expand Up @@ -124,6 +128,9 @@ def native_value(self) -> float | None:
else:
ret = data.cruising_range_ac_off_km

if ret is None:
return None

if self.hass.config.units is US_CUSTOMARY_SYSTEM:
ret = DistanceConverter.convert(ret, UnitOfLength.KILOMETERS, UnitOfLength.MILES)

Expand Down

0 comments on commit de0d879

Please sign in to comment.