Initial commit
This commit is contained in:
57
custom_components/integration_blueprint/sensor.py
Normal file
57
custom_components/integration_blueprint/sensor.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""Sensor platform for integration_blueprint."""
|
||||
|
||||
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="integration_blueprint",
|
||||
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):
|
||||
"""integration_blueprint 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")
|
||||
Reference in New Issue
Block a user