mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Expose altitude for Starlink device tracker (#115508)
This commit is contained in:
parent
6d0ae77288
commit
2b2c4e8262
@ -1,3 +1,5 @@
|
|||||||
"""Constants for the Starlink integration."""
|
"""Constants for the Starlink integration."""
|
||||||
|
|
||||||
DOMAIN = "starlink"
|
DOMAIN = "starlink"
|
||||||
|
|
||||||
|
ATTR_ALTITUDE = "altitude"
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import SourceType, TrackerEntity
|
from homeassistant.components.device_tracker import SourceType, TrackerEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -9,7 +10,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity import EntityDescription
|
from homeassistant.helpers.entity import EntityDescription
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import ATTR_ALTITUDE, DOMAIN
|
||||||
from .coordinator import StarlinkData
|
from .coordinator import StarlinkData
|
||||||
from .entity import StarlinkEntity
|
from .entity import StarlinkEntity
|
||||||
|
|
||||||
@ -32,6 +33,7 @@ class StarlinkDeviceTrackerEntityDescription(EntityDescription):
|
|||||||
|
|
||||||
latitude_fn: Callable[[StarlinkData], float]
|
latitude_fn: Callable[[StarlinkData], float]
|
||||||
longitude_fn: Callable[[StarlinkData], float]
|
longitude_fn: Callable[[StarlinkData], float]
|
||||||
|
altitude_fn: Callable[[StarlinkData], float]
|
||||||
|
|
||||||
|
|
||||||
DEVICE_TRACKERS = [
|
DEVICE_TRACKERS = [
|
||||||
@ -41,6 +43,7 @@ DEVICE_TRACKERS = [
|
|||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
latitude_fn=lambda data: data.location["latitude"],
|
latitude_fn=lambda data: data.location["latitude"],
|
||||||
longitude_fn=lambda data: data.location["longitude"],
|
longitude_fn=lambda data: data.location["longitude"],
|
||||||
|
altitude_fn=lambda data: data.location["altitude"],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -64,3 +67,10 @@ class StarlinkDeviceTrackerEntity(StarlinkEntity, TrackerEntity):
|
|||||||
def longitude(self) -> float | None:
|
def longitude(self) -> float | None:
|
||||||
"""Return longitude value of the device."""
|
"""Return longitude value of the device."""
|
||||||
return self.entity_description.longitude_fn(self.coordinator.data)
|
return self.entity_description.longitude_fn(self.coordinator.data)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
|
"""Return device specific attributes."""
|
||||||
|
return {
|
||||||
|
ATTR_ALTITUDE: self.entity_description.altitude_fn(self.coordinator.data)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user