Skip to content

Commit

Permalink
update average_speed to be a SPEED not DISTANCE
Browse files Browse the repository at this point in the history
  • Loading branch information
David Carrel committed Jan 9, 2024
1 parent cba3929 commit bf894f4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions custom_components/polestar_api/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from homeassistant.helpers import entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from homeassistant.util.unit_conversion import DistanceConverter
from homeassistant.util.unit_conversion import DistanceConverter, SpeedConverter

from . import DOMAIN as POLESTAR_API_DOMAIN
from .entity import PolestarEntity
Expand Down Expand Up @@ -130,9 +130,9 @@ class PolestarSensorDescription(
query="getOdometerData",
field_name="averageSpeedKmPerHour",
native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
round_digits=None,
round_digits=2,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.DISTANCE,
device_class=SensorDeviceClass.SPEED,
max_value=150,
dict_data=None
),
Expand Down Expand Up @@ -519,6 +519,11 @@ def state(self) -> StateType:
self._sensor_data, self.entity_description.native_unit_of_measurement, self._sensor_option_unit_of_measurement
)
self._attr_native_unit_of_measurement = self._sensor_option_unit_of_measurement
elif self._sensor_option_unit_of_measurement in (UnitOfSpeed.MILES_PER_HOUR, UnitOfSpeed.KILOMETERS_PER_HOUR):
self._attr_native_value = SpeedConverter.convert(
self._sensor_data, self.entity_description.native_unit_of_measurement, self._sensor_option_unit_of_measurement
)
self._attr_native_unit_of_measurement = self._sensor_option_unit_of_measurement
if self.entity_description.key in ("estimate_range", "estimate_full_charge_range"):
if self._sensor_option_unit_of_measurement == UnitOfLength.MILES:
self.entity_description.max_value = 410
Expand Down

0 comments on commit bf894f4

Please sign in to comment.