mirror of https://github.com/home-assistant/core
Migrate BMW Connected Drive to new entity naming (#77045)
Co-authored-by: rikroe <rikroe@users.noreply.github.com>
This commit is contained in:
parent
b5f9f08aa8
commit
516dc3372f
|
@ -163,6 +163,7 @@ class BMWBaseEntity(CoordinatorEntity[BMWDataUpdateCoordinator]):
|
|||
|
||||
coordinator: BMWDataUpdateCoordinator
|
||||
_attr_attribution = ATTRIBUTION
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -182,7 +183,7 @@ class BMWBaseEntity(CoordinatorEntity[BMWDataUpdateCoordinator]):
|
|||
identifiers={(DOMAIN, self.vehicle.vin)},
|
||||
manufacturer=vehicle.brand.name,
|
||||
model=vehicle.name,
|
||||
name=f"{vehicle.brand.name} {vehicle.name}",
|
||||
name=vehicle.name,
|
||||
)
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
|
|
|
@ -121,7 +121,7 @@ class BMWBinarySensorEntityDescription(
|
|||
SENSOR_TYPES: tuple[BMWBinarySensorEntityDescription, ...] = (
|
||||
BMWBinarySensorEntityDescription(
|
||||
key="lids",
|
||||
name="Doors",
|
||||
name="Lids",
|
||||
device_class=BinarySensorDeviceClass.OPENING,
|
||||
icon="mdi:car-door-lock",
|
||||
# device class opening: On means open, Off means closed
|
||||
|
@ -165,7 +165,7 @@ SENSOR_TYPES: tuple[BMWBinarySensorEntityDescription, ...] = (
|
|||
),
|
||||
BMWBinarySensorEntityDescription(
|
||||
key="check_control_messages",
|
||||
name="Control messages",
|
||||
name="Check control messages",
|
||||
device_class=BinarySensorDeviceClass.PROBLEM,
|
||||
icon="mdi:car-tire-alert",
|
||||
# device class problem: On means problem detected, Off means no problem
|
||||
|
@ -224,8 +224,6 @@ class BMWBinarySensor(BMWBaseEntity, BinarySensorEntity):
|
|||
super().__init__(coordinator, vehicle)
|
||||
self.entity_description = description
|
||||
self._unit_system = unit_system
|
||||
|
||||
self._attr_name = f"{vehicle.name} {description.key}"
|
||||
self._attr_unique_id = f"{vehicle.vin}-{description.key}"
|
||||
|
||||
@callback
|
||||
|
|
|
@ -38,31 +38,31 @@ BUTTON_TYPES: tuple[BMWButtonEntityDescription, ...] = (
|
|||
BMWButtonEntityDescription(
|
||||
key="light_flash",
|
||||
icon="mdi:car-light-alert",
|
||||
name="Flash Lights",
|
||||
name="Flash lights",
|
||||
remote_function=lambda vehicle: vehicle.remote_services.trigger_remote_light_flash(),
|
||||
),
|
||||
BMWButtonEntityDescription(
|
||||
key="sound_horn",
|
||||
icon="mdi:bullhorn",
|
||||
name="Sound Horn",
|
||||
name="Sound horn",
|
||||
remote_function=lambda vehicle: vehicle.remote_services.trigger_remote_horn(),
|
||||
),
|
||||
BMWButtonEntityDescription(
|
||||
key="activate_air_conditioning",
|
||||
icon="mdi:hvac",
|
||||
name="Activate Air Conditioning",
|
||||
name="Activate air conditioning",
|
||||
remote_function=lambda vehicle: vehicle.remote_services.trigger_remote_air_conditioning(),
|
||||
),
|
||||
BMWButtonEntityDescription(
|
||||
key="deactivate_air_conditioning",
|
||||
icon="mdi:hvac-off",
|
||||
name="Deactivate Air Conditioning",
|
||||
name="Deactivate air conditioning",
|
||||
remote_function=lambda vehicle: vehicle.remote_services.trigger_remote_air_conditioning_stop(),
|
||||
),
|
||||
BMWButtonEntityDescription(
|
||||
key="find_vehicle",
|
||||
icon="mdi:crosshairs-question",
|
||||
name="Find Vehicle",
|
||||
name="Find vehicle",
|
||||
remote_function=lambda vehicle: vehicle.remote_services.trigger_remote_vehicle_finder(),
|
||||
),
|
||||
BMWButtonEntityDescription(
|
||||
|
@ -112,8 +112,6 @@ class BMWButton(BMWBaseEntity, ButtonEntity):
|
|||
"""Initialize BMW vehicle sensor."""
|
||||
super().__init__(coordinator, vehicle)
|
||||
self.entity_description = description
|
||||
|
||||
self._attr_name = f"{vehicle.name} {description.name}"
|
||||
self._attr_unique_id = f"{vehicle.vin}-{description.key}"
|
||||
|
||||
async def async_press(self) -> None:
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from bimmer_connected.vehicle import MyBMWVehicle
|
||||
|
||||
|
@ -53,10 +54,10 @@ class BMWDeviceTracker(BMWBaseEntity, TrackerEntity):
|
|||
super().__init__(coordinator, vehicle)
|
||||
|
||||
self._attr_unique_id = vehicle.vin
|
||||
self._attr_name = vehicle.name
|
||||
self._attr_name = None
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict:
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
"""Return entity specific state attributes."""
|
||||
return {**self._attrs, ATTR_DIRECTION: self.vehicle.vehicle_location.heading}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ from typing import Any
|
|||
from bimmer_connected.vehicle import MyBMWVehicle
|
||||
from bimmer_connected.vehicle.doors_windows import LockState
|
||||
|
||||
from homeassistant.components.lock import LockEntity
|
||||
from homeassistant.components.lock import LockEntity, LockEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -32,7 +32,13 @@ async def async_setup_entry(
|
|||
|
||||
for vehicle in coordinator.account.vehicles:
|
||||
if not coordinator.read_only:
|
||||
entities.append(BMWLock(coordinator, vehicle, "lock", "BMW lock"))
|
||||
entities.append(
|
||||
BMWLock(
|
||||
coordinator,
|
||||
vehicle,
|
||||
LockEntityDescription(key="lock", device_class="lock", name="Lock"),
|
||||
)
|
||||
)
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
|
@ -43,16 +49,13 @@ class BMWLock(BMWBaseEntity, LockEntity):
|
|||
self,
|
||||
coordinator: BMWDataUpdateCoordinator,
|
||||
vehicle: MyBMWVehicle,
|
||||
attribute: str,
|
||||
sensor_name: str,
|
||||
description: LockEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the lock."""
|
||||
super().__init__(coordinator, vehicle)
|
||||
|
||||
self._attribute = attribute
|
||||
self._attr_name = f"{vehicle.name} {attribute}"
|
||||
self._attr_unique_id = f"{vehicle.vin}-{attribute}"
|
||||
self._sensor_name = sensor_name
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = f"{vehicle.vin}-{description.key}"
|
||||
self.door_lock_state_available = DOOR_LOCK_STATE in vehicle.available_attributes
|
||||
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
|
|
|
@ -56,23 +56,27 @@ SENSOR_TYPES: dict[str, BMWSensorEntityDescription] = {
|
|||
# --- Generic ---
|
||||
"charging_start_time": BMWSensorEntityDescription(
|
||||
key="charging_start_time",
|
||||
name="Charging start time",
|
||||
key_class="fuel_and_battery",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"charging_end_time": BMWSensorEntityDescription(
|
||||
key="charging_end_time",
|
||||
name="Charging end time",
|
||||
key_class="fuel_and_battery",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
),
|
||||
"charging_status": BMWSensorEntityDescription(
|
||||
key="charging_status",
|
||||
name="Charging status",
|
||||
key_class="fuel_and_battery",
|
||||
icon="mdi:ev-station",
|
||||
value=lambda x, y: x.value,
|
||||
),
|
||||
"remaining_battery_percent": BMWSensorEntityDescription(
|
||||
key="remaining_battery_percent",
|
||||
name="Remaining battery percent",
|
||||
key_class="fuel_and_battery",
|
||||
unit_type=PERCENTAGE,
|
||||
device_class=SensorDeviceClass.BATTERY,
|
||||
|
@ -80,12 +84,14 @@ SENSOR_TYPES: dict[str, BMWSensorEntityDescription] = {
|
|||
# --- Specific ---
|
||||
"mileage": BMWSensorEntityDescription(
|
||||
key="mileage",
|
||||
name="Mileage",
|
||||
icon="mdi:speedometer",
|
||||
unit_type=LENGTH,
|
||||
value=lambda x, hass: convert_and_round(x, hass.config.units.length, 2),
|
||||
),
|
||||
"remaining_range_total": BMWSensorEntityDescription(
|
||||
key="remaining_range_total",
|
||||
name="Remaining range total",
|
||||
key_class="fuel_and_battery",
|
||||
icon="mdi:map-marker-distance",
|
||||
unit_type=LENGTH,
|
||||
|
@ -93,6 +99,7 @@ SENSOR_TYPES: dict[str, BMWSensorEntityDescription] = {
|
|||
),
|
||||
"remaining_range_electric": BMWSensorEntityDescription(
|
||||
key="remaining_range_electric",
|
||||
name="Remaining range electric",
|
||||
key_class="fuel_and_battery",
|
||||
icon="mdi:map-marker-distance",
|
||||
unit_type=LENGTH,
|
||||
|
@ -100,6 +107,7 @@ SENSOR_TYPES: dict[str, BMWSensorEntityDescription] = {
|
|||
),
|
||||
"remaining_range_fuel": BMWSensorEntityDescription(
|
||||
key="remaining_range_fuel",
|
||||
name="Remaining range fuel",
|
||||
key_class="fuel_and_battery",
|
||||
icon="mdi:map-marker-distance",
|
||||
unit_type=LENGTH,
|
||||
|
@ -107,6 +115,7 @@ SENSOR_TYPES: dict[str, BMWSensorEntityDescription] = {
|
|||
),
|
||||
"remaining_fuel": BMWSensorEntityDescription(
|
||||
key="remaining_fuel",
|
||||
name="Remaining fuel",
|
||||
key_class="fuel_and_battery",
|
||||
icon="mdi:gas-station",
|
||||
unit_type=VOLUME,
|
||||
|
@ -114,6 +123,7 @@ SENSOR_TYPES: dict[str, BMWSensorEntityDescription] = {
|
|||
),
|
||||
"remaining_fuel_percent": BMWSensorEntityDescription(
|
||||
key="remaining_fuel_percent",
|
||||
name="Remaining fuel percent",
|
||||
key_class="fuel_and_battery",
|
||||
icon="mdi:gas-station",
|
||||
unit_type=PERCENTAGE,
|
||||
|
@ -159,8 +169,6 @@ class BMWSensor(BMWBaseEntity, SensorEntity):
|
|||
"""Initialize BMW vehicle sensor."""
|
||||
super().__init__(coordinator, vehicle)
|
||||
self.entity_description = description
|
||||
|
||||
self._attr_name = f"{vehicle.name} {description.key}"
|
||||
self._attr_unique_id = f"{vehicle.vin}-{description.key}"
|
||||
|
||||
# Set the correct unit of measurement based on the unit_type
|
||||
|
|
Loading…
Reference in New Issue