Skip to content

Commit

Permalink
feat: Expose polling interval as a sensor (#948)
Browse files Browse the repository at this point in the history
* feat: Expose polling interval as a sensor

* style: auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* feat: Expose polling interval as a sensor

* style: auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ddaddy and pre-commit-ci[bot] committed Apr 24, 2024
1 parent f315261 commit d5040ac
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions custom_components/tesla_custom/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
UnitOfPressure,
UnitOfSpeed,
UnitOfTemperature,
UnitOfTime,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
Expand Down Expand Up @@ -73,6 +74,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry, async_add_entitie
entities.append(TeslaCarArrivalTime(car, coordinator))
entities.append(TeslaCarDistanceToArrival(car, coordinator))
entities.append(TeslaCarDataUpdateTime(car, coordinator))
entities.append(TeslaCarPollingInterval(car, coordinator))

for energy_site_id, energysite in energysites.items():
coordinator = coordinators[energy_site_id]
Expand Down Expand Up @@ -649,3 +651,19 @@ def native_value(self) -> datetime:
else:
date_obj = last_time.replace(tzinfo=dt.UTC)
return date_obj


class TeslaCarPollingInterval(TeslaCarEntity, SensorEntity):
"""Representation of a Tesla car polling interval."""

type = "polling interval"
_attr_device_class = SensorDeviceClass.DURATION
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = UnitOfTime.SECONDS
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_icon = "mdi:timer-sync"

@property
def native_value(self) -> int:
"""Return the update time interval."""
return self.coordinator.controller.get_update_interval_vin(vin=self._car.vin)

0 comments on commit d5040ac

Please sign in to comment.