Add device_info to Linky integration (#26477)
* Add device_info to Linky integration * Remove useless SENSORS const * Review: remove DOMAIN from the unique_id
This commit is contained in:
parent
9e8f4a589f
commit
b3e574d5b2
1 changed files with 17 additions and 11 deletions
|
@ -18,6 +18,8 @@ from homeassistant.helpers.entity import Entity
|
|||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SCAN_INTERVAL = timedelta(hours=4)
|
||||
|
@ -28,17 +30,6 @@ INDEX_CURRENT = -1
|
|||
INDEX_LAST = -2
|
||||
ATTRIBUTION = "Data provided by Enedis"
|
||||
|
||||
SENSORS = {
|
||||
"yesterday": ("Linky yesterday", DAILY, INDEX_LAST),
|
||||
"current_month": ("Linky current month", MONTHLY, INDEX_CURRENT),
|
||||
"last_month": ("Linky last month", MONTHLY, INDEX_LAST),
|
||||
"current_year": ("Linky current year", YEARLY, INDEX_CURRENT),
|
||||
"last_year": ("Linky last year", YEARLY, INDEX_LAST),
|
||||
}
|
||||
SENSORS_INDEX_LABEL = 0
|
||||
SENSORS_INDEX_SCALE = 1
|
||||
SENSORS_INDEX_WHEN = 2
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Old way of setting up the Linky platform."""
|
||||
|
@ -114,6 +105,12 @@ class LinkySensor(Entity):
|
|||
self._username = account.username
|
||||
self._time = None
|
||||
self._consumption = None
|
||||
self._unique_id = f"{self._username}_{scale}_{when}"
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique ID."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -144,6 +141,15 @@ class LinkySensor(Entity):
|
|||
CONF_USERNAME: self._username,
|
||||
}
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return device information."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.unique_id)},
|
||||
"name": self.name,
|
||||
"manufacturer": "Enedis",
|
||||
}
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Retrieve the new data for the sensor."""
|
||||
data = self._account.data[self._scale][self._when]
|
||||
|
|
Loading…
Add table
Reference in a new issue