From 8c46380a24c4c85273be9e234c287e82ba1c098e Mon Sep 17 00:00:00 2001 From: Andreas Hedlund <25015949+moorgrove@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:03:08 +0100 Subject: [PATCH 1/3] Update sensor.py with new native units --- .../volkswagen_we_connect_id/sensor.py | 76 +++++++++---------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/custom_components/volkswagen_we_connect_id/sensor.py b/custom_components/volkswagen_we_connect_id/sensor.py index 5864ff9..a9c7f83 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,34 @@ class VolkswagenIdEntityDescription(SensorEntityDescription): name="Range", key="cruisingRangeElectric", icon="mdi:car-arrow-right", - native_unit_of_measurement=LENGTH_KILOMETERS, + 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", + 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, + native_unit_of_measurement=UnitOfLength.KILOMETERS, value=lambda data: data["measurements"]["odometerStatus"].odometer.value, ), VolkswagenIdEntityDescription( @@ -375,28 +374,28 @@ class VolkswagenIdEntityDescription(SensorEntityDescription): name="Gasoline Range", key="GasolineRange", icon="mdi:car-arrow-right", - native_unit_of_measurement=LENGTH_KILOMETERS, + 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", + native_unit_of_measurement=UnitOfLength.KILOMETERS, + value=lambda data: data["vehicleHealthInspection"][ + "maintenanceStatus" + ].oilServiceDue_km.value, ), VolkswagenIdEntityDescription( name="HV Battery Temperature Min", @@ -526,4 +525,3 @@ def native_value(self) -> StateType: return None return cast(StateType, state) - From 346b85e63b356b9717c85e7fbe79038515c4ff65 Mon Sep 17 00:00:00 2001 From: Andreas Hedlund <25015949+moorgrove@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:03:29 +0100 Subject: [PATCH 2/3] Update number.py with new native units --- custom_components/volkswagen_we_connect_id/number.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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: From 7e63fece33515554e94d30625f2a81879ebfacf0 Mon Sep 17 00:00:00 2001 From: Andreas Hedlund <25015949+moorgrove@users.noreply.github.com> Date: Fri, 8 Dec 2023 10:48:14 +0100 Subject: [PATCH 3/3] Update sensor.py with sensor device class distance Add device_class=SensorDeviceClass.DISTANCE --- custom_components/volkswagen_we_connect_id/sensor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/custom_components/volkswagen_we_connect_id/sensor.py b/custom_components/volkswagen_we_connect_id/sensor.py index a9c7f83..1719f45 100644 --- a/custom_components/volkswagen_we_connect_id/sensor.py +++ b/custom_components/volkswagen_we_connect_id/sensor.py @@ -153,6 +153,7 @@ class VolkswagenIdEntityDescription(SensorEntityDescription): name="Range", key="cruisingRangeElectric", icon="mdi:car-arrow-right", + device_class=SensorDeviceClass.DISTANCE, native_unit_of_measurement=UnitOfLength.KILOMETERS, value=lambda data: data["charging"][ "batteryStatus" @@ -171,6 +172,7 @@ class VolkswagenIdEntityDescription(SensorEntityDescription): 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" @@ -180,6 +182,7 @@ class VolkswagenIdEntityDescription(SensorEntityDescription): name="Odometer", key="odometer", icon="mdi:car-cruise-control", + device_class=SensorDeviceClass.DISTANCE, native_unit_of_measurement=UnitOfLength.KILOMETERS, value=lambda data: data["measurements"]["odometerStatus"].odometer.value, ), @@ -374,6 +377,7 @@ class VolkswagenIdEntityDescription(SensorEntityDescription): name="Gasoline Range", key="GasolineRange", icon="mdi:car-arrow-right", + device_class=SensorDeviceClass.DISTANCE, native_unit_of_measurement=UnitOfLength.KILOMETERS, value=lambda data: data["measurements"][ "rangeStatus" @@ -392,6 +396,7 @@ class VolkswagenIdEntityDescription(SensorEntityDescription): 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"