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