Add device info to edl21 (#89070)
* Added device info for edl21. * Apply suggestions from code review
This commit is contained in:
parent
876776e291
commit
fc673139cd
1 changed files with 9 additions and 14 deletions
|
@ -32,6 +32,7 @@ from homeassistant.helpers.dispatcher import (
|
||||||
async_dispatcher_connect,
|
async_dispatcher_connect,
|
||||||
async_dispatcher_send,
|
async_dispatcher_send,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
@ -283,7 +284,7 @@ async def async_setup_platform(
|
||||||
hass,
|
hass,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
"deprecated_yaml",
|
"deprecated_yaml",
|
||||||
breaks_in_ha_version="2023.2.0",
|
breaks_in_ha_version="2023.5.0",
|
||||||
is_fixable=False,
|
is_fixable=False,
|
||||||
severity=IssueSeverity.WARNING,
|
severity=IssueSeverity.WARNING,
|
||||||
translation_key="deprecated_yaml",
|
translation_key="deprecated_yaml",
|
||||||
|
@ -397,7 +398,7 @@ class EDL21:
|
||||||
old_entity_id = registry.async_get_entity_id(
|
old_entity_id = registry.async_get_entity_id(
|
||||||
"sensor", DOMAIN, entity.old_unique_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(
|
LOGGER.debug(
|
||||||
"Migrating unique_id from [%s] to [%s]",
|
"Migrating unique_id from [%s] to [%s]",
|
||||||
entity.old_unique_id,
|
entity.old_unique_id,
|
||||||
|
@ -422,8 +423,6 @@ class EDL21Entity(SensorEntity):
|
||||||
"""Initialize an EDL21Entity."""
|
"""Initialize an EDL21Entity."""
|
||||||
self._electricity_id = electricity_id
|
self._electricity_id = electricity_id
|
||||||
self._obis = obis
|
self._obis = obis
|
||||||
self._name = name
|
|
||||||
self._unique_id = f"{electricity_id}_{obis}"
|
|
||||||
self._telegram = telegram
|
self._telegram = telegram
|
||||||
self._min_time = MIN_TIME_BETWEEN_UPDATES
|
self._min_time = MIN_TIME_BETWEEN_UPDATES
|
||||||
self._last_update = utcnow()
|
self._last_update = utcnow()
|
||||||
|
@ -435,6 +434,12 @@ class EDL21Entity(SensorEntity):
|
||||||
}
|
}
|
||||||
self._async_remove_dispatcher = None
|
self._async_remove_dispatcher = None
|
||||||
self.entity_description = entity_description
|
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:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Run when entity about to be added to hass."""
|
"""Run when entity about to be added to hass."""
|
||||||
|
@ -466,21 +471,11 @@ class EDL21Entity(SensorEntity):
|
||||||
if self._async_remove_dispatcher:
|
if self._async_remove_dispatcher:
|
||||||
self._async_remove_dispatcher()
|
self._async_remove_dispatcher()
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str:
|
|
||||||
"""Return a unique ID."""
|
|
||||||
return self._unique_id
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def old_unique_id(self) -> str:
|
def old_unique_id(self) -> str:
|
||||||
"""Return a less unique ID as used in the first version of edl21."""
|
"""Return a less unique ID as used in the first version of edl21."""
|
||||||
return self._obis
|
return self._obis
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str | None:
|
|
||||||
"""Return a name."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> str:
|
def native_value(self) -> str:
|
||||||
"""Return the value of the last received telegram."""
|
"""Return the value of the last received telegram."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue