diff --git a/homeassistant/components/bmw_connected_drive/__init__.py b/homeassistant/components/bmw_connected_drive/__init__.py index 722809dff5c37f75a6348f8b357665a3a674936a..0dad3e1fce19bd967e91997c60336322c36924f0 100644 --- a/homeassistant/components/bmw_connected_drive/__init__.py +++ b/homeassistant/components/bmw_connected_drive/__init__.py @@ -1,6 +1,7 @@ """Reads vehicle status from BMW connected drive portal.""" from __future__ import annotations +from collections.abc import Callable import logging from bimmer_connected.account import ConnectedDriveAccount @@ -282,7 +283,7 @@ class BMWConnectedDriveAccount: self.read_only = read_only self.account = ConnectedDriveAccount(username, password, region) self.name = name - self._update_listeners = [] + self._update_listeners: list[Callable[[], None]] = [] # Set observer position once for older cars to be in range for # GPS position (pre-7/2014, <2km) and get new data from API @@ -311,7 +312,7 @@ class BMWConnectedDriveAccount: ) _LOGGER.exception(exception) - def add_update_listener(self, listener): + def add_update_listener(self, listener: Callable[[], None]) -> None: """Add a listener for update notifications.""" self._update_listeners.append(listener) diff --git a/homeassistant/components/bmw_connected_drive/sensor.py b/homeassistant/components/bmw_connected_drive/sensor.py index daf7569bc7761f8fe6cdd9c6a99f1009c36a2ed8..d2b434f96cd88a6a07fdea98958d6378e37ae69c 100644 --- a/homeassistant/components/bmw_connected_drive/sensor.py +++ b/homeassistant/components/bmw_connected_drive/sensor.py @@ -388,12 +388,18 @@ async def async_setup_entry( if service == SERVICE_LAST_TRIP: entities.extend( [ + # mypy issues will be fixed in next release + # https://github.com/python/mypy/issues/9096 BMWConnectedDriveSensor( - account, vehicle, description, unit_system, service + account, + vehicle, + description, # type: ignore[arg-type] + unit_system, + service, ) for attribute_name in vehicle.state.last_trip.available_attributes if attribute_name != "date" - and (description := SENSOR_TYPES.get(attribute_name)) + and (description := SENSOR_TYPES.get(attribute_name)) # type: ignore[no-redef] ] ) if "date" in vehicle.state.last_trip.available_attributes: @@ -534,7 +540,14 @@ class BMWConnectedDriveSensor(BMWConnectedDriveBaseEntity, SensorEntity): vehicle_last_trip = self._vehicle.state.last_trip if sensor_key == "date_utc": date_str = getattr(vehicle_last_trip, "date") - self._attr_native_value = dt_util.parse_datetime(date_str).isoformat() + if parsed_date := dt_util.parse_datetime(date_str): + self._attr_native_value = parsed_date.isoformat() + else: + _LOGGER.debug( + "Could not parse date string for 'date_utc' sensor: %s", + date_str, + ) + self._attr_native_value = None else: self._attr_native_value = getattr(vehicle_last_trip, sensor_key) elif self._service == SERVICE_ALL_TRIPS: @@ -553,7 +566,14 @@ class BMWConnectedDriveSensor(BMWConnectedDriveBaseEntity, SensorEntity): return if sensor_key == "reset_date_utc": date_str = getattr(vehicle_all_trips, "reset_date") - self._attr_native_value = dt_util.parse_datetime(date_str).isoformat() + if parsed_date := dt_util.parse_datetime(date_str): + self._attr_native_value = parsed_date.isoformat() + else: + _LOGGER.debug( + "Could not parse date string for 'reset_date_utc' sensor: %s", + date_str, + ) + self._attr_native_value = None else: self._attr_native_value = getattr(vehicle_all_trips, sensor_key) diff --git a/mypy.ini b/mypy.ini index 058d587ec22addadc8801409ef07f44666d8d4fa..315ee094b406510e9682797898b8f67066ef7e72 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1546,9 +1546,6 @@ ignore_errors = true [mypy-homeassistant.components.blueprint.*] ignore_errors = true -[mypy-homeassistant.components.bmw_connected_drive.*] -ignore_errors = true - [mypy-homeassistant.components.climacell.*] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 6ffd2e0da4239239b5792d16c43ee7a9573a53ce..7d2899843355e51bb627c31b74e033d51aaff7c3 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -16,7 +16,6 @@ from .model import Config, Integration IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.awair.*", "homeassistant.components.blueprint.*", - "homeassistant.components.bmw_connected_drive.*", "homeassistant.components.climacell.*", "homeassistant.components.cloud.*", "homeassistant.components.config.*",