diff --git a/custom_components/volkswagencarnet/__init__.py b/custom_components/volkswagencarnet/__init__.py index b6cf352..d9e1e66 100755 --- a/custom_components/volkswagencarnet/__init__.py +++ b/custom_components/volkswagencarnet/__init__.py @@ -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, @@ -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: @@ -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: diff --git a/custom_components/volkswagencarnet/binary_sensor.py b/custom_components/volkswagencarnet/binary_sensor.py index 91912f6..65250f6 100644 --- a/custom_components/volkswagencarnet/binary_sensor.py +++ b/custom_components/volkswagencarnet/binary_sensor.py @@ -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 diff --git a/custom_components/volkswagencarnet/climate.py b/custom_components/volkswagencarnet/climate.py index d7e92b4..933150a 100644 --- a/custom_components/volkswagencarnet/climate.py +++ b/custom_components/volkswagencarnet/climate.py @@ -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") ) diff --git a/custom_components/volkswagencarnet/config_flow.py b/custom_components/volkswagencarnet/config_flow.py index c29d3b4..4283d04 100644 --- a/custom_components/volkswagencarnet/config_flow.py +++ b/custom_components/volkswagencarnet/config_flow.py @@ -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( @@ -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( diff --git a/custom_components/volkswagencarnet/device_tracker.py b/custom_components/volkswagencarnet/device_tracker.py index 2a512de..d3542d2 100644 --- a/custom_components/volkswagencarnet/device_tracker.py +++ b/custom_components/volkswagencarnet/device_tracker.py @@ -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" diff --git a/custom_components/volkswagencarnet/lock.py b/custom_components/volkswagencarnet/lock.py index 0e4a54a..4c355e0 100644 --- a/custom_components/volkswagencarnet/lock.py +++ b/custom_components/volkswagencarnet/lock.py @@ -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") ) diff --git a/custom_components/volkswagencarnet/services.py b/custom_components/volkswagencarnet/services.py index 7559949..9611fd9 100644 --- a/custom_components/volkswagencarnet/services.py +++ b/custom_components/volkswagencarnet/services.py @@ -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": diff --git a/custom_components/volkswagencarnet/switch.py b/custom_components/volkswagencarnet/switch.py index fe6fb48..32f5f3e 100644 --- a/custom_components/volkswagencarnet/switch.py +++ b/custom_components/volkswagencarnet/switch.py @@ -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) @@ -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): @@ -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") diff --git a/requirements.txt b/requirements.txt index 4dfbc2d..cd709b7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ pytz -volkswagencarnet==4.4.65 +volkswagencarnet==4.4.66b1 diff --git a/tests/config_flow_test.py b/tests/config_flow_test.py index 39226e2..0abc014 100644 --- a/tests/config_flow_test.py +++ b/tests/config_flow_test.py @@ -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") @@ -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 = [ diff --git a/tests/conftest.py b/tests/conftest.py index 69241c8..1e072fe 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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, ): diff --git a/tests/timer_services_test.py b/tests/timer_services_test.py index ff437d9..8dae541 100644 --- a/tests/timer_services_test.py +++ b/tests/timer_services_test.py @@ -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)) @@ -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() diff --git a/tests/util_test.py b/tests/util_test.py index b565f5b..70be35d 100644 --- a/tests/util_test.py +++ b/tests/util_test.py @@ -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,