Skip to content

Commit

Permalink
* Bumped weconnect to 0.40
Browse files Browse the repository at this point in the history
* Reduced the name of the entities & buttons
* Added range in milaes
  • Loading branch information
mitch-dc committed May 17, 2022
1 parent 2c4c31d commit 51b4dd5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
12 changes: 2 additions & 10 deletions custom_components/volkswagen_we_connect_id/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions custom_components/volkswagen_we_connect_id/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions custom_components/volkswagen_we_connect_id/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
6 changes: 2 additions & 4 deletions custom_components/volkswagen_we_connect_id/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions custom_components/volkswagen_we_connect_id/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
LENGTH_KILOMETERS,
LENGTH_MILES,
PERCENTAGE,
POWER_KILO_WATT,
SPEED_KILOMETERS_PER_HOUR,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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

Expand All @@ -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)

1 comment on commit 51b4dd5

@odelma
Copy link

@odelma odelma commented on 51b4dd5 Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @mitch-dc. Why was updatePictures=False (51b4dd5#diff-31afb15cb0fb003e221a5d2bc6f981b22949d1fdfa6dc037b064b767802c7a0dL38) removed right after it was merged in the previous commit? Now I need to do this manually after updating to prevent HA crashing (due to going out of memory in about 1h)?

Please sign in to comment.