Add device info to edl21 (#89070)

* Added device info for edl21.

* Apply suggestions from code review
pull/89217/head
Stephan Uhle 2023-03-06 08:29:41 +01:00 committed by GitHub
parent 876776e291
commit fc673139cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 14 deletions

View File

@ -32,6 +32,7 @@ from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
async_dispatcher_send,
)
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -283,7 +284,7 @@ async def async_setup_platform(
hass,
DOMAIN,
"deprecated_yaml",
breaks_in_ha_version="2023.2.0",
breaks_in_ha_version="2023.5.0",
is_fixable=False,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml",
@ -397,7 +398,7 @@ class EDL21:
old_entity_id = registry.async_get_entity_id(
"sensor", DOMAIN, entity.old_unique_id
)
if old_entity_id is not None:
if old_entity_id is not None and entity.unique_id is not None:
LOGGER.debug(
"Migrating unique_id from [%s] to [%s]",
entity.old_unique_id,
@ -422,8 +423,6 @@ class EDL21Entity(SensorEntity):
"""Initialize an EDL21Entity."""
self._electricity_id = electricity_id
self._obis = obis
self._name = name
self._unique_id = f"{electricity_id}_{obis}"
self._telegram = telegram
self._min_time = MIN_TIME_BETWEEN_UPDATES
self._last_update = utcnow()
@ -435,6 +434,12 @@ class EDL21Entity(SensorEntity):
}
self._async_remove_dispatcher = None
self.entity_description = entity_description
self._attr_name = name
self._attr_unique_id = f"{electricity_id}_{obis}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self._electricity_id)},
name=self._electricity_id,
)
async def async_added_to_hass(self) -> None:
"""Run when entity about to be added to hass."""
@ -466,21 +471,11 @@ class EDL21Entity(SensorEntity):
if self._async_remove_dispatcher:
self._async_remove_dispatcher()
@property
def unique_id(self) -> str:
"""Return a unique ID."""
return self._unique_id
@property
def old_unique_id(self) -> str:
"""Return a less unique ID as used in the first version of edl21."""
return self._obis
@property
def name(self) -> str | None:
"""Return a name."""
return self._name
@property
def native_value(self) -> str:
"""Return the value of the last received telegram."""