|
2 | 2 |
|
3 | 3 | from __future__ import annotations
|
4 | 4 |
|
| 5 | +from typing import Iterable |
| 6 | + |
5 | 7 | from vivintpy.devices.alarm_panel import AlarmPanel
|
6 | 8 | from vivintpy.enums import ArmedState
|
7 | 9 |
|
8 | 10 | from homeassistant.components.alarm_control_panel import (
|
| 11 | + DOMAIN as PLATFORM, |
9 | 12 | AlarmControlPanelEntity,
|
10 | 13 | AlarmControlPanelEntityFeature as Feature,
|
11 | 14 | CodeFormat,
|
|
19 | 22 | STATE_ALARM_TRIGGERED,
|
20 | 23 | )
|
21 | 24 | from homeassistant.core import HomeAssistant
|
| 25 | +from homeassistant.helpers import entity_registry as er |
22 | 26 | from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
23 | 27 | from homeassistant.helpers.typing import StateType
|
24 | 28 |
|
25 | 29 | from . import VivintConfigEntry
|
26 |
| -from .const import CONF_DISARM_CODE |
| 30 | +from .const import CONF_DISARM_CODE, DOMAIN |
27 | 31 | from .hub import VivintEntity, VivintHub
|
28 | 32 |
|
29 | 33 | ARMED_STATE_MAP = {
|
@@ -62,6 +66,9 @@ async def async_setup_entry(
|
62 | 66 | if not entities:
|
63 | 67 | return
|
64 | 68 |
|
| 69 | + # Migrate unique ids |
| 70 | + async_update_unique_id(hass, PLATFORM, entities) |
| 71 | + |
65 | 72 | async_add_entities(entities)
|
66 | 73 |
|
67 | 74 |
|
@@ -105,3 +112,19 @@ async def async_alarm_arm_away(self, code: str | None = None) -> None:
|
105 | 112 | async def async_alarm_trigger(self, code: str | None = None) -> None:
|
106 | 113 | """Send alarm trigger command."""
|
107 | 114 | await self.device.trigger_alarm()
|
| 115 | + |
| 116 | + |
| 117 | +# to be removed 2025-01 |
| 118 | +def async_update_unique_id( |
| 119 | + hass: HomeAssistant, domain: str, entities: Iterable[VivintAlarmControlPanelEntity] |
| 120 | +) -> None: |
| 121 | + """Update unique ID to be based on VIN and entity description key instead of name.""" |
| 122 | + ent_reg = er.async_get(hass) |
| 123 | + for entity in entities: |
| 124 | + old_unique_id = int(entity.unique_id) |
| 125 | + if entity_id := ent_reg.async_get_entity_id(domain, DOMAIN, old_unique_id): |
| 126 | + if existing_entity_id := ent_reg.async_get_entity_id( |
| 127 | + domain, DOMAIN, entity.unique_id |
| 128 | + ): |
| 129 | + ent_reg.async_remove(existing_entity_id) |
| 130 | + ent_reg.async_update_entity(entity_id, new_unique_id=entity.unique_id) |
0 commit comments