mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-29 21:03:40 +00:00
57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
"""Sensor platform for tibber_prices."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
|
|
|
from .entity import IntegrationBlueprintEntity
|
|
|
|
if TYPE_CHECKING:
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from .coordinator import BlueprintDataUpdateCoordinator
|
|
from .data import IntegrationBlueprintConfigEntry
|
|
|
|
ENTITY_DESCRIPTIONS = (
|
|
SensorEntityDescription(
|
|
key="tibber_prices",
|
|
name="Integration Sensor",
|
|
icon="mdi:format-quote-close",
|
|
),
|
|
)
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant, # noqa: ARG001 Unused function argument: `hass`
|
|
entry: IntegrationBlueprintConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Set up the sensor platform."""
|
|
async_add_entities(
|
|
IntegrationBlueprintSensor(
|
|
coordinator=entry.runtime_data.coordinator,
|
|
entity_description=entity_description,
|
|
)
|
|
for entity_description in ENTITY_DESCRIPTIONS
|
|
)
|
|
|
|
|
|
class IntegrationBlueprintSensor(IntegrationBlueprintEntity, SensorEntity):
|
|
"""tibber_prices Sensor class."""
|
|
|
|
def __init__(
|
|
self,
|
|
coordinator: BlueprintDataUpdateCoordinator,
|
|
entity_description: SensorEntityDescription,
|
|
) -> None:
|
|
"""Initialize the sensor class."""
|
|
super().__init__(coordinator)
|
|
self.entity_description = entity_description
|
|
|
|
@property
|
|
def native_value(self) -> str | None:
|
|
"""Return the native value of the sensor."""
|
|
return self.coordinator.data.get("body")
|