2021-09-01 11:10:48 +00:00
|
|
|
"""Support for Renault device trackers."""
|
2024-03-08 14:05:07 +00:00
|
|
|
|
2021-09-01 11:10:48 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from renault_api.kamereon.models import KamereonVehicleLocationData
|
|
|
|
|
2022-10-28 15:40:37 +00:00
|
|
|
from homeassistant.components.device_tracker import SourceType, TrackerEntity
|
2021-09-01 11:10:48 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
|
2024-04-30 15:39:03 +00:00
|
|
|
from . import RenaultConfigEntry
|
2023-04-04 12:38:52 +00:00
|
|
|
from .entity import RenaultDataEntity, RenaultDataEntityDescription
|
2021-09-01 11:10:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
2024-04-30 15:39:03 +00:00
|
|
|
config_entry: RenaultConfigEntry,
|
2021-09-01 11:10:48 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
|
|
|
"""Set up the Renault entities from config entry."""
|
|
|
|
entities: list[RenaultDeviceTracker] = [
|
|
|
|
RenaultDeviceTracker(vehicle, description)
|
2024-04-30 15:39:03 +00:00
|
|
|
for vehicle in config_entry.runtime_data.vehicles.values()
|
2021-09-01 11:10:48 +00:00
|
|
|
for description in DEVICE_TRACKER_TYPES
|
|
|
|
if description.coordinator in vehicle.coordinators
|
|
|
|
]
|
|
|
|
async_add_entities(entities)
|
|
|
|
|
|
|
|
|
|
|
|
class RenaultDeviceTracker(
|
|
|
|
RenaultDataEntity[KamereonVehicleLocationData], TrackerEntity
|
|
|
|
):
|
|
|
|
"""Mixin for device tracker specific attributes."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def latitude(self) -> float | None:
|
|
|
|
"""Return latitude value of the device."""
|
|
|
|
return self.coordinator.data.gpsLatitude if self.coordinator.data else None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def longitude(self) -> float | None:
|
|
|
|
"""Return longitude value of the device."""
|
|
|
|
return self.coordinator.data.gpsLongitude if self.coordinator.data else None
|
|
|
|
|
|
|
|
@property
|
2022-07-31 13:48:43 +00:00
|
|
|
def source_type(self) -> SourceType:
|
2021-09-01 11:10:48 +00:00
|
|
|
"""Return the source type of the device."""
|
2022-07-31 13:48:43 +00:00
|
|
|
return SourceType.GPS
|
2021-09-01 11:10:48 +00:00
|
|
|
|
|
|
|
|
2021-11-15 14:50:43 +00:00
|
|
|
DEVICE_TRACKER_TYPES: tuple[RenaultDataEntityDescription, ...] = (
|
|
|
|
RenaultDataEntityDescription(
|
2021-09-01 11:10:48 +00:00
|
|
|
key="location",
|
|
|
|
coordinator="location",
|
2023-04-03 16:20:11 +00:00
|
|
|
translation_key="location",
|
2021-09-01 11:10:48 +00:00
|
|
|
),
|
|
|
|
)
|