Migrate HomeKit Controller to use stable identifiers (#80064)
This commit is contained in:
parent
e3a3f93441
commit
f23b1750e8
66 changed files with 781 additions and 234 deletions
|
@ -19,10 +19,12 @@ from homeassistant.components.media_player import (
|
|||
MediaPlayerState,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import KNOWN_DEVICES
|
||||
from .connection import HKDevice
|
||||
from .entity import HomeKitEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -41,15 +43,19 @@ async def async_setup_entry(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Homekit television."""
|
||||
hkid = config_entry.data["AccessoryPairingID"]
|
||||
conn = hass.data[KNOWN_DEVICES][hkid]
|
||||
hkid: str = config_entry.data["AccessoryPairingID"]
|
||||
conn: HKDevice = hass.data[KNOWN_DEVICES][hkid]
|
||||
|
||||
@callback
|
||||
def async_add_service(service: Service) -> bool:
|
||||
if service.type != ServicesTypes.TELEVISION:
|
||||
return False
|
||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
||||
async_add_entities([HomeKitTelevision(conn, info)], True)
|
||||
entity = HomeKitTelevision(conn, info)
|
||||
conn.async_migrate_unique_id(
|
||||
entity.old_unique_id, entity.unique_id, Platform.MEDIA_PLAYER
|
||||
)
|
||||
async_add_entities([entity])
|
||||
return True
|
||||
|
||||
conn.add_listener(async_add_service)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue