diff --git a/custom_components/volkswagen_we_connect_id/number.py b/custom_components/volkswagen_we_connect_id/number.py index dccba79..24991ca 100644 --- a/custom_components/volkswagen_we_connect_id/number.py +++ b/custom_components/volkswagen_we_connect_id/number.py @@ -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): @@ -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: diff --git a/custom_components/volkswagen_we_connect_id/sensor.py b/custom_components/volkswagen_we_connect_id/sensor.py index 5864ff9..1719f45 100644 --- a/custom_components/volkswagen_we_connect_id/sensor.py +++ b/custom_components/volkswagen_we_connect_id/sensor.py @@ -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, ) @@ -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, @@ -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, @@ -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, ), @@ -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( @@ -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", @@ -526,4 +530,3 @@ def native_value(self) -> StateType: return None return cast(StateType, state) -