393 files
This commit is contained in:
@@ -10,22 +10,23 @@ from homeassistant.components.sensor import (
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from . import build_unique_id, entry_location_key
|
||||
from .const import BASE_URL, CONF_AREA, CONF_PATH, CONF_PLACE, DOMAIN
|
||||
from .coordinator import SeaTemperatureConfigEntry, SeaTemperatureCoordinator
|
||||
from .parser import validate_location_path
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# The coordinator does the one fetch per location; the sensor only reads its
|
||||
# data and has no update method or action of its own, so nothing to serialise.
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
def _to_float(val: Any, round_to: int | None = None) -> float | str:
|
||||
"""Safely convert a value to float if possible."""
|
||||
@@ -47,9 +48,11 @@ class SeaTemperatureSensorEntityDescription(SensorEntityDescription):
|
||||
SENSORS: tuple[SeaTemperatureSensorEntityDescription, ...] = (
|
||||
SeaTemperatureSensorEntityDescription(
|
||||
key="today",
|
||||
name="Temperature",
|
||||
# No name and no icon: with has_entity_name, HA names an unnamed sensor
|
||||
# after its device class ("Temperature", "Temperatur", ...) in the
|
||||
# user's language, and the temperature device class brings the
|
||||
# mdi:thermometer default icon with it.
|
||||
data_key="today",
|
||||
icon="mdi:thermometer",
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
@@ -59,11 +62,11 @@ SENSORS: tuple[SeaTemperatureSensorEntityDescription, ...] = (
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: SeaTemperatureConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Sea Temperature sensor entry."""
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
sensors = [
|
||||
SeaTemperatureSensor(coordinator, entry, description) for description in SENSORS
|
||||
@@ -79,8 +82,8 @@ class SeaTemperatureSensor(CoordinatorEntity, SensorEntity):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: DataUpdateCoordinator,
|
||||
entry: ConfigEntry,
|
||||
coordinator: SeaTemperatureCoordinator,
|
||||
entry: SeaTemperatureConfigEntry,
|
||||
description: SeaTemperatureSensorEntityDescription,
|
||||
):
|
||||
super().__init__(coordinator)
|
||||
@@ -90,9 +93,6 @@ class SeaTemperatureSensor(CoordinatorEntity, SensorEntity):
|
||||
# Shared with the unique_id migration, so both sides agree on the id.
|
||||
self._location_key = entry_location_key(entry)
|
||||
|
||||
# Set friendly name
|
||||
self._attr_name = "Temperature"
|
||||
|
||||
place_prefix = slugify(self._place_name)
|
||||
|
||||
# Slugified: the raw location path produced ids like
|
||||
|
||||
Reference in New Issue
Block a user