Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deprecated native unit of measurement #232

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions custom_components/volkswagen_we_connect_id/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
)
from .const import DOMAIN

from homeassistant.const import TEMP_CELSIUS
from homeassistant.const import PERCENTAGE
from homeassistant.const import (
PERCENTAGE,
UnitOfTemperature,
)


async def async_setup_entry(hass, config_entry, async_add_entities):
Expand Down Expand Up @@ -103,7 +105,7 @@ def __init__(
self._attr_native_min_value = 10
self._attr_native_max_value = 30
self._attr_native_step = 0.5
self._attr_native_unit_of_measurement = TEMP_CELSIUS
self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS

@property
def native_value(self) -> float | None:
Expand Down
81 changes: 42 additions & 39 deletions custom_components/volkswagen_we_connect_id/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
SensorDeviceClass,
)
from homeassistant.const import (
LENGTH_KILOMETERS,
PERCENTAGE,
SPEED_KILOMETERS_PER_HOUR,
TIME_DAYS,
TIME_MINUTES,
UnitOfPower,
UnitOfTemperature,
UnitOfEnergy,
UnitOfLength,
UnitOfSpeed,
UnitOfTime,
)


Expand Down Expand Up @@ -60,7 +59,7 @@ class VolkswagenIdEntityDescription(SensorEntityDescription):
key="remainingClimatisationTime_min",
name="Remaining Climatisation Time",
icon="mdi:fan-clock",
native_unit_of_measurement=TIME_MINUTES,
native_unit_of_measurement=UnitOfTime.MINUTES,
value=lambda data: data["climatisation"][
"climatisationStatus"
].remainingClimatisationTime_min.value,
Expand Down Expand Up @@ -91,7 +90,7 @@ class VolkswagenIdEntityDescription(SensorEntityDescription):
key="remainingChargingTimeToComplete_min",
name="Remaining Charging Time",
icon="mdi:battery-clock",
native_unit_of_measurement=TIME_MINUTES,
native_unit_of_measurement=UnitOfTime.MINUTES,
value=lambda data: data["charging"][
"chargingStatus"
].remainingChargingTimeToComplete_min.value,
Expand All @@ -112,7 +111,7 @@ class VolkswagenIdEntityDescription(SensorEntityDescription):
VolkswagenIdEntityDescription(
key="chargeRate_kmph",
name="Charge Rate",
native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
device_class=SensorDeviceClass.SPEED,
value=lambda data: data["charging"]["chargingStatus"].chargeRate_kmph.value,
),
Expand Down Expand Up @@ -154,34 +153,37 @@ class VolkswagenIdEntityDescription(SensorEntityDescription):
name="Range",
key="cruisingRangeElectric",
icon="mdi:car-arrow-right",
native_unit_of_measurement=LENGTH_KILOMETERS,
device_class=SensorDeviceClass.DISTANCE,
native_unit_of_measurement=UnitOfLength.KILOMETERS,
value=lambda data: data["charging"][
"batteryStatus"
].cruisingRangeElectric_km.value,
),
VolkswagenIdEntityDescription(
name="Health Inspection",
key="inspectionDue",
icon="mdi:wrench-clock-outline",
native_unit_of_measurement=TIME_DAYS,
value=lambda data: data["vehicleHealthInspection"][
"maintenanceStatus"
].inspectionDue_days.value,
name="Health Inspection",
key="inspectionDue",
icon="mdi:wrench-clock-outline",
native_unit_of_measurement=UnitOfTime.DAYS,
value=lambda data: data["vehicleHealthInspection"][
"maintenanceStatus"
].inspectionDue_days.value,
),
VolkswagenIdEntityDescription(
name="Health Inspection km",
key="inspectionDuekm",
icon="mdi:wrench-clock-outline",
native_unit_of_measurement=LENGTH_KILOMETERS,
value=lambda data: data["vehicleHealthInspection"][
"maintenanceStatus"
].inspectionDue_km.value,
name="Health Inspection km",
key="inspectionDuekm",
icon="mdi:wrench-clock-outline",
device_class=SensorDeviceClass.DISTANCE,
native_unit_of_measurement=UnitOfLength.KILOMETERS,
value=lambda data: data["vehicleHealthInspection"][
"maintenanceStatus"
].inspectionDue_km.value,
),
VolkswagenIdEntityDescription(
name="Odometer",
key="odometer",
icon="mdi:car-cruise-control",
native_unit_of_measurement=LENGTH_KILOMETERS,
device_class=SensorDeviceClass.DISTANCE,
native_unit_of_measurement=UnitOfLength.KILOMETERS,
value=lambda data: data["measurements"]["odometerStatus"].odometer.value,
),
VolkswagenIdEntityDescription(
Expand Down Expand Up @@ -375,28 +377,30 @@ class VolkswagenIdEntityDescription(SensorEntityDescription):
name="Gasoline Range",
key="GasolineRange",
icon="mdi:car-arrow-right",
native_unit_of_measurement=LENGTH_KILOMETERS,
device_class=SensorDeviceClass.DISTANCE,
native_unit_of_measurement=UnitOfLength.KILOMETERS,
value=lambda data: data["measurements"][
"rangeStatus"
].gasolineRange.value,
),
VolkswagenIdEntityDescription(
name="Oil Inspection days",
key="oilInspectionDue",
icon="mdi:wrench-clock-outline",
native_unit_of_measurement=TIME_DAYS,
value=lambda data: data["vehicleHealthInspection"][
"maintenanceStatus"
].oilServiceDue_days.value,
name="Oil Inspection days",
key="oilInspectionDue",
icon="mdi:wrench-clock-outline",
native_unit_of_measurement=UnitOfTime.DAYS,
value=lambda data: data["vehicleHealthInspection"][
"maintenanceStatus"
].oilServiceDue_days.value,
),
VolkswagenIdEntityDescription(
name="Oil Inspection km",
key="oilInspectionDuekm",
icon="mdi:wrench-clock-outline",
native_unit_of_measurement=LENGTH_KILOMETERS,
value=lambda data: data["vehicleHealthInspection"][
"maintenanceStatus"
].oilServiceDue_km.value,
name="Oil Inspection km",
key="oilInspectionDuekm",
icon="mdi:wrench-clock-outline",
device_class=SensorDeviceClass.DISTANCE,
native_unit_of_measurement=UnitOfLength.KILOMETERS,
value=lambda data: data["vehicleHealthInspection"][
"maintenanceStatus"
].oilServiceDue_km.value,
),
VolkswagenIdEntityDescription(
name="HV Battery Temperature Min",
Expand Down Expand Up @@ -526,4 +530,3 @@ def native_value(self) -> StateType:
return None

return cast(StateType, state)