Enable type checking - bmw_connected_drive (#58310)
This commit is contained in:
parent
47f6313e5b
commit
b60934b10d
4 changed files with 27 additions and 10 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
3
mypy.ini
3
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
|
||||
|
||||
|
|
|
@ -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.*",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue