1
mirror of https://github.com/home-assistant/core synced 2024-10-04 07:58:43 +02:00

Remove Sonos migrations (#113506)

This commit is contained in:
Joost Lekkerkerker 2024-03-15 14:40:40 +01:00 committed by GitHub
parent eb1f37ea9b
commit 4b4258881b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,7 +11,7 @@ from soco.exceptions import SoCoSlaveException, SoCoUPnPException
from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TIME, EntityCategory, Platform
from homeassistant.const import ATTR_TIME, EntityCategory
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -91,9 +91,6 @@ async def async_setup_entry(
"""Set up Sonos from a config entry."""
async def _async_create_alarms(speaker: SonosSpeaker, alarm_ids: list[str]) -> None:
async_migrate_alarm_unique_ids(
hass, config_entry, speaker.household_id, alarm_ids
)
entities = []
created_alarms = (
hass.data[DATA_SONOS].alarms[speaker.household_id].created_alarm_ids
@ -123,10 +120,6 @@ async def async_setup_entry(
available_soco_attributes, speaker
)
for feature_type in available_features:
if feature_type == ATTR_SPEECH_ENHANCEMENT:
async_migrate_speech_enhancement_entity_unique_id(
hass, config_entry, speaker
)
_LOGGER.debug(
"Creating %s switch on %s",
feature_type,
@ -354,88 +347,3 @@ class SonosAlarmEntity(SonosEntity, SwitchEntity):
"""Handle turn on/off of alarm switch."""
self.alarm.enabled = turn_on
self.alarm.save()
@callback
def async_migrate_alarm_unique_ids(
hass: HomeAssistant,
config_entry: ConfigEntry,
household_id: str,
alarm_ids: list[str],
) -> None:
"""Migrate alarm switch unique_ids in the entity registry to the new format."""
entity_registry = er.async_get(hass)
registry_entries = er.async_entries_for_config_entry(
entity_registry, config_entry.entry_id
)
alarm_entries = [
(entry.unique_id, entry)
for entry in registry_entries
if entry.domain == Platform.SWITCH and entry.original_icon == "mdi:alarm"
]
for old_unique_id, alarm_entry in alarm_entries:
if ":" in old_unique_id:
continue
entry_alarm_id = old_unique_id.split("-")[-1]
if entry_alarm_id in alarm_ids:
new_unique_id = f"alarm-{household_id}:{entry_alarm_id}"
_LOGGER.debug(
"Migrating unique_id for %s from %s to %s",
alarm_entry.entity_id,
old_unique_id,
new_unique_id,
)
entity_registry.async_update_entity(
alarm_entry.entity_id, new_unique_id=new_unique_id
)
@callback
def async_migrate_speech_enhancement_entity_unique_id(
hass: HomeAssistant,
config_entry: ConfigEntry,
speaker: SonosSpeaker,
) -> None:
"""Migrate Speech Enhancement switch entity unique_id."""
entity_registry = er.async_get(hass)
registry_entries = er.async_entries_for_config_entry(
entity_registry, config_entry.entry_id
)
speech_enhancement_entries = [
entry
for entry in registry_entries
if entry.domain == Platform.SWITCH
and entry.original_icon == FEATURE_ICONS[ATTR_SPEECH_ENHANCEMENT]
and entry.unique_id.startswith(speaker.soco.uid)
]
if len(speech_enhancement_entries) > 1:
_LOGGER.warning(
(
"Migration of Speech Enhancement switches on %s failed,"
" manual cleanup required: %s"
),
speaker.zone_name,
[e.entity_id for e in speech_enhancement_entries],
)
return
if len(speech_enhancement_entries) == 1:
old_entry = speech_enhancement_entries[0]
if old_entry.unique_id.endswith("dialog_level"):
return
new_unique_id = f"{speaker.soco.uid}-{ATTR_SPEECH_ENHANCEMENT}"
_LOGGER.debug(
"Migrating unique_id for %s from %s to %s",
old_entry.entity_id,
old_entry.unique_id,
new_unique_id,
)
entity_registry.async_update_entity(
old_entry.entity_id, new_unique_id=new_unique_id
)