278 files
This commit is contained in:
@@ -20,7 +20,8 @@ from homeassistant.helpers.update_coordinator import (
|
||||
)
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from .const import BASE_URL, CONF_AREA, CONF_PATH, CONF_PLACE, CONF_PLACE_ID, DOMAIN
|
||||
from . import build_unique_id, entry_location_key
|
||||
from .const import BASE_URL, CONF_AREA, CONF_PATH, CONF_PLACE, DOMAIN
|
||||
from .parser import validate_location_path
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -86,29 +87,30 @@ class SeaTemperatureSensor(CoordinatorEntity, SensorEntity):
|
||||
self.entity_description = description
|
||||
self._entry = entry
|
||||
self._place_name = entry.data.get(CONF_PLACE, "Unknown")
|
||||
self._location_key = entry.data.get(CONF_PLACE_ID) or entry.data.get(CONF_PATH)
|
||||
if self._location_key is None:
|
||||
self._location_key = self._place_name
|
||||
# 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)
|
||||
|
||||
self._attr_unique_id = f"{DOMAIN}_{self._location_key}_{description.key}"
|
||||
# Slugified: the raw location path produced ids like
|
||||
# "seatemperatures_/europe/germany/island-of-sylt/_today". Entry
|
||||
# version 4 rewrites the registry, so existing entities keep their
|
||||
# entity_id and their history.
|
||||
self._attr_unique_id = build_unique_id(self._location_key, description.key)
|
||||
self.entity_id = f"sensor.{DOMAIN}_{place_prefix}_{description.key}"
|
||||
|
||||
@property
|
||||
def native_value(self) -> float | str | None:
|
||||
"""Return the state of the sensor."""
|
||||
# native_value is read on every state write, so nothing here logs the
|
||||
# payload: it carries the 30-point chart series, and one place turned
|
||||
# debug logging for this integration into an unreadable wall of numbers.
|
||||
if not self.coordinator.data:
|
||||
_LOGGER.debug("No coordinator data available for %s", self.entity_id)
|
||||
return None
|
||||
|
||||
_LOGGER.debug(
|
||||
"Coordinator data for %s: %s", self.entity_id, self.coordinator.data
|
||||
)
|
||||
|
||||
# Try to get data from 'sst' nesting if it exists
|
||||
data = self.coordinator.data.get("sst", self.coordinator.data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user