diff --git a/custom_components/volkswagen_we_connect_id/__init__.py b/custom_components/volkswagen_we_connect_id/__init__.py index 4d56869..e67a523 100644 --- a/custom_components/volkswagen_we_connect_id/__init__.py +++ b/custom_components/volkswagen_we_connect_id/__init__.py @@ -3,11 +3,9 @@ from datetime import timedelta import logging -from tarfile import SUPPORTED_TYPES from weconnect import weconnect from weconnect.elements.control_operation import ControlOperation -from weconnect.elements.range_status import RangeStatus from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform @@ -35,21 +33,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: username=entry.data["username"], password=entry.data["password"], updateAfterLogin=False, - updatePictures=False, loginOnInit=False, ) - def we_connect_update() -> None: - _we_connect.update( - updatePictures=False - ) - await hass.async_add_executor_job(_we_connect.login) - await hass.async_add_executor_job(we_connect_update) + await hass.async_add_executor_job(_we_connect.update) async def async_update_data(): """Fetch data from Volkswagen API.""" - await hass.async_add_executor_job(we_connect_update) + await hass.async_add_executor_job(_we_connect.update) vehicles = [] diff --git a/custom_components/volkswagen_we_connect_id/binary_sensor.py b/custom_components/volkswagen_we_connect_id/binary_sensor.py index 3429ce4..9b6ef10 100644 --- a/custom_components/volkswagen_we_connect_id/binary_sensor.py +++ b/custom_components/volkswagen_we_connect_id/binary_sensor.py @@ -161,7 +161,7 @@ def __init__( self.entity_description = sensor self._coordinator = coordinator - self._attr_name = f"Volkswagen ID {self.data.nickname} {sensor.name}" + self._attr_name = f"{self.data.nickname} {sensor.name}" self._attr_unique_id = f"{self.data.vin}-{sensor.key}" @property diff --git a/custom_components/volkswagen_we_connect_id/button.py b/custom_components/volkswagen_we_connect_id/button.py index 6ef44e9..7155a83 100644 --- a/custom_components/volkswagen_we_connect_id/button.py +++ b/custom_components/volkswagen_we_connect_id/button.py @@ -28,7 +28,7 @@ class VolkswagenIDStartClimateButton(ButtonEntity): def __init__(self, vehicle, we_connect) -> None: """Initialize VolkswagenID vehicle sensor.""" - self._attr_name = f"Volkswagen ID {vehicle.nickname} Start Climate" + self._attr_name = f"{vehicle.nickname} Start Climate" self._attr_unique_id = f"{vehicle.vin}-start_climate" self._we_connect = we_connect self._vehicle = vehicle @@ -43,7 +43,7 @@ class VolkswagenIDToggleACChargeSpeed(ButtonEntity): def __init__(self, vehicle: Vehicle, we_connect: weconnect.WeConnect) -> None: """Initialize VolkswagenID vehicle sensor.""" - self._attr_name = f"Volkswagen ID {vehicle.nickname} Toggle AC Charge Speed" + self._attr_name = f"{vehicle.nickname} Toggle AC Charge Speed" self._attr_unique_id = f"{vehicle.vin}-toggle_ac_charge_speed" self._we_connect = we_connect self._vehicle = vehicle diff --git a/custom_components/volkswagen_we_connect_id/manifest.json b/custom_components/volkswagen_we_connect_id/manifest.json index b472360..88a3ff0 100644 --- a/custom_components/volkswagen_we_connect_id/manifest.json +++ b/custom_components/volkswagen_we_connect_id/manifest.json @@ -3,12 +3,12 @@ "name": "Volkswagen We Connect ID", "config_flow": true, "documentation": "https://github.com/mitch-dc/volkswagen_we_connect_id", - "requirements": ["weconnect==0.39", "ascii_magic==1.6"], + "requirements": ["weconnect==0.40", "ascii_magic==1.6"], "ssdp": [], "zeroconf": [], "homekit": {}, "dependencies": [], "codeowners": ["@mitch-dc"], "iot_class": "cloud_polling", - "version": "0.3.2" + "version": "0.4" } diff --git a/custom_components/volkswagen_we_connect_id/number.py b/custom_components/volkswagen_we_connect_id/number.py index 4fb6283..9860f08 100644 --- a/custom_components/volkswagen_we_connect_id/number.py +++ b/custom_components/volkswagen_we_connect_id/number.py @@ -49,7 +49,7 @@ def __init__( super().__init__(we_connect, coordinator, index) self._coordinator = coordinator - self._attr_name = f"Volkswagen ID {self.data.nickname} Target State Of Charge" + self._attr_name = f"{self.data.nickname} Target State Of Charge" self._attr_unique_id = f"{self.data.vin}-target_state_of_charge" self._we_connect = we_connect self._attr_min_value = 10 @@ -92,9 +92,7 @@ def __init__( super().__init__(we_connect, coordinator, index) self._coordinator = coordinator - self._attr_name = ( - f"Volkswagen ID {self.data.nickname} Target Climate Temperature" - ) + self._attr_name = f"{self.data.nickname} Target Climate Temperature" self._attr_unique_id = f"{self.data.vin}-target_climate_temperature" self._we_connect = we_connect self._attr_min_value = 10 diff --git a/custom_components/volkswagen_we_connect_id/sensor.py b/custom_components/volkswagen_we_connect_id/sensor.py index 86ea26d..c5e3a95 100644 --- a/custom_components/volkswagen_we_connect_id/sensor.py +++ b/custom_components/volkswagen_we_connect_id/sensor.py @@ -13,6 +13,7 @@ DEVICE_CLASS_POWER, DEVICE_CLASS_TEMPERATURE, LENGTH_KILOMETERS, + LENGTH_MILES, PERCENTAGE, POWER_KILO_WATT, SPEED_KILOMETERS_PER_HOUR, @@ -141,13 +142,21 @@ class VolkswagenIdEntityDescription(SensorEntityDescription): value=lambda data: data["charging"]["batteryStatus"].currentSOC_pct.value, ), VolkswagenIdEntityDescription( - name="Range", + name="Range in Kilometers", key="cruisingRangeElectric_km", native_unit_of_measurement=LENGTH_KILOMETERS, value=lambda data: data["charging"][ "batteryStatus" ].cruisingRangeElectric_km.value, ), + VolkswagenIdEntityDescription( + name="Range in Miles", + key="cruisingRangeElectric_mi", + native_unit_of_measurement=LENGTH_MILES, + value=lambda data: data["charging"][ + "batteryStatus" + ].cruisingRangeElectric_km.value, + ), VolkswagenIdEntityDescription( name="Battery Power Level", key="batteryPowerLevel", @@ -193,7 +202,7 @@ def __init__( self.entity_description = sensor self._coordinator = coordinator - self._attr_name = f"Volkswagen ID {self.data.nickname} {sensor.name}" + self._attr_name = f"{self.data.nickname} {sensor.name}" self._attr_unique_id = f"{self.data.vin}-{sensor.key}" self._attr_native_unit_of_measurement = sensor.native_unit_of_measurement @@ -202,4 +211,8 @@ def native_value(self) -> StateType: """Return the state.""" state = get_object_value(self.entity_description.value(self.data.domains)) + + if self.entity_description.key == "cruisingRangeElectric_mi": + state = int(float(state) * 0.62137) + return cast(StateType, state)