Skip to content

Commit

Permalink
Set suggested unit and use the provided const (#7)
Browse files Browse the repository at this point in the history
* Set suggested unit and use the provided const

* Increase precision and adjust keys
  • Loading branch information
tjorim authored Jun 8, 2024
1 parent 013fb86 commit e3c8301
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions custom_components/flitsmeister/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
from homeassistant.const import (
CURRENCY_EURO,
UnitOfEnergy,
UnitOfVolume,
UnitOfLength,
UnitOfSpeed,
UnitOfTime,
UnitOfVolume,
)
from homeassistant.core import HassJob, HomeAssistant
from homeassistant.helpers import event
Expand Down Expand Up @@ -49,7 +50,7 @@ class FMSensorEntityDescription(SensorEntityDescription):

SENSOR_TYPES: tuple[FMSensorEntityDescription, ...] = (
FMSensorEntityDescription(
key="km_driven",
key="distance_driven",
name="Distance driven",
native_unit_of_measurement=UnitOfLength.KILOMETERS,
suggested_display_precision=0,
Expand All @@ -67,10 +68,11 @@ class FMSensorEntityDescription(SensorEntityDescription):
icon="mdi:cash-check",
),
FMSensorEntityDescription(
key="sec_driven",
key="time_driven",
name="Time driven",
native_unit_of_measurement="s",
suggested_display_precision=0,
native_unit_of_measurement=UnitOfTime.SECONDS,
suggested_display_precision=2,
suggested_unit_of_measurement=UnitOfTime.HOURS,
state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: data[DATA_STATISTICS].sec_driven,
device_class=SensorDeviceClass.DURATION,
Expand All @@ -85,10 +87,11 @@ class FMSensorEntityDescription(SensorEntityDescription):
icon="mdi:car-multiple",
),
FMSensorEntityDescription(
key="top_100_sprint_ms",
key="top_100_sprint",
name="Top 100 sprint",
native_unit_of_measurement="ms",
suggested_display_precision=0,
native_unit_of_measurement=UnitOfTime.MILLISECONDS,
suggested_display_precision=3,
suggested_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda data: data[DATA_STATISTICS].top_100_sprint_ms,
icon="mdi:flag-checkered",
Expand Down

0 comments on commit e3c8301

Please sign in to comment.