From d043df4a7f1143a76d22505595d22eea185513ee Mon Sep 17 00:00:00 2001 From: Nils Vogels Date: Fri, 3 Jan 2025 00:17:40 +0100 Subject: [PATCH 1/2] Rename references to ConfigEntry from config to entry --- custom_components/myskoda/__init__.py | 22 ++++++++++---------- custom_components/myskoda/button.py | 2 +- custom_components/myskoda/climate.py | 10 ++++----- custom_components/myskoda/coordinator.py | 26 ++++++++++++------------ custom_components/myskoda/lock.py | 10 ++++----- custom_components/myskoda/number.py | 2 +- custom_components/myskoda/switch.py | 2 +- 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/custom_components/myskoda/__init__.py b/custom_components/myskoda/__init__.py index 87a92d3..bbe020c 100644 --- a/custom_components/myskoda/__init__.py +++ b/custom_components/myskoda/__init__.py @@ -48,11 +48,11 @@ ] -async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up MySkoda integration from a config entry.""" trace_configs = [] - if config.options.get("tracing"): + if entry.options.get("tracing"): trace_configs.append(TRACE_CONFIG) session = async_create_clientsession( @@ -61,7 +61,7 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: myskoda = MySkoda(session, get_default_context(), mqtt_enabled=False) try: - await myskoda.connect(config.data["email"], config.data["password"]) + await myskoda.connect(entry.data["email"], entry.data["password"]) except AuthorizationFailedError as exc: _LOGGER.debug("Authorization with MySkoda failed.") raise ConfigEntryAuthFailed from exc @@ -69,32 +69,32 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: _LOGGER.error( "Change to terms and conditions or consents detected while logging in. Please log into the MySkoda app (may require a logout first) to access the new Terms and Conditions. This HomeAssistant integration currently can not continue." ) - async_create_tnc_issue(hass, config.entry_id) + async_create_tnc_issue(hass, entry.entry_id) raise ConfigEntryNotReady from exc except (CSRFError, InvalidUrlClientError) as exc: _LOGGER.debug("An error occurred during login.") raise ConfigEntryNotReady from exc except ClientResponseError as err: - handle_aiohttp_error("setup", err, hass, config) + handle_aiohttp_error("setup", err, hass, entry) except Exception: _LOGGER.exception("Login with MySkoda failed for an unknown reason.") return False - async_delete_tnc_issue(hass, config.entry_id) - async_delete_spin_issue(hass, config.entry_id) + async_delete_tnc_issue(hass, entry.entry_id) + async_delete_spin_issue(hass, entry.entry_id) coordinators: dict[str, MySkodaDataUpdateCoordinator] = {} vehicles = await myskoda.list_vehicle_vins() for vin in vehicles: - coordinator = MySkodaDataUpdateCoordinator(hass, config, myskoda, vin) + coordinator = MySkodaDataUpdateCoordinator(hass, entry, myskoda, vin) await coordinator.async_config_entry_first_refresh() coordinators[vin] = coordinator hass.data.setdefault(DOMAIN, {}) - hass.data[DOMAIN][config.entry_id] = {COORDINATORS: coordinators} + hass.data[DOMAIN][entry.entry_id] = {COORDINATORS: coordinators} - await hass.config_entries.async_forward_entry_setups(config, PLATFORMS) - config.async_on_unload(config.add_update_listener(_async_update_listener)) + await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + entry.async_on_unload(entry.add_update_listener(_async_update_listener)) return True diff --git a/custom_components/myskoda/button.py b/custom_components/myskoda/button.py index dd86ef5..7de294e 100644 --- a/custom_components/myskoda/button.py +++ b/custom_components/myskoda/button.py @@ -54,7 +54,7 @@ def is_supported(self) -> bool: all_capabilities_present = all( self.vehicle.has_capability(cap) for cap in self.required_capabilities() ) - readonly = self.coordinator.config.options.get(CONF_READONLY) + readonly = self.coordinator.entry.options.get(CONF_READONLY) return all_capabilities_present and not readonly diff --git a/custom_components/myskoda/climate.py b/custom_components/myskoda/climate.py index 3d76236..c0ebc19 100644 --- a/custom_components/myskoda/climate.py +++ b/custom_components/myskoda/climate.py @@ -48,13 +48,13 @@ async def async_setup_entry( hass: HomeAssistant, - config: ConfigEntry, + entry: ConfigEntry, async_add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: add_supported_entities( available_entities=[MySkodaClimate, AuxiliaryHeater], - coordinators=hass.data[DOMAIN][config.entry_id][COORDINATORS], + coordinators=hass.data[DOMAIN][entry.entry_id][COORDINATORS], async_add_entities=async_add_entities, ) @@ -190,7 +190,7 @@ def is_supported(self) -> bool: all_capabilities_present = all( self.vehicle.has_capability(cap) for cap in self.required_capabilities() ) - readonly = self.coordinator.config.options.get(CONF_READONLY) + readonly = self.coordinator.entry.options.get(CONF_READONLY) return all_capabilities_present and not readonly @@ -287,7 +287,7 @@ def _state(self) -> str | None: @property def available(self) -> bool: # noqa: D102 - if not self.coordinator.config.options.get(CONF_SPIN): + if not self.coordinator.entry.options.get(CONF_SPIN): return False return True @@ -357,7 +357,7 @@ async def handle_mode(desired_state, start_mode=None, **kwargs): start_mode=start_mode, **kwargs, ) - spin = self.coordinator.config.options.get(CONF_SPIN) + spin = self.coordinator.entry.options.get(CONF_SPIN) if spin is None: _LOGGER.error("Cannot start %s: No S-PIN set.", desired_state) return diff --git a/custom_components/myskoda/coordinator.py b/custom_components/myskoda/coordinator.py index 3b2da8c..a3f07cb 100644 --- a/custom_components/myskoda/coordinator.py +++ b/custom_components/myskoda/coordinator.py @@ -90,7 +90,7 @@ class MySkodaDataUpdateCoordinator(DataUpdateCoordinator[State]): data: State def __init__( - self, hass: HomeAssistant, config: ConfigEntry, myskoda: MySkoda, vin: str + self, hass: HomeAssistant, entry: ConfigEntry, myskoda: MySkoda, vin: str ) -> None: """Create a new coordinator.""" @@ -99,7 +99,7 @@ def __init__( _LOGGER, name=DOMAIN, update_interval=timedelta( - minutes=config.options.get( + minutes=entry.options.get( CONF_POLL_INTERVAL, DEFAULT_FETCH_INTERVAL_IN_MINUTES ) ), @@ -109,7 +109,7 @@ def __init__( self.vin: str = vin self.myskoda: MySkoda = myskoda self.operations: OrderedDict = OrderedDict() - self.config: ConfigEntry = config + self.entry: ConfigEntry = entry self.update_driving_range = self._debounce(self._update_driving_range) self.update_charging = self._debounce(self._update_charging) self.update_air_conditioning = self._debounce(self._update_air_conditioning) @@ -134,7 +134,7 @@ async def _async_update_data(self) -> State: try: user = await self.myskoda.get_user() except ClientResponseError as err: - handle_aiohttp_error("user", err, self.hass, self.config) + handle_aiohttp_error("user", err, self.hass, self.entry) if self.data.user: user = self.data.user else: @@ -165,7 +165,7 @@ async def _async_update_data(self) -> State: else: vehicle = await self.myskoda.get_vehicle(self.vin) except ClientResponseError as err: - handle_aiohttp_error("vehicle", err, self.hass, self.config) + handle_aiohttp_error("vehicle", err, self.hass, self.entry) except ClientError as err: raise UpdateFailed("Error getting update from MySkoda API: %s", err) @@ -302,7 +302,7 @@ async def _update_driving_range(self) -> None: try: driving_range = await self.myskoda.get_driving_range(self.vin) except ClientResponseError as err: - handle_aiohttp_error("driving range", err, self.hass, self.config) + handle_aiohttp_error("driving range", err, self.hass, self.entry) except ClientError as err: raise UpdateFailed("Error getting update from MySkoda API: %s", err) @@ -318,7 +318,7 @@ async def _update_charging(self) -> None: try: charging = await self.myskoda.get_charging(self.vin) except ClientResponseError as err: - handle_aiohttp_error("charging information", err, self.hass, self.config) + handle_aiohttp_error("charging information", err, self.hass, self.entry) except ClientError as err: raise UpdateFailed("Error getting update from MySkoda API: %s", err) @@ -334,7 +334,7 @@ async def _update_air_conditioning(self) -> None: try: air_conditioning = await self.myskoda.get_air_conditioning(self.vin) except ClientResponseError as err: - handle_aiohttp_error("AC update", err, self.hass, self.config) + handle_aiohttp_error("AC update", err, self.hass, self.entry) except ClientError as err: raise UpdateFailed("Error getting update from MySkoda API: %s", err) @@ -355,7 +355,7 @@ async def _update_auxiliary_heating(self) -> None: try: auxiliary_heating = await self.myskoda.get_auxiliary_heating(self.vin) except ClientResponseError as err: - handle_aiohttp_error("Auxiliary update", err, self.hass, self.config) + handle_aiohttp_error("Auxiliary update", err, self.hass, self.entry) except ClientError as err: raise UpdateFailed("Error getting update from MySkoda API: %s", err) @@ -371,7 +371,7 @@ async def _update_status(self) -> None: try: status = await self.myskoda.get_status(self.vin) except ClientResponseError as err: - handle_aiohttp_error("vehicle status", err, self.hass, self.config) + handle_aiohttp_error("vehicle status", err, self.hass, self.entry) except ClientError as err: raise UpdateFailed("Error getting update from MySkoda API: %s", err) @@ -387,7 +387,7 @@ async def _update_departure_info(self) -> None: try: departure_info = await self.myskoda.get_departure_timers(self.vin) except ClientResponseError as err: - handle_aiohttp_error("departure info", err, self.hass, self.config) + handle_aiohttp_error("departure info", err, self.hass, self.entry) except ClientError as err: raise UpdateFailed("Error getting update from MySkoda API: %s", err) @@ -403,7 +403,7 @@ async def _update_vehicle(self) -> None: try: vehicle = await self.myskoda.get_vehicle(self.vin) except ClientResponseError as err: - handle_aiohttp_error("vehicle update", err, self.hass, self.config) + handle_aiohttp_error("vehicle update", err, self.hass, self.entry) except ClientError as err: raise UpdateFailed("Error getting update from MySkoda API: %s", err) @@ -422,7 +422,7 @@ async def _update_positions(self) -> None: await asyncio.sleep(60) # GPS is not updated immediately, wait 60 seconds positions = await self.myskoda.get_positions(self.vin) except ClientResponseError as err: - handle_aiohttp_error("positions", err, self.hass, self.config) + handle_aiohttp_error("positions", err, self.hass, self.entry) except ClientError as err: raise UpdateFailed("Error getting update from MySkoda API: %s", err) diff --git a/custom_components/myskoda/lock.py b/custom_components/myskoda/lock.py index 98570cb..8952c75 100644 --- a/custom_components/myskoda/lock.py +++ b/custom_components/myskoda/lock.py @@ -56,7 +56,7 @@ class DoorLock(MySkodaLock): @property def available(self) -> bool: - if not self.coordinator.config.options.get(CONF_SPIN): + if not self.coordinator.entry.options.get(CONF_SPIN): return False return True @@ -77,18 +77,18 @@ async def _async_lock_unlock(self, lock: bool, spin: str, **kwargs): # noqa: D1 _LOGGER.error("Failed to unlock vehicle: %s", exc) async def async_lock(self, **kwargs) -> None: - if self.coordinator.config.options.get(CONF_SPIN): + if self.coordinator.entry.options.get(CONF_SPIN): await self._async_lock_unlock( - lock=True, spin=self.coordinator.config.options.get(CONF_SPIN) + lock=True, spin=self.coordinator.entry.options.get(CONF_SPIN) ) _LOGGER.info("Sent command to lock the vehicle.") else: _LOGGER.error("Cannot lock car: No S-PIN set.") async def async_unlock(self, **kwargs) -> None: - if self.coordinator.config.options.get(CONF_SPIN): + if self.coordinator.entry.options.get(CONF_SPIN): await self._async_lock_unlock( - lock=False, spin=self.coordinator.config.options.get(CONF_SPIN) + lock=False, spin=self.coordinator.entry.options.get(CONF_SPIN) ) _LOGGER.info("Sent command to unlock the vehicle.") else: diff --git a/custom_components/myskoda/number.py b/custom_components/myskoda/number.py index ffdaa2a..f56150b 100644 --- a/custom_components/myskoda/number.py +++ b/custom_components/myskoda/number.py @@ -50,7 +50,7 @@ def is_supported(self) -> bool: all_capabilities_present = all( self.vehicle.has_capability(cap) for cap in self.required_capabilities() ) - readonly = self.coordinator.config.options.get(CONF_READONLY) + readonly = self.coordinator.entry.options.get(CONF_READONLY) return all_capabilities_present and not readonly diff --git a/custom_components/myskoda/switch.py b/custom_components/myskoda/switch.py index ac7cdbf..6c024a5 100644 --- a/custom_components/myskoda/switch.py +++ b/custom_components/myskoda/switch.py @@ -77,7 +77,7 @@ def is_supported(self) -> bool: all_capabilities_present = all( self.vehicle.has_capability(cap) for cap in self.required_capabilities() ) - readonly = self.coordinator.config.options.get(CONF_READONLY) + readonly = self.coordinator.entry.options.get(CONF_READONLY) return all_capabilities_present and not readonly From d114de9e41ef95fe0d2d6926051caba112788963 Mon Sep 17 00:00:00 2001 From: Nils Vogels Date: Sat, 4 Jan 2025 02:28:13 +0100 Subject: [PATCH 2/2] Fix complaints from linter --- custom_components/myskoda/coordinator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/myskoda/coordinator.py b/custom_components/myskoda/coordinator.py index bb25a54..43a7644 100644 --- a/custom_components/myskoda/coordinator.py +++ b/custom_components/myskoda/coordinator.py @@ -157,14 +157,14 @@ async def _async_update_data(self) -> State: config = self.data.config if self.data and self.data.config else Config() operations = self.operations - if self.config.state == ConfigEntryState.SETUP_IN_PROGRESS: + if self.entry.state == ConfigEntryState.SETUP_IN_PROGRESS: _LOGGER.debug("Performing initial data fetch for vin %s", self.vin) try: user = await self.myskoda.get_user() vehicle = await self._async_get_minimal_data() except ClientResponseError as err: handle_aiohttp_error( - "setup user and vehicle", err, self.hass, self.config + "setup user and vehicle", err, self.hass, self.entry ) raise UpdateFailed("Failed to retrieve initial data during setup") @@ -186,7 +186,7 @@ def _async_finish_startup(hass, config, vin) -> None: async_at_started( hass=self.hass, - at_start_cb=_async_finish_startup(self.hass, self.config, self.vin), # pyright: ignore[reportArgumentType] + at_start_cb=_async_finish_startup(self.hass, self.entry, self.vin), # pyright: ignore[reportArgumentType] ) # Schedule post-setup tasks return State(vehicle, user, config, operations)