From 28255f6e2d0d07dff36fa3056a46056e4319149b Mon Sep 17 00:00:00 2001 From: Mitch Date: Fri, 25 Feb 2022 08:58:59 +0100 Subject: [PATCH] * Upped the polling time * Changed ID car check * Bumped weconnect to 0.37 * Added new sensors * Fixed bug where changing target temp started climate control --- .../volkswagen_we_connect_id/__init__.py | 12 ++++++------ .../volkswagen_we_connect_id/manifest.json | 2 +- .../volkswagen_we_connect_id/number.py | 14 ++++++-------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/custom_components/volkswagen_we_connect_id/__init__.py b/custom_components/volkswagen_we_connect_id/__init__.py index 33681cf..b45c183 100644 --- a/custom_components/volkswagen_we_connect_id/__init__.py +++ b/custom_components/volkswagen_we_connect_id/__init__.py @@ -3,6 +3,7 @@ from datetime import timedelta import logging +from tarfile import SUPPORTED_TYPES from weconnect import weconnect from weconnect.elements.control_operation import ControlOperation @@ -23,6 +24,8 @@ _LOGGER = logging.getLogger(__name__) +SUPPORTED_VEHICLES = ["ID.3", "ID.4", "ID.5"] + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Volkswagen We Connect ID from a config entry.""" @@ -45,10 +48,7 @@ async def async_update_data(): vehicles = [] for vin, vehicle in _we_connect.vehicles.items(): - car_type = get_object_value( - vehicle.domains["fuelStatus"]["rangeStatus"].carType - ) - if car_type == RangeStatus.CarType.ELECTRIC.value: + if vehicle.model.value in SUPPORTED_VEHICLES: vehicles.append(vehicle) hass.data[DOMAIN][entry.entry_id + "_vehicles"] = vehicles @@ -59,7 +59,7 @@ async def async_update_data(): _LOGGER, name=DOMAIN, update_method=async_update_data, - update_interval=timedelta(seconds=10), + update_interval=timedelta(seconds=30), ) hass.data.setdefault(DOMAIN, {}) @@ -264,7 +264,7 @@ def set_climatisation( try: vehicle.domains["climatisation"][ "climatisationSettings" - ].targetTemperature_C.value = target_temperature + ].targetTemperature_C.value = float(target_temperature) _LOGGER.info("Sended target temperature call to the car") except Exception as exc: _LOGGER.error("Failed to send request to car - %s", exc) diff --git a/custom_components/volkswagen_we_connect_id/manifest.json b/custom_components/volkswagen_we_connect_id/manifest.json index 34bb498..da1924c 100644 --- a/custom_components/volkswagen_we_connect_id/manifest.json +++ b/custom_components/volkswagen_we_connect_id/manifest.json @@ -3,7 +3,7 @@ "name": "Volkswagen We Connect ID", "config_flow": true, "documentation": "https://github.com/mitch-dc/volkswagen_we_connect_id", - "requirements": ["weconnect==0.37.0.dev4", "ascii_magic==1.6"], + "requirements": ["weconnect==0.37.0", "ascii_magic==1.6"], "ssdp": [], "zeroconf": [], "homekit": {}, diff --git a/custom_components/volkswagen_we_connect_id/number.py b/custom_components/volkswagen_we_connect_id/number.py index 92a2a2f..4fb6283 100644 --- a/custom_components/volkswagen_we_connect_id/number.py +++ b/custom_components/volkswagen_we_connect_id/number.py @@ -104,18 +104,16 @@ def __init__( @property def value(self) -> float: """Return the current value.""" + targetTemp = self.data.domains["climatisation"][ + "climatisationSettings" + ].targetTemperature_C.value - return float( - get_object_value( - self.data.domains["climatisation"][ - "climatisationSettings" - ].targetTemperature_C.value, - ) - ) + return float(targetTemp) async def async_set_value(self, value: float) -> None: """Update the current value.""" if value > 10: + self._attr_value = value await self.hass.async_add_executor_job( - set_climatisation, self.data.vin.value, self._we_connect, "start", value + set_climatisation, self.data.vin.value, self._we_connect, "none", value )