Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions homeassistant/components/linky/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
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)
Expand All @@ -28,17 +30,6 @@
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."""
Expand Down Expand Up @@ -114,6 +105,12 @@ def __init__(self, name, account: LinkyAccount, scale, when):
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):
Expand Down Expand Up @@ -144,6 +141,15 @@ def device_state_attributes(self):
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]
Expand Down