Skip to content

Commit

Permalink
Merge pull request #559 from robinostlund/v4.4.66-beta1
Browse files Browse the repository at this point in the history
new beta release
  • Loading branch information
robinostlund authored Jan 29, 2024
2 parents a79511c + 34112c8 commit c02e7dd
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 28 deletions.
15 changes: 12 additions & 3 deletions custom_components/volkswagencarnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.icon import icon_for_battery_level
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed, CoordinatorEntity
from homeassistant.helpers.update_coordinator import (
DataUpdateCoordinator,
UpdateFailed,
CoordinatorEntity,
)
from volkswagencarnet.vw_connection import Connection
from volkswagencarnet.vw_dashboard import (
Instrument,
Expand Down Expand Up @@ -320,7 +324,11 @@ def async_write_ha_state(self) -> None:
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]:
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:
Expand Down Expand Up @@ -552,7 +560,8 @@ async def update(self) -> Optional[Vehicle]:
async def report_request(self, vehicle: Vehicle) -> None:
"""Request car to report itself an update to Volkswagen WeConnect."""
report_interval = self.entry.options.get(
CONF_REPORT_SCAN_INTERVAL, self.entry.data.get(CONF_REPORT_SCAN_INTERVAL, DEFAULT_REPORT_UPDATE_INTERVAL)
CONF_REPORT_SCAN_INTERVAL,
self.entry.data.get(CONF_REPORT_SCAN_INTERVAL, DEFAULT_REPORT_UPDATE_INTERVAL),
)

if not self.report_last_updated:
Expand Down
6 changes: 5 additions & 1 deletion custom_components/volkswagencarnet/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import logging
from typing import Union

from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorEntity, BinarySensorDeviceClass
from homeassistant.components.binary_sensor import (
DEVICE_CLASSES,
BinarySensorEntity,
BinarySensorDeviceClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
Expand Down
7 changes: 6 additions & 1 deletion custom_components/volkswagencarnet/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ async def async_setup_entry(hass, entry, async_add_devices):
coordinator = data.coordinator
if coordinator.data is not None:
async_add_devices(
VolkswagenClimate(data=data, vin=coordinator.vin, component=instrument.component, attribute=instrument.attr)
VolkswagenClimate(
data=data,
vin=coordinator.vin,
component=instrument.component,
attribute=instrument.attr,
)
for instrument in (instrument for instrument in data.instruments if instrument.component == "climate")
)

Expand Down
22 changes: 16 additions & 6 deletions custom_components/volkswagencarnet/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ async def async_step_select_instruments(self, user_input=None):
return self.async_create_entry(
title=self._init_info[CONF_NAME],
data=self._init_info,
options={CONF_RESOURCES: user_input[CONF_RESOURCES], CONF_AVAILABLE_RESOURCES: instruments_dict},
options={
CONF_RESOURCES: user_input[CONF_RESOURCES],
CONF_AVAILABLE_RESOURCES: instruments_dict,
},
)

return self.async_show_form(
Expand Down Expand Up @@ -261,29 +264,36 @@ async def async_step_user(self, user_input=None):
vol.Optional(
CONF_REPORT_REQUEST,
default=self._config_entry.options.get(
CONF_REPORT_REQUEST, self._config_entry.data.get(CONF_REPORT_REQUEST, False)
CONF_REPORT_REQUEST,
self._config_entry.data.get(CONF_REPORT_REQUEST, False),
),
): cv.boolean,
vol.Optional(
CONF_DEBUG,
default=self._config_entry.options.get(
CONF_DEBUG, self._config_entry.data.get(CONF_DEBUG, DEFAULT_DEBUG)
CONF_DEBUG,
self._config_entry.data.get(CONF_DEBUG, DEFAULT_DEBUG),
),
): cv.boolean,
vol.Optional(
CONF_CONVERT, default=self._config_entry.data.get(CONF_CONVERT, CONF_NO_CONVERSION)
CONF_CONVERT,
default=self._config_entry.data.get(CONF_CONVERT, CONF_NO_CONVERSION),
): vol.In(CONVERT_DICT),
vol.Optional(
CONF_REPORT_SCAN_INTERVAL,
default=self._config_entry.options.get(
CONF_REPORT_SCAN_INTERVAL,
self._config_entry.data.get(CONF_REPORT_SCAN_INTERVAL, DEFAULT_REPORT_UPDATE_INTERVAL),
self._config_entry.data.get(
CONF_REPORT_SCAN_INTERVAL,
DEFAULT_REPORT_UPDATE_INTERVAL,
),
),
): cv.positive_int,
vol.Optional(
CONF_SCAN_INTERVAL,
default=self._config_entry.options.get(
CONF_SCAN_INTERVAL, self._config_entry.data.get(CONF_SCAN_INTERVAL, DEFAULT_UPDATE_INTERVAL)
CONF_SCAN_INTERVAL,
self._config_entry.data.get(CONF_SCAN_INTERVAL, DEFAULT_UPDATE_INTERVAL),
),
): cv.positive_int,
vol.Optional(
Expand Down
5 changes: 4 additions & 1 deletion custom_components/volkswagencarnet/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ async def async_setup_entry(hass: HomeAssistant, entry, async_add_devices):
if coordinator.data is not None:
async_add_devices(
VolkswagenDeviceTracker(
data=data, vin=coordinator.vin, component=instrument.component, attribute=instrument.attr
data=data,
vin=coordinator.vin,
component=instrument.component,
attribute=instrument.attr,
)
for instrument in (
instrument for instrument in data.instruments if instrument.component == "device_tracker"
Expand Down
7 changes: 6 additions & 1 deletion custom_components/volkswagencarnet/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ async def async_setup_entry(hass, entry, async_add_devices):
coordinator = data.coordinator
if coordinator.data is not None:
async_add_devices(
VolkswagenLock(data=data, vin=coordinator.vin, component=instrument.component, attribute=instrument.attr)
VolkswagenLock(
data=data,
vin=coordinator.vin,
component=instrument.component,
attribute=instrument.attr,
)
for instrument in (instrument for instrument in data.instruments if instrument.component == "lock")
)

Expand Down
6 changes: 5 additions & 1 deletion custom_components/volkswagencarnet/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ async def update_schedule(self, service_call: ServiceCall) -> bool:
departure_datetime = service_call.data.get("departure_datetime", None)
weekday_mask = service_call.data.get("weekday_mask", None)

timers: dict[int, Timer] = {1: data.get_schedule(1), 2: data.get_schedule(2), 3: data.get_schedule(3)}
timers: dict[int, Timer] = {
1: data.get_schedule(1),
2: data.get_schedule(2),
3: data.get_schedule(3),
}
if frequency is not None:
timers[timer_id].timerFrequency = frequency
if frequency == "single":
Expand Down
23 changes: 20 additions & 3 deletions custom_components/volkswagencarnet/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ async def async_setup_entry(hass: HomeAssistant, entry, async_add_devices):
class VolkswagenSwitch(VolkswagenEntity, ToggleEntity):
"""Representation of a Volkswagen WeConnect Switch."""

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

Expand Down Expand Up @@ -108,7 +115,10 @@ def assumed_state(self):
@property
def extra_state_attributes(self) -> dict[str, Any]:
"""Return extra state attributes."""
return {**super().extra_state_attributes, **(self.instrument.attributes if self.instrument is not None else {})}
return {
**super().extra_state_attributes,
**(self.instrument.attributes if self.instrument is not None else {}),
}


class VolkswagenDepartureTimer(VolkswagenSwitch):
Expand All @@ -122,7 +132,14 @@ def turn_off(self, **kwargs: Any) -> None:
"""Disable timer."""
super().turn_off()

def __init__(self, data: VolkswagenData, vin: str, component: str, attribute: str, callback=None):
def __init__(
self,
data: VolkswagenData,
vin: str,
component: str,
attribute: str,
callback=None,
):
"""Initialize class."""
super().__init__(data, vin, component, attribute, callback)
_LOGGER.debug("Departure Timer initialized")
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pytz
volkswagencarnet==4.4.65
volkswagencarnet==4.4.66b1
14 changes: 12 additions & 2 deletions tests/config_flow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
CONF_REGION: "XX",
CONF_CONVERT: CONF_NO_CONVERSION,
}
DUMMY_OPTIONS = {CONF_CONVERT: CONF_NO_CONVERSION, CONF_DEBUG: True, CONF_REGION: "XY", CONF_REPORT_REQUEST: False}
DUMMY_OPTIONS = {
CONF_CONVERT: CONF_NO_CONVERSION,
CONF_DEBUG: True,
CONF_REGION: "XY",
CONF_REPORT_REQUEST: False,
}


@patch("custom_components.volkswagencarnet.config_flow.Connection")
Expand Down Expand Up @@ -72,7 +77,12 @@ async def test_flow_user_init_auth_fails(m_connection, hass: HomeAssistant):

@patch("custom_components.volkswagencarnet.config_flow.get_coordinator")
@patch("custom_components.volkswagencarnet.config_flow.get_vehicle")
async def test_options_flow(get_vehicle: MagicMock, get_coordinator: MagicMock, hass: HomeAssistant, m_connection):
async def test_options_flow(
get_vehicle: MagicMock,
get_coordinator: MagicMock,
hass: HomeAssistant,
m_connection,
):
"""Test options flow."""
m_dashboard = MagicMock(spec=Dashboard)
m_dashboard.instruments = [
Expand Down
5 changes: 1 addition & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ def auto_enable_custom_integrations(enable_custom_integrations):
@pytest.fixture
def bypass_setup_fixture():
"""Prevent setup."""
with patch(
"custom_components.volkswagencarnet.async_setup",
return_value=True,
), patch(
with patch("custom_components.volkswagencarnet.async_setup", return_value=True,), patch(
"custom_components.volkswagencarnet.async_setup_entry",
return_value=True,
):
Expand Down
20 changes: 17 additions & 3 deletions tests/timer_services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
async def test_call_service(conn: MagicMock, hass: HomeAssistant):
"""Test service call."""
e = MockConfigEntry(
data={CONF_VEHICLE: "xyz", CONF_USERNAME: "", CONF_PASSWORD: "", CONF_DEBUG: True, CONF_REGION: "ZZ"}
data={
CONF_VEHICLE: "xyz",
CONF_USERNAME: "",
CONF_PASSWORD: "",
CONF_DEBUG: True,
CONF_REGION: "ZZ",
}
)

c: VolkswagenCoordinator = VolkswagenCoordinator(hass=hass, entry=e, update_interval=timedelta(minutes=10))
Expand Down Expand Up @@ -99,14 +105,22 @@ async def test_call_service(conn: MagicMock, hass: HomeAssistant):
]
basic_settings = BasicSettings(timestamp="2022-02-22T20:22:00Z", targetTemperature=2965, chargeMinLimit=20)
tpl = TimerProfileList(timer_profiles)
tp = TimersAndProfiles(timerProfileList=tpl, timerList=TimerList(timer_list), timerBasicSetting=basic_settings)
tp = TimersAndProfiles(
timerProfileList=tpl,
timerList=TimerList(timer_list),
timerBasicSetting=basic_settings,
)

future: Future = asyncio.Future()
future.set_result(TimerData(timersAndProfiles=tp, status={}))
get_timers.return_value = future

res = await hass.services.async_call(
domain=DOMAIN, service=SERVICE_SET_TIMER_BASIC_SETTINGS, service_data=data, blocking=True, limit=15
domain=DOMAIN,
service=SERVICE_SET_TIMER_BASIC_SETTINGS,
service_data=data,
blocking=True,
limit=15,
)

c.connection.vehicles[0].set_climatisation_temp.assert_called_once()
Expand Down
6 changes: 5 additions & 1 deletion tests/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry

from custom_components.volkswagencarnet import VolkswagenCoordinator, SchedulerService, util
from custom_components.volkswagencarnet import (
VolkswagenCoordinator,
SchedulerService,
util,
)
from custom_components.volkswagencarnet.const import (
DOMAIN,
CONF_VEHICLE,
Expand Down

0 comments on commit c02e7dd

Please sign in to comment.