Skip to content

Commit

Permalink
Add Last Updated timestamp sensor entity
Browse files Browse the repository at this point in the history
  • Loading branch information
BHSPitMonkey committed Dec 29, 2023
1 parent 6232401 commit cfeccf9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions custom_components/garmin_mapshare/sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
from datetime import datetime
from typing import cast

from homeassistant.components.sensor import (
Expand All @@ -25,6 +26,10 @@ def float_from_first_word(text: str) -> float:
return None
return float(text.split()[0])

def datetime_from_feed(text: str) -> datetime:
dt = datetime.strptime(text + ' +0000', '%m/%d/%Y %I:%M:%S %p %z')
return dt

SENSOR_TYPES: dict[str, tuple[SensorEntityDescription, callable, str]] = {
"Latitude": (SensorEntityDescription(
key="latitude",
Expand Down Expand Up @@ -71,6 +76,11 @@ def float_from_first_word(text: str) -> float:
icon="mdi:history",
entity_registry_enabled_default=False,
), None, "Last Event"),
"Time UTC": (SensorEntityDescription(
key="last_updated",
translation_key="last_updated",
device_class=SensorDeviceClass.TIMESTAMP,
), datetime_from_feed, "Last Updated"),
}

async def async_setup_entry(
Expand Down

0 comments on commit cfeccf9

Please sign in to comment.