Skip to content

Commit

Permalink
Add number restore
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Jul 9, 2024
1 parent c4b9557 commit c7a3f91
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion custom_components/teslemetry/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity

from .const import DOMAIN
from .entity import TeslemetryVehicleEntity
Expand All @@ -30,7 +31,7 @@ async def async_setup_entry(
)


class TeslemetryDeviceTrackerEntity(TeslemetryVehicleEntity, TrackerEntity):
class TeslemetryDeviceTrackerEntity(TeslemetryVehicleEntity, TrackerEntity, RestoreEntity):
"""Base class for Teslemetry Tracker Entities."""

_attr_entity_category = None
Expand All @@ -43,6 +44,13 @@ def __init__(
"""Initialize the device tracker."""
super().__init__(vehicle, self.key, self.timestamp_key, self.streaming_key)

async def async_added_to_hass(self) -> None:
"""Handle entity which will be added."""
await super().async_added_to_hass()
if (state := await self.async_get_last_state()) is not None and self._attr_latitude is None and self._attr_longitude is None:
self._attr_latitude = state.attributes.get('latitude')
self._attr_longitude = state.attributes.get('longitude')

@property
def latitude(self) -> float | None:
"""Return latitude value of the device."""
Expand Down

0 comments on commit c7a3f91

Please sign in to comment.