Skip to content

Commit

Permalink
Merge pull request #584 from robinostlund/v4.5.6
Browse files Browse the repository at this point in the history
v4.5.6
  • Loading branch information
robinostlund authored Mar 3, 2024
2 parents e7369e3 + 3cb0595 commit b1f2b6a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 149 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

## Description

Welcome to Volkswagen We Connect custom component designed for [Home Assistant](https://www.home-assistant.io) with the capability to interact with the Volkswagen We Connect service (your car).
Welcome to Volkswagen We Connect custom component designed for [Home Assistant](https://www.home-assistant.io) with the capability to interact with the Volkswagen Connect service (your car).

This custom component supports the "**non-ID" Volkswagen We Connect cars** such as the Passat, Golf, e-Golf, Tiguan etc. It requires you to have an active and working VW online subscription connected to your car. For the new electric vehicles such as the ID series this component does not work. The new ID platform uses another backend system.
This custom component supports the **Volkswagen Connect cars** such as the Passat, Golf, e-Golf, Tiguan, ID etc. It requires you to have an active and working VW online subscription connected to your car. The new electric vehicles such as the ID series are supported as well.

Most of the functionality found the "We Connect app" should be available via this integration, this includes options such as auxiliary heater control.
Most of the functionality found the "Volkswagen Connect app" should be available via this integration, this includes options such as auxiliary heater control.

Note: Some features included in Volkswagen We Connect 2019 and newer are not fully tested. This custom component should work with any models such as Golf/Passat 8.5/Tiguan etc. But please bear with me and report any fault or error as an issue.
Note: Some features included in Volkswagen Connect 2023 and newer are not fully tested. This custom component should work with any models such as Golf/Passat 8.5/Tiguan etc. But please bear with me and report any fault or error as an issue.

Please note that there has only been reports of success with this component for cars sold (and based) in the EU. Please feel free to contribue to make this component work in the US as well, we do not have access to any We Connect accounts to verify at this stage.
Please note that there has only been reports of success with this component for cars sold (and based) in the EU. Please feel free to contribue to make this component work in the US as well, we do not have access to any Volkswagen Connect accounts to verify at this stage.

## Having issues with this custom component?
Please, before posting an issue make sure that VW´s WeConnect service works for you via a normal web browser. Not only the login part but also make sure that the VW WeConnect service interacts with the car proper, including updating of all sensors and location. If there are problems with the VW WeConnect service this component will not work either. This custom component is only as good as the VW WeConnect service.
Please, before posting an issue make sure that VW´s Connect service works for you via a normal web browser. Not only the login part but also make sure that the VW Connect service interacts with the car proper, including updating of all sensors and location. If there are problems with the VW Connect service this component will not work either. This custom component is only as good as the VW Connect service.

## Installation

Expand All @@ -39,7 +39,7 @@ Please, before posting an issue make sure that VW´s WeConnect service works for
Do you you have [HACS](https://community.home-assistant.io/t/custom-component-hacs) installed? Just search for Volkswagen We Connect and install it direct from HACS. HACS will keep track of updates and you can easly upgrade this component to latest version.

### Install manually
Make sure you have an account on Volkswagen We Connect.
Make sure you have an account on Volkswagen Connect.

Clone or copy the repository and copy the folder 'homeassistant-volkswagencarnet/custom_component/volkswagencarnet' into '<config dir>/custom_components'

Expand All @@ -48,7 +48,7 @@ Note that only the packaged releases (zip file) have the dependencies configured

## Configuration
* Restart Home Assistant
* Add and configure the component via the UI: Configuration > Integrations > search for "Volkswagen We Connect" and follow the wizard to configure (use your We Connect credentials)
* Add and configure the component via the UI: Configuration > Integrations > search for "Volkswagen We Connect" and follow the wizard to configure (use your Volkswagen Connect credentials)
* All available features of your car should be added automatically after you have selected the VIN

### Configuration flow settings
Expand Down
21 changes: 1 addition & 20 deletions custom_components/volkswagencarnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
CONF_USERNAME,
EVENT_HOMEASSISTANT_STOP,
STATE_UNKNOWN,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant, Event, callback, State
from homeassistant.helpers.aiohttp_client import async_get_clientsession
Expand All @@ -25,7 +24,6 @@
from volkswagencarnet.vw_connection import Connection
from volkswagencarnet.vw_dashboard import (
Instrument,
Climate,
BinarySensor,
Sensor,
Switch,
Expand Down Expand Up @@ -292,20 +290,6 @@ def async_write_ha_state(self) -> None:
# Get the previous state from the state machine if found
prev: Optional[State] = self.hass.states.get(self.entity_id)

# This is not the best place to handle this, but... :shrug:..
if self.attribute == "requests_remaining" and self.state in [-1, STATE_UNAVAILABLE, STATE_UNKNOWN]:
restored = prev or self.restored_state
if restored is not None:
try:
value = int(restored.state)
_LOGGER.debug(f"Restoring requests remaining to '{restored.state}'")
self.vehicle.requests_remaining = value
except ValueError:
pass
else:
_LOGGER.debug(f"Not changing requests remaining to '{self.state}'")
return

# need to persist state if:
# - there is no previous state
# - there is no information about when the last backend update was done
Expand All @@ -315,10 +299,7 @@ def async_write_ha_state(self) -> None:
prev is None
or str(prev.attributes.get("last_updated", None)) != str(backend_refresh_time)
or str(self.state or STATE_UNKNOWN) != str(prev.state)
or self.component == "climate"
):
if self.component == "climate":
self._update_state()
super().async_write_ha_state()
else:
_LOGGER.debug(f"{self.name}: state not changed ('{prev.state}' == '{self.state}'), skipping update.")
Expand Down Expand Up @@ -352,7 +333,7 @@ async def async_added_to_hass(self) -> None:
@property
def instrument(
self,
) -> Union[BinarySensor, Climate, DoorLock, Position, Sensor, Switch, TrunkLock, Number, Instrument]:
) -> Union[BinarySensor, DoorLock, Position, Sensor, Switch, TrunkLock, Number, Instrument]:
"""Return corresponding instrument."""
return self.data.instrument(self.vin, self.component, self.attribute)

Expand Down
96 changes: 0 additions & 96 deletions custom_components/volkswagencarnet/climate.py

This file was deleted.

10 changes: 7 additions & 3 deletions custom_components/volkswagencarnet/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import asyncio

from typing import Optional

import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -54,8 +56,8 @@

class VolkswagenCarnetConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 3
task_login = None
task_finish = None
task_login: asyncio.Task | None = None
task_finish: asyncio.Task | None = None
entry = None

def __init__(self):
Expand Down Expand Up @@ -152,6 +154,7 @@ async def async_step_login(self, user_input=None):
return self.async_show_progress(
step_id="login",
progress_action="task_login",
progress_task=self.task_login,
)

# noinspection PyBroadException
Expand Down Expand Up @@ -197,7 +200,8 @@ async def async_step_reauth_confirm(self, user_input: dict = None) -> dict:

if not await self._connection.validate_login:
_LOGGER.debug(
"Unable to login to WeConnect. Need to accept a new EULA? Try logging in to the portal: https://www.portal.volkswagen-we.com/"
"Unable to login to WeConnect. Need to accept a new EULA?"
"Try logging in to the portal: https://www.portal.volkswagen-we.com/"
)
errors["base"] = "cannot_connect"
else:
Expand Down
4 changes: 0 additions & 4 deletions custom_components/volkswagencarnet/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@
"lock": "lock",
"device_tracker": "device_tracker",
"switch": "switch",
"climate": "climate",
"number": "number",
}

SERVICE_SET_TIMER_BASIC_SETTINGS = "set_timer_basic_settings"
SERVICE_UPDATE_SCHEDULE = "update_schedule"
SERVICE_UPDATE_PROFILE = "update_profile"
SERVICE_SET_CHARGER_MAX_CURRENT = "set_charger_max_current"
42 changes: 24 additions & 18 deletions custom_components/volkswagencarnet/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
import logging
from typing import Union

from homeassistant.components.number import NumberEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.components.number import (
NumberEntity,
NumberDeviceClass,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory

from . import VolkswagenEntity, VolkswagenData
from . import VolkswagenEntity
from .const import DATA_KEY, DATA, DOMAIN, UPDATE_CALLBACK

_LOGGER = logging.getLogger(__name__)


async def async_setup_platform(hass: HomeAssistant, config: ConfigEntry, async_add_entities, discovery_info=None):
async def async_setup_platform(hass: HomeAssistant, config, async_add_entities, discovery_info=None):
"""Set up the Volkswagen number platform."""
if discovery_info is None:
return
Expand Down Expand Up @@ -43,10 +45,6 @@ async def async_setup_entry(hass, entry, async_add_devices):
class VolkswagenNumber(VolkswagenEntity, NumberEntity):
"""Representation of a Volkswagen number."""

def __init__(self, data: VolkswagenData, vin: str, component: str, attribute: str, callback=None):
"""Initialize switch."""
super().__init__(data, vin, component, attribute, callback)

@property
def native_min_value(self) -> float:
"""Return the minimum value."""
Expand All @@ -63,16 +61,30 @@ def native_max_value(self) -> float:

@property
def native_step(self) -> float:
if self.instrument.native_step:
return self.instrument.native_step
return None
"""Return the increment/decrement step."""
return self.instrument.native_step

@property
def native_unit_of_measurement(self) -> str:
if self.instrument.unit:
return self.instrument.unit
return ""

@property
def native_value(self) -> float:
"""Return the entity value to represent the entity state."""
if self.instrument.state:
return self.instrument.state
return None

@property
def device_class(self) -> Union[NumberDeviceClass, None]:
"""Return the device class."""
if self.instrument.device_class is None or self.instrument.device_class in NumberDeviceClass:
return self.instrument.device_class
_LOGGER.warning(f"Unknown device class {self.instrument.device_class}")
return None

@property
def entity_category(self) -> Union[EntityCategory, str, None]:
"""Return entity category."""
Expand All @@ -81,13 +93,7 @@ def entity_category(self) -> Union[EntityCategory, str, None]:
if self.instrument.entity_type == "config":
return EntityCategory.CONFIG

@property
def native_value(self) -> float:
"""Return the entity value to represent the entity state."""
return self.instrument.state

async def async_set_native_value(self, value: int) -> None:
"""Update the current value."""
_LOGGER.debug("Update current value to %s." % value)
await self.instrument.set_value(value)
# self.notify_updated()
self.notify_updated()

0 comments on commit b1f2b6a

Please sign in to comment.