46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
"""Sensor platform for Linky Tariff integration."""
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.components.sensor import SensorEntity
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
from .const import DOMAIN
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Set up the Linky Tariff sensor."""
|
|
coordinator = hass.data[DOMAIN][entry.entry_id]
|
|
async_add_entities([LinkyTariffSensor(coordinator)])
|
|
|
|
class LinkyTariffSensor(CoordinatorEntity, SensorEntity):
|
|
"""Representation of a Linky Tariff sensor."""
|
|
|
|
_attr_icon = "mdi:lightning-bolt"
|
|
_attr_has_entity_name = True
|
|
_attr_name = "Linky Tariff Period"
|
|
|
|
def __init__(self, coordinator) -> None:
|
|
"""Initialize the sensor."""
|
|
super().__init__(coordinator)
|
|
self._attr_unique_id = f"{coordinator.ieee}_tariff_period"
|
|
self._attr_device_info = {
|
|
"identifiers": {(DOMAIN, coordinator.ieee)},
|
|
}
|
|
|
|
@property
|
|
def native_value(self) -> str:
|
|
"""Return the state of the sensor."""
|
|
return self.coordinator.data["value"]
|
|
|
|
@property
|
|
def extra_state_attributes(self) -> dict[str, Any]:
|
|
"""Return the state attributes."""
|
|
return {
|
|
"last_update": self.coordinator.data["last_update"],
|
|
} |