Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expose polling interval as a sensor #948

Merged
merged 5 commits into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading