Skip to content

Commit

Permalink
#134 current watt and amps if we get None, we should mark them as 0
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyuentuen committed Apr 27, 2024
1 parent b4807a2 commit f650ea4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions custom_components/polestar_api/polestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,8 @@ def get_value(self, query: str, field_name: str, skip_cache: bool = False):
"""Get the latest value from the Polestar API."""
data = self.polestarApi.get_cache_data(query, field_name, skip_cache)
if data is None:
# if amp and voltage can be null, so we will return 0
if field_name in ('chargingCurrentAmps', 'chargingPowerWatts'):
return 0
return
return data
2 changes: 2 additions & 0 deletions custom_components/polestar_api/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ async def async_update(self) -> None:
if value is not None:
self._attr_native_value = value
self._sensor_data = value


except Exception:
_LOGGER.warning("Failed to update sensor async update")
self._device.polestarApi.next_update = datetime.now() + timedelta(seconds=60)
Expand Down

0 comments on commit f650ea4

Please sign in to comment.