Enable type checking - bmw_connected_drive (#58310)

This commit is contained in:
Marc Mueller 2021-10-26 20:27:26 +02:00 committed by GitHub
parent 47f6313e5b
commit b60934b10d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 10 deletions

View File

@ -1,6 +1,7 @@
"""Reads vehicle status from BMW connected drive portal.""" """Reads vehicle status from BMW connected drive portal."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Callable
import logging import logging
from bimmer_connected.account import ConnectedDriveAccount from bimmer_connected.account import ConnectedDriveAccount
@ -282,7 +283,7 @@ class BMWConnectedDriveAccount:
self.read_only = read_only self.read_only = read_only
self.account = ConnectedDriveAccount(username, password, region) self.account = ConnectedDriveAccount(username, password, region)
self.name = name self.name = name
self._update_listeners = [] self._update_listeners: list[Callable[[], None]] = []
# Set observer position once for older cars to be in range for # Set observer position once for older cars to be in range for
# GPS position (pre-7/2014, <2km) and get new data from API # GPS position (pre-7/2014, <2km) and get new data from API
@ -311,7 +312,7 @@ class BMWConnectedDriveAccount:
) )
_LOGGER.exception(exception) _LOGGER.exception(exception)
def add_update_listener(self, listener): def add_update_listener(self, listener: Callable[[], None]) -> None:
"""Add a listener for update notifications.""" """Add a listener for update notifications."""
self._update_listeners.append(listener) self._update_listeners.append(listener)

View File

@ -388,12 +388,18 @@ async def async_setup_entry(
if service == SERVICE_LAST_TRIP: if service == SERVICE_LAST_TRIP:
entities.extend( entities.extend(
[ [
# mypy issues will be fixed in next release
# https://github.com/python/mypy/issues/9096
BMWConnectedDriveSensor( 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 for attribute_name in vehicle.state.last_trip.available_attributes
if attribute_name != "date" 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: 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 vehicle_last_trip = self._vehicle.state.last_trip
if sensor_key == "date_utc": if sensor_key == "date_utc":
date_str = getattr(vehicle_last_trip, "date") 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: else:
self._attr_native_value = getattr(vehicle_last_trip, sensor_key) self._attr_native_value = getattr(vehicle_last_trip, sensor_key)
elif self._service == SERVICE_ALL_TRIPS: elif self._service == SERVICE_ALL_TRIPS:
@ -553,7 +566,14 @@ class BMWConnectedDriveSensor(BMWConnectedDriveBaseEntity, SensorEntity):
return return
if sensor_key == "reset_date_utc": if sensor_key == "reset_date_utc":
date_str = getattr(vehicle_all_trips, "reset_date") 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: else:
self._attr_native_value = getattr(vehicle_all_trips, sensor_key) self._attr_native_value = getattr(vehicle_all_trips, sensor_key)

View File

@ -1546,9 +1546,6 @@ ignore_errors = true
[mypy-homeassistant.components.blueprint.*] [mypy-homeassistant.components.blueprint.*]
ignore_errors = true ignore_errors = true
[mypy-homeassistant.components.bmw_connected_drive.*]
ignore_errors = true
[mypy-homeassistant.components.climacell.*] [mypy-homeassistant.components.climacell.*]
ignore_errors = true ignore_errors = true

View File

@ -16,7 +16,6 @@ from .model import Config, Integration
IGNORED_MODULES: Final[list[str]] = [ IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.awair.*", "homeassistant.components.awair.*",
"homeassistant.components.blueprint.*", "homeassistant.components.blueprint.*",
"homeassistant.components.bmw_connected_drive.*",
"homeassistant.components.climacell.*", "homeassistant.components.climacell.*",
"homeassistant.components.cloud.*", "homeassistant.components.cloud.*",
"homeassistant.components.config.*", "homeassistant.components.config.*",