mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Limit unique_id migration to platform for BMW (#131582)
This commit is contained in:
parent
a7ba63bf86
commit
8bbbbb00d5
@ -73,6 +73,7 @@ async def _async_migrate_entries(
|
|||||||
@callback
|
@callback
|
||||||
def update_unique_id(entry: er.RegistryEntry) -> dict[str, str] | None:
|
def update_unique_id(entry: er.RegistryEntry) -> dict[str, str] | None:
|
||||||
replacements = {
|
replacements = {
|
||||||
|
Platform.SENSOR.value: {
|
||||||
"charging_level_hv": "fuel_and_battery.remaining_battery_percent",
|
"charging_level_hv": "fuel_and_battery.remaining_battery_percent",
|
||||||
"fuel_percent": "fuel_and_battery.remaining_fuel_percent",
|
"fuel_percent": "fuel_and_battery.remaining_fuel_percent",
|
||||||
"ac_current_limit": "charging_profile.ac_current_limit",
|
"ac_current_limit": "charging_profile.ac_current_limit",
|
||||||
@ -88,8 +89,13 @@ async def _async_migrate_entries(
|
|||||||
"remaining_fuel_percent": "fuel_and_battery.remaining_fuel_percent",
|
"remaining_fuel_percent": "fuel_and_battery.remaining_fuel_percent",
|
||||||
"activity": "climate.activity",
|
"activity": "climate.activity",
|
||||||
}
|
}
|
||||||
if (key := entry.unique_id.split("-")[-1]) in replacements:
|
}
|
||||||
new_unique_id = entry.unique_id.replace(key, replacements[key])
|
if (key := entry.unique_id.split("-")[-1]) in replacements.get(
|
||||||
|
entry.domain, []
|
||||||
|
):
|
||||||
|
new_unique_id = entry.unique_id.replace(
|
||||||
|
key, replacements[entry.domain][key]
|
||||||
|
)
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Migrating entity '%s' unique_id from '%s' to '%s'",
|
"Migrating entity '%s' unique_id from '%s' to '%s'",
|
||||||
entry.entity_id,
|
entry.entity_id,
|
||||||
|
@ -10,7 +10,7 @@ from homeassistant.components.bmw_connected_drive.const import (
|
|||||||
CONF_READ_ONLY,
|
CONF_READ_ONLY,
|
||||||
DOMAIN as BMW_DOMAIN,
|
DOMAIN as BMW_DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
|
|
||||||
@ -18,6 +18,9 @@ from . import FIXTURE_CONFIG_ENTRY
|
|||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
BINARY_SENSOR_DOMAIN = Platform.BINARY_SENSOR.value
|
||||||
|
SENSOR_DOMAIN = Platform.SENSOR.value
|
||||||
|
|
||||||
VIN = "WBYYYYYYYYYYYYYYY"
|
VIN = "WBYYYYYYYYYYYYYYY"
|
||||||
VEHICLE_NAME = "i3 (+ REX)"
|
VEHICLE_NAME = "i3 (+ REX)"
|
||||||
VEHICLE_NAME_SLUG = "i3_rex"
|
VEHICLE_NAME_SLUG = "i3_rex"
|
||||||
@ -109,6 +112,28 @@ async def test_migrate_options_from_data(hass: HomeAssistant) -> None:
|
|||||||
f"{VIN}-mileage",
|
f"{VIN}-mileage",
|
||||||
f"{VIN}-mileage",
|
f"{VIN}-mileage",
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
{
|
||||||
|
"domain": SENSOR_DOMAIN,
|
||||||
|
"platform": BMW_DOMAIN,
|
||||||
|
"unique_id": f"{VIN}-charging_status",
|
||||||
|
"suggested_object_id": f"{VEHICLE_NAME} Charging Status",
|
||||||
|
"disabled_by": None,
|
||||||
|
},
|
||||||
|
f"{VIN}-charging_status",
|
||||||
|
f"{VIN}-fuel_and_battery.charging_status",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
{
|
||||||
|
"domain": BINARY_SENSOR_DOMAIN,
|
||||||
|
"platform": BMW_DOMAIN,
|
||||||
|
"unique_id": f"{VIN}-charging_status",
|
||||||
|
"suggested_object_id": f"{VEHICLE_NAME} Charging Status",
|
||||||
|
"disabled_by": None,
|
||||||
|
},
|
||||||
|
f"{VIN}-charging_status",
|
||||||
|
f"{VIN}-charging_status",
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_migrate_unique_ids(
|
async def test_migrate_unique_ids(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user