Remove Amcrest camera unique id migration (#113870)

This commit is contained in:
Joost Lekkerkerker 2024-03-20 10:36:02 +01:00 committed by GitHub
parent ac008a4c6d
commit d2663347e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,15 +13,11 @@ from amcrest import AmcrestError
from haffmpeg.camera import CameraMjpeg
import voluptuous as vol
from homeassistant.components.camera import (
DOMAIN as CAMERA_DOMAIN,
Camera,
CameraEntityFeature,
)
from homeassistant.components.camera import Camera, CameraEntityFeature
from homeassistant.components.ffmpeg import FFmpegManager, get_ffmpeg_manager
from homeassistant.const import ATTR_ENTITY_ID, CONF_NAME, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_registry as er
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.aiohttp_client import (
async_aiohttp_proxy_stream,
async_aiohttp_proxy_web,
@ -37,7 +33,6 @@ from .const import (
COMM_TIMEOUT,
DATA_AMCREST,
DEVICES,
DOMAIN,
RESOLUTION_TO_STREAM,
SERVICE_UPDATE,
SNAPSHOT_TIMEOUT,
@ -141,18 +136,6 @@ async def async_setup_platform(
device = hass.data[DATA_AMCREST][DEVICES][name]
entity = AmcrestCam(name, device, get_ffmpeg_manager(hass))
# 2021.9.0 introduced unique id's for the camera entity, but these were not
# unique for different resolution streams. If any cameras were configured
# with this version, update the old entity with the new unique id.
serial_number = await device.api.async_serial_number
serial_number = serial_number.strip()
registry = er.async_get(hass)
entity_id = registry.async_get_entity_id(CAMERA_DOMAIN, DOMAIN, serial_number)
if entity_id is not None:
_LOGGER.debug("Updating unique id for camera %s", entity_id)
new_unique_id = f"{serial_number}-{device.resolution}-{device.channel}"
registry.async_update_entity(entity_id, new_unique_id=new_unique_id)
async_add_entities([entity], True)